diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6da4321..f46fc05 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -30,8 +30,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ '7.1', '7.2', '7.3', '7.4' ] - mysql: [ '5.7', '8.0' ] + php: [ '7.4' ] + mysql: [ '8.0' ] env: NC3_BUILD_DIR: "/opt/nc3" diff --git a/Model/MultidatabaseContent.php b/Model/MultidatabaseContent.php index 1275cd2..eadd57f 100644 --- a/Model/MultidatabaseContent.php +++ b/Model/MultidatabaseContent.php @@ -288,6 +288,14 @@ public function saveContent($data, $isUpdate) { } $data = $this->data; + // $this->dataには、クレンジングされたデータが保持されており、添付ファイルの削除フラグが消されてしまっている。 + // 後続の処理で、添付ファイルを削除する際に、`$data['value5__attach_del'] = 'on'`がないと削除してくれないため、 + // $dataを引数$dataにある値を戻す。 + foreach ($deleteFiles as $colNo) { + $delColumn = 'value' . $colNo . '_attach'; + $data[$delColumn . '_del'] = 'on'; + } + $result = $this->MultidatabaseContentEdit->makeSaveData($data, $metadatas, $isUpdate); return $this->__saveContent($result); @@ -365,7 +373,7 @@ public function deleteContentByKey($key) { $this->deleteCommentsByContentKey($key); // 添付ファイルの削除 - if (! $this->MultidatabaseContentFile->removeFileByContentKey($key)) { + if (! $this->MultidatabaseContentFile->removeFilesByContentKey($key)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } @@ -470,14 +478,16 @@ private function __saveContent($data) { $attachPasswords ); - $this->commit(); - // ファイルを削除する if (! empty($removeAttachFields)) { $this->MultidatabaseContentFile->removeAttachFile( - $removeAttachFields, $data['MultidatabaseContent']['key']); + $removeAttachFields, + $data['MultidatabaseContent']['key'] + ); } + $this->commit(); + } catch (Exception $e) { $this->rollback($e); } diff --git a/Model/MultidatabaseContentFile.php b/Model/MultidatabaseContentFile.php index cf06d2c..b39a71e 100644 --- a/Model/MultidatabaseContentFile.php +++ b/Model/MultidatabaseContentFile.php @@ -241,6 +241,38 @@ public function removeFileByContentKey($key, $fieldName = '') { return $this->__removeFile($fileInfo, $fieldName); } +/** + * Remove File(s) + * ファイルを削除する(コンテンツKeyより) + * + * @param string $contentKey コンテンツKey + * @return bool + */ + public function removeFilesByContentKey($contentKey) { + $UploadFile = ClassRegistry::init('Files.UploadFile'); + $pluginKey = 'multidatabases'; + + $options = [ + 'recursive' => -1, + 'fields' => [ + 'UploadFile.id', + ], + 'conditions' => [ + 'UploadFile.plugin_key' => $pluginKey, + 'UploadFile.content_key' => $contentKey, + ], + 'callbacks' => false, + ]; + + $files = $UploadFile->find('all', $options); + + foreach ($files as $file) { + $UploadFile->deleteUploadFile($file['UploadFile']['id']); + } + + return true; + } + /** * RemoveFile(s) Base * ファイルを削除する