Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 14 additions & 4 deletions Model/MultidatabaseContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'));
}

Expand Down Expand Up @@ -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);
}
Expand Down
32 changes: 32 additions & 0 deletions Model/MultidatabaseContentFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
* ファイルを削除する
Expand Down