Skip to content

Commit

Permalink
ThemeFolder (#2853)
Browse files Browse the repository at this point in the history
  • Loading branch information
nghiem-mb authored Nov 9, 2023
1 parent 73eb231 commit ddb173d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
8 changes: 4 additions & 4 deletions plugins/bc-theme-file/src/Form/ThemeFolderForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace BcThemeFile\Form;

use Cake\Filesystem\Folder;
use BaserCore\Utility\BcFolder;
use Cake\Form\Form;
use Cake\Form\Schema;
use BaserCore\Annotation\UnitTest;
Expand Down Expand Up @@ -50,13 +50,13 @@ protected function _buildSchema(Schema $schema): Schema
*/
protected function _execute(array $data): bool
{
$folder = new Folder();
$folder = new BcFolder($data['fullpath'] . DS . $data['name'] . DS);
if($data['mode'] === 'create') {
return $folder->create($data['fullpath'] . DS . $data['name'] . DS, 0777);
return $folder->create();
} elseif($data['mode'] === 'update') {
$newPath = dirname($data['fullpath']) . DS . $data['name'] . DS;
if($newPath === $data['fullpath']) return true;
return $folder->move($newPath, ['from' => $data['fullpath'], 'chmod' => 0777, 'skip' => ['_notes']]);
return $folder->move($data['fullpath'], $newPath);
}
return false;
}
Expand Down
15 changes: 5 additions & 10 deletions plugins/bc-theme-file/src/Service/ThemeFoldersService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use BcThemeFile\Form\ThemeFolderForm;
use BcThemeFile\Model\Entity\ThemeFolder;
use Cake\Core\Plugin;
use Cake\Filesystem\Folder;

/**
* ThemeFoldersService
Expand Down Expand Up @@ -210,12 +209,8 @@ public function copy(string $fullpath)
}
$newPath .= '_copy';
}
$folder = new Folder();
$result = $folder->copy($newPath, [
'from' => $fullpath,
'chmod' => 0777,
'skip' => ['_notes'
]]);
$folder = new BcFolder($fullpath);
$result = $folder->copy($fullpath, $newPath);
$folder = null;
if ($result) {
return $newEntity;
Expand Down Expand Up @@ -302,9 +297,9 @@ public function copyToTheme(array $params)
} else {
$themePath = Plugin::templatePath($theme) . $params['path'] . DS;
}
$folder = new Folder();
$folder->create(dirname($themePath), 0777);
if ($folder->copy($themePath, ['from' => $params['fullpath'], 'chmod' => 0777, 'skip' => ['_notes']])) {
$folder = new BcFolder(dirname($themePath));
$folder->create();
if ($folder->copy($params['fullpath'], $themePath)) {
return str_replace(ROOT, '', $themePath);
} else {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use BaserCore\Test\Factory\SiteFactory;
use BaserCore\Test\Factory\UserFactory;
use BaserCore\TestSuite\BcTestCase;
use Cake\Filesystem\Folder;
use BaserCore\Utility\BcFolder;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

class ThemeFoldersControllerTest extends BcTestCase
Expand Down Expand Up @@ -58,7 +58,7 @@ public function tearDown(): void
public function test_batch()
{
$fullpath = BASER_PLUGINS . 'BcThemeSample' . '/templates/layout/';
(new Folder())->create($fullpath . 'delete_folder', 0777);
(new BcFolder($fullpath . 'delete_folder'))->create();
//APIをコール
$this->post('/baser/api/admin/bc-theme-file/theme_folders/batch.json?token=' . $this->accessToken,
[
Expand Down Expand Up @@ -176,7 +176,7 @@ public function test_delete()
{
//テストテーマフォルダを作成
$fullpath = BASER_PLUGINS . 'BcThemeSample' . '/templates/layout/';
(new Folder())->create($fullpath . 'delete_folder', 0777);
(new BcFolder($fullpath . 'delete_folder'))->create();
//Postデータを生成
$data = [
'theme' => 'BcThemeSample',
Expand Down Expand Up @@ -211,7 +211,7 @@ public function test_copy()
{
//テストテーマフォルダを作成
$fullpath = BASER_PLUGINS . 'BcThemeSample' . '/templates/layout/';
(new Folder())->create($fullpath . 'new_folder', 0777);
(new BcFolder($fullpath . 'new_folder'))->create();
//Postデータを生成
$data = [
'theme' => 'BcThemeSample',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use BaserCore\Test\Factory\SiteFactory;
use BaserCore\Test\Factory\UserFactory;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcFolder;
use BcThemeFile\Service\ThemeFoldersService;
use Cake\Filesystem\Folder;

/**
* ThemeFoldersServiceTest
Expand Down Expand Up @@ -147,7 +147,7 @@ public function test_delete()
{
//テストテーマフォルダを作成
$fullpath = BASER_PLUGINS . 'BcThemeSample' . '/templates/layout';
(new Folder())->create($fullpath . DS . 'delete_folder', 0777);
(new BcFolder($fullpath . DS . 'delete_folder'))->create();
$rs = $this->ThemeFoldersService->delete($fullpath . DS . 'delete_folder');
//戻る値を確認
$this->assertTrue($rs);
Expand All @@ -162,7 +162,7 @@ public function test_copy()
{
//テストテーマフォルダを作成
$fullpath = BASER_PLUGINS . 'BcThemeSample/templates/layout/';
(new Folder())->create($fullpath . 'new_folder', 0777);
(new BcFolder($fullpath . 'new_folder'))->create();

//対象のメソッドを確認
$rs = $this->ThemeFoldersService->copy($fullpath . 'new_folder');
Expand All @@ -187,8 +187,8 @@ public function test_batch()
{
//テストテーマフォルダパス
$fullpath = BASER_PLUGINS . 'BcThemeSample/templates/layout';
(new Folder())->create($fullpath . DS . 'folder_1', 0777);
(new Folder())->create($fullpath . DS . 'folder_2', 0777);
(new BcFolder($fullpath . DS . 'folder_1'))->create();
(new BcFolder($fullpath . DS . 'folder_2'))->create();
//一括削除処理をテスト
$paths = [
$fullpath . DS . 'folder_1',
Expand Down

0 comments on commit ddb173d

Please sign in to comment.