From 0e72412d692cd78419221ef13070a2e1ca6c1218 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Tue, 30 Sep 2025 00:14:57 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E6=B1=8E=E7=94=A8=E3=83=87=E3=83=BC?= =?UTF-8?q?=E3=82=BF=E3=83=99=E3=83=BC=E3=82=B9=E3=81=AE=E7=B7=A8=E9=9B=86?= =?UTF-8?q?=E7=94=BB=E9=9D=A2=E3=81=A7=E3=80=8C=E7=99=BB=E9=8C=B2=E6=B8=88?= =?UTF-8?q?=E3=81=BF=E3=81=AE=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4=E3=81=99=E3=82=8B=E3=80=8D=E3=81=AB=E3=83=81?= =?UTF-8?q?=E3=82=A7=E3=83=83=E3=82=AF=E3=82=92=E4=BB=98=E3=81=91=E3=81=A6?= =?UTF-8?q?=E3=82=82=E6=B7=BB=E4=BB=98=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=81=8C=E5=89=8A=E9=99=A4=E3=81=95=E3=82=8C=E3=81=AA=E3=81=84?= =?UTF-8?q?=20https://github.com/NetCommons3/NetCommons3/issues/1728?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/MultidatabaseContent.php | 18 +++++++++++++---- Model/MultidatabaseContentFile.php | 32 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) 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 * ファイルを削除する From 49cd0503c71caea8862e0e17c81b3d19861c41a0 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Tue, 30 Sep 2025 00:25:24 +0900 Subject: [PATCH 2/2] =?UTF-8?q?ci:=20test=E3=82=B1=E3=83=BC=E3=82=B9?= =?UTF-8?q?=E3=82=92php7.4=E3=81=AE=E3=81=BF=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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"