Skip to content

Commit

Permalink
Fix issue 2978 (#2984)
Browse files Browse the repository at this point in the history
  • Loading branch information
nghiem-mb authored Dec 26, 2023
1 parent 89a5233 commit 4b2b486
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 34 deletions.
2 changes: 1 addition & 1 deletion plugins/baser-core/src/Service/PluginsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ public function add(array $postData)
$dstName = Inflector::camelize($baseName) . $num;
}
$folder = new BcFolder(TMP . $srcName);
$folder->move(TMP . $srcName, BASER_PLUGINS. $dstName);
$folder->move( BASER_PLUGINS. $dstName);
unlink(TMP . $name);
BcUtil::changePluginNameSpace($dstName);
return $dstName;
Expand Down
6 changes: 3 additions & 3 deletions plugins/baser-core/src/Service/ThemesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function add(array $postData): string
$num++;
}
$folder = new BcFolder(TMP . $srcName);
$folder->move(TMP . $srcName, BASER_THEMES . $dstName,);
$folder->move( BASER_THEMES . $dstName,);
unlink(TMP . $name);
BcUtil::changePluginNameSpace($dstName);
return $dstName;
Expand Down Expand Up @@ -365,7 +365,7 @@ public function copy(string $theme): bool
$newTheme .= 'Copy';
}
$folder = new BcFolder(BASER_THEMES . $theme);
if (!$folder->copy(BASER_THEMES . $theme, BASER_THEMES . $newTheme)) {
if (!$folder->copy( BASER_THEMES . $newTheme)) {
return false;
}
if(!BcUtil::changePluginNameSpace($newTheme)) return false;
Expand Down Expand Up @@ -421,7 +421,7 @@ public function createDownloadToTmp(string $theme): string
$folder->create();
}
$folder = new BcFolder(BcUtil::getPluginPath($theme));
$folder->copy(BcUtil::getPluginPath($theme), $tmpDir . $theme);
$folder->copy($tmpDir . $theme);
return $tmpDir;
}

Expand Down
11 changes: 7 additions & 4 deletions plugins/baser-core/src/Utility/BcFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ public function delete()
* @noTodo
* @unitTest
*/
public function copy($source, $dest): bool
public function copy($dest): bool
{
$source=$this->path;
if (!is_dir($source)) return false;
if(is_dir($source)) {
$dir_handle=opendir($source);
Expand All @@ -191,7 +192,8 @@ public function copy($source, $dest): bool
while($file=readdir($dir_handle)){
if($file!="." && $file!=".."){
if(is_dir($source."/".$file)){
self::copy($source .DS. $file, $dest .DS. $file);
$this->path = $source .DS. $file;
self::copy( $dest .DS. $file);
} else {
copy($source."/".$file, $dest."/".$file);
}
Expand All @@ -210,10 +212,11 @@ public function copy($source, $dest): bool
* @noTodo
* @unitTest
*/
public function move($source, $dest): bool
public function move($dest): bool
{
$source = $this->path;
if (!is_dir($source)) return false;
return $this->copy($source, $dest) && $this->delete();
return $this->copy($dest) && $this->delete();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions plugins/baser-core/tests/TestCase/BcPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ public function testInstallAndUninstall()
$pluginDir = dirname($from);
$folder = new BcFolder($from);
$to = $pluginDir . DS . 'BcBlogBak';
$folder->copy($from, $to);
$folder->copy($to);
$folder->create();
$this->BcPlugin->uninstall(['connection' => 'test']);
$this->assertFalse(is_dir($from));
$plugins = $this->getTableLocator()->get('BaserCore.Plugins')->find()->where(['name' => 'BcBlog'])->first();
$this->assertNull($plugins);
$folder->move($from, $to);
$folder->move( $to);
$this->BcPlugin->install(['connection' => 'test']);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function testDetachAndInstallAndUninstall(): void
$folder = new BcFolder($from);
$folder->create();
$to = $pluginDir . DS . 'BcBlogBak';
$folder->copy($from, $to);
$folder->copy($to);
$this->post('/baser/admin/baser-core/plugins/uninstall/BcBlog', $data);
$this->assertRedirect([
'plugin' => 'BaserCore',
Expand All @@ -188,7 +188,7 @@ public function testDetachAndInstallAndUninstall(): void
'action' => 'index'
]);
$this->assertFlashMessage('プラグイン「BcBlog」を削除しました。');
$folder->move($from, $to);
$folder->move($to);
$this->put('/baser/admin/baser-core/plugins/install/BcBlog', $data);
}

Expand Down Expand Up @@ -305,7 +305,9 @@ public function test_add()
$zipSrcPath = TMP . 'zip' . DS;
$folder = new BcFolder($zipSrcPath);
$folder->create();
$folder->copy($path, $zipSrcPath . 'BcPluginSample2');
//copy
$folder = new BcFolder($path);
$folder->copy($zipSrcPath . 'BcPluginSample2');
$plugin = 'BcPluginSample2';
$zip = new ZipArchiver();
$testFile = $zipSrcPath . $plugin . '.zip';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public function test_add()
$theme = 'BcPluginSample2';
$folder = new BcFolder($zipSrcPath);
$folder->create();
$folder->copy($path, $zipSrcPath. 'BcPluginSample2');
//copy
$folder = new BcFolder($path);
$folder->copy($zipSrcPath. 'BcPluginSample2');
$zip = new ZipArchiver();
$testFile = $zipSrcPath . $theme . '.zip';
$zip->archive($zipSrcPath, $testFile, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ public function testLog_maintenance(): void
// ログが存在しないテスト
$logsFolder = new BcFolder(LOGS);
$backupPath = ROOT . DS . 'logsBackup' . DS;
$logsFolder->copy(LOGS, $backupPath); // 念の為ログフォルダをバックアップする
$logsFolder->delete();
$logsFolder->move($backupPath); // 念の為ログフォルダをバックアップする
$this->get('/baser/admin/baser-core/utilities/log_maintenance/download');
// ステータスを確認
$this->assertResponseCode(302);
Expand All @@ -98,8 +97,7 @@ public function testLog_maintenance(): void
// ログが存在しない場合のメッセージを確認
$this->assertFlashMessage("エラーログが存在しません。");
$backupFolder = new BcFolder($backupPath);
$backupFolder->copy($backupPath, LOGS); // ログフォルダのファイルを復元する
$backupFolder->delete(); // バックアップフォルダを削除する
$backupFolder->move( LOGS); // ログフォルダのファイルを復元する
// ---- 引数 $mode が download の場合 end ----

// ---- 引数 $mode が delete の場合 start ----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ public function test_add()
$zipSrcPath = TMP . 'zip' . DS;
$folder = new BcFolder($zipSrcPath);
$folder->create();
$folder->copy($path, $zipSrcPath . 'BcPluginSample2');
//copy
$folder = new BcFolder($path);
$folder->copy($zipSrcPath . 'BcPluginSample2');
$plugin = 'BcPluginSample2';
$zip = new ZipArchiver();
$testFile = $zipSrcPath . $plugin . '.zip';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ public function testAdd(): void
$zipSrcPath = TMP . 'zip' . DS;
$folder = new BcFolder($zipSrcPath);
$folder->create();
$folder->copy($path, $zipSrcPath. 'BcPluginSample2');
//copy
$folder = new BcFolder($path);
$folder->copy($zipSrcPath. 'BcPluginSample2');
$theme = 'BcPluginSample2';
$zip = new ZipArchiver();
$testFile = $zipSrcPath . $theme . '.zip';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ public function test_add()
$zipSrcPath = TMP . 'zip' . DS;
$folder = new BcFolder($zipSrcPath);
$folder->create();
$folder->copy($path, $zipSrcPath. 'BcThemeSample2');
//copy
$folder = new BcFolder($path);
$folder->copy( $zipSrcPath. 'BcThemeSample2');
$plugin = 'BcThemeSample2';
$zip = new ZipArchiver();
$testFile = $zipSrcPath . $plugin . '.zip';
Expand All @@ -415,7 +417,9 @@ public function test_add()
// 既に /plugins/ 内に同名のプラグインが存在する場合には、数字付きのディレクトリ名(PluginName2)にリネームする。
$folder = new BcFolder($zipSrcPath);
$folder->create();
$folder->copy($path, $zipSrcPath . 'BcThemeSample2');
//copy
$folder = new BcFolder($path);
$folder->copy($zipSrcPath . 'BcThemeSample2');
$zip = new ZipArchiver();
$zip->archive($zipSrcPath, $testFile, true);
$this->setUploadFileToRequest('file', $testFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ public function test_add()
$zipSrcPath = TMP . 'zip' . DS;
$folder = new BcFolder($zipSrcPath);
$folder->create();
$folder->copy($path, $zipSrcPath . 'BcPluginSample2');
//copy
$folder = new BcFolder($path);
$folder->copy( $zipSrcPath . 'BcPluginSample2');
$theme = 'BcPluginSample2';
$zip = new ZipArchiver();
$testFile = $zipSrcPath . $theme . '.zip';
Expand Down Expand Up @@ -109,7 +111,9 @@ public function test_add()
// 既に存在するテーマと同じテーマをアップロードした場合の戻り値の変化
$folder = new BcFolder($zipSrcPath);
$folder->create();
$folder->copy($path, $zipSrcPath . 'BcPluginSample2');
//copy
$folder = new BcFolder($path);
$folder->copy($zipSrcPath . 'BcPluginSample2');
$zip = new ZipArchiver();
$zip->archive($zipSrcPath, $testFile, true);
$this->setUploadFileToRequest('file', $testFile);
Expand Down
4 changes: 2 additions & 2 deletions plugins/baser-core/tests/TestCase/Utility/BcFolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function test_copy()
$file = new BcFile($path. DS. 'test.txt');
$file->create();
$des = TMP_TESTS . 'test_des';
$result = $folder1->copy($path, $des);
$result = $folder1->copy($des);
$this->assertTrue($result);
$this->assertFileExists($des. DS. 'test.txt');
$this->assertFileExists($des. DS. 'test1' .DS. 'test1.txt');
Expand All @@ -160,7 +160,7 @@ public function test_move()
$des = TMP_TESTS . 'test_des';
$folder2 = new BcFolder($des);
$folder2->create();
$result = $folder1->move($path, $des);
$result = $folder1->move($des);
$this->assertTrue($result);
$this->assertFileDoesNotExist($path. DS. 'test.txt');
$this->assertFileExists($des. DS. 'test.txt');
Expand Down
5 changes: 3 additions & 2 deletions plugins/baser-core/tests/TestCase/Utility/BcUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public function testClearAllCache(): void
// $folder->create();
$backup = str_replace('cache', 'cache_backup', CACHE);
(new BcFolder($backup))->create();
$folder->move($origin, $backup);
$folder->move($backup);

// cache環境準備
$cacheList = ['environment' => '_bc_env_', 'persistent' => '_cake_core_', 'models' => '_cake_model_'];
Expand All @@ -300,7 +300,8 @@ public function testClearAllCache(): void
}

// cacheファイル復元
$folder->move($backup, $origin);
$folder = new BcFolder($backup);
$folder->move($origin);
$folder->chmod(0777);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ protected function redirectEditBlog(string $template): ResponseInterface
if (is_dir($source)) {
$folder = new BcFolder(dirname($target));
$folder->create();
$folder->copy($source, $target);
//copy
$folder = new BcFolder($source);
$folder->copy($target);
}
}
$path = str_replace(DS, '/', $path);
Expand Down
2 changes: 1 addition & 1 deletion plugins/bc-theme-file/src/Form/ThemeFolderForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function _execute(array $data): bool
$newPath = dirname($data['fullpath']) . DS . $data['name'] . DS;
if($newPath === $data['fullpath']) return true;
$folder = new BcFolder($data['fullpath']);
return $folder->move($data['fullpath'], $newPath);
return $folder->move($newPath);
}
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions plugins/bc-theme-file/src/Service/ThemeFoldersService.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function copy(string $fullpath)
$newPath .= '_copy';
}
$folder = new BcFolder($fullpath);
$result = $folder->copy($fullpath, $newPath);
$result = $folder->copy($newPath);
$folder = null;
if ($result) {
return $newEntity;
Expand Down Expand Up @@ -297,9 +297,9 @@ public function copyToTheme(array $params)
} else {
$themePath = Plugin::templatePath($theme) . $params['path'] . DS;
}
$folder = new BcFolder(dirname($themePath));
$folder->create();
if ($folder->copy($params['fullpath'], $themePath)) {
(new BcFolder(dirname($themePath)))->create();
$folder = new BcFolder($params['fullpath']);
if ($folder->copy($themePath)) {
return str_replace(ROOT, '', $themePath);
} else {
return false;
Expand Down

0 comments on commit 4b2b486

Please sign in to comment.