Skip to content

Commit

Permalink
コンテンツ管理のルートフォルダの名称が変更できない fix #2900 (#2901)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Dec 1, 2023
1 parent 643b00f commit 4c0f144
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 5 deletions.
10 changes: 9 additions & 1 deletion plugins/baser-core/src/Model/Table/ContentsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ public function validationDefault(Validator $validator): Validator
$validator
->integer('parent_id')
->requirePresence('parent_id', 'create', __d('baser_core', 'content[parent_id] フィールドが存在しません。'))
->notEmptyString('parent_id', __d('baser_core', '親フォルダを入力してください。'));
->allowEmptyString('parent_id', __d('baser_core', '親フォルダを入力してください。'), function(array $context){
return (isset($context['data']['id']) && $context['data']['id'] === 1);
});

$validator
->scalar('name')
Expand Down Expand Up @@ -236,6 +238,12 @@ public function validationDefault(Validator $validator): Validator
return $validator;
}

public function checkParentId($value, $context)
{
$value = 1;
return false;
}

/**
* サイト設定にて、エイリアスを利用してメインサイトと自動連携するオプションを利用時に、
* 関連するサブサイトで、関連コンテンツを作成する際、同階層に重複名称のコンテンツがないか確認する
Expand Down
4 changes: 2 additions & 2 deletions plugins/baser-core/src/Service/ContentFoldersService.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ public function getParentTemplate($id, $type)
*/
public function saveSiteRoot($site, $isUpdateChildrenUrl = false)
{
if ($site->id === 1) return false;
$rootContentId = 1;
$rootContentId = ($site->id === 1) ? null : 1;
if($site->main_site_id) {
/* @var SitesTable $sitesTable */
$sitesTable = TableRegistry::getTableLocator()->get('BaserCore.Sites');
Expand All @@ -320,6 +319,7 @@ public function saveSiteRoot($site, $isUpdateChildrenUrl = false)
'author_id' => BcUtil::loginUser()['id'],
'site_root' => true,
'layout_template' => 'default',
'created_date' => date('Y-m-d H:i:s')
]
];
$contentFolder = $this->create($data);
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/tests/TestCase/BcPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class BcPluginTest extends BcTestCase
'plugin.BaserCore.SiteConfigs',
'plugin.BaserCore.Sites',
'plugin.BaserCore.Contents',
'plugin.BaserCore.ContentFolders',
];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\Controller\Admin\ThemesController;
use BaserCore\Test\Scenario\SmallSetContentFoldersScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use Cake\Filesystem\Folder;
Expand Down Expand Up @@ -192,7 +193,7 @@ public function test_apply()
{
$this->enableSecurityToken();
$this->enableCsrfToken();

$this->loadFixtureScenario(SmallSetContentFoldersScenario::class);
$theme = 'BcFront';
$this->post('/baser/admin/baser-core/themes/apply/' . $theme);
$this->assertResponseCode(302);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use BaserCore\Service\ThemesService;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\Test\Scenario\SmallSetContentFoldersScenario;
use BaserCore\TestSuite\BcTestCase;
use Cake\Filesystem\Folder;
use Cake\TestSuite\IntegrationTestTrait;
Expand Down Expand Up @@ -167,6 +168,7 @@ public function testApply(): void
$this->enableSecurityToken();
$this->enableCsrfToken();
$theme = 'BcColumn';
$this->loadFixtureScenario(SmallSetContentFoldersScenario::class);
$this->post('/baser/api/admin/baser-core/themes/apply/1/'. $theme . '.json?token=' . $this->accessToken);
$this->assertResponseOk();
$result = json_decode((string)$this->_response->getBody());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use BaserCore\Test\Factory\SiteFactory;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\Test\Scenario\MultiSiteScenario;
use BaserCore\Test\Scenario\SmallSetContentFoldersScenario;
use BaserCore\TestSuite\BcTestCase;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

Expand Down Expand Up @@ -143,6 +144,7 @@ public function test_process_site_private(): void
{
//データ生成
$this->loadFixtureScenario(InitAppScenario::class);
$this->loadFixtureScenario(SmallSetContentFoldersScenario::class);

//サイトが非公開を設定する
$SitesService = $this->getService(SitesServiceInterface::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use BaserCore\Test\Factory\UserFactory;
use BaserCore\Test\Factory\UserGroupFactory;
use BaserCore\Test\Factory\UsersUserGroupFactory;
use BaserCore\Test\Scenario\SmallSetContentFoldersScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use BaserCore\Utility\BcUtil;
Expand All @@ -36,6 +37,7 @@
use Cake\TestSuite\IntegrationTestTrait;
use Cake\Filesystem\File;
use Cake\Utility\Inflector;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;
use Migrations\Migrations;

/**
Expand All @@ -50,6 +52,7 @@ class BcDatabaseServiceTest extends BcTestCase
*/
use BcContainerTrait;
use IntegrationTestTrait;
use ScenarioAwareTrait;

/**
* Set Up
Expand Down Expand Up @@ -356,6 +359,7 @@ public function test_initSystemData()
SiteFactory::make(['id' => '1', 'theme' => 'BcPluginSample'])->persist();
// userデータを作成する
UserFactory::make(['name' => 'C. Le'])->persist();
$this->loadFixtureScenario(SmallSetContentFoldersScenario::class);

$result1 = $this->BcDatabaseService->initSystemData($options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ public function testSaveSiteRoot(): void
$sites = TableRegistry::getTableLocator()->get('BaserCore.Sites');
// 初期サイトIDの場合はfalse
$site = $sites->get(1);
$this->assertFalse($this->ContentFoldersService->saveSiteRoot($site, true));
$contentFolder = $this->ContentFoldersService->saveSiteRoot($site, true);
$this->assertEmpty($contentFolder->content->name);
// サイト新規作成の場合
$site = $sites->get(3);
$site->setNew(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use BaserCore\Test\Factory\SiteFactory;
use BaserCore\Test\Factory\UsersUserGroupFactory;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\Test\Scenario\SmallSetContentFoldersScenario;
use BaserCore\Utility\BcContainerTrait;
use BaserCore\Utility\BcSiteConfig;
use BaserCore\Utility\BcUtil;
Expand Down Expand Up @@ -381,6 +382,7 @@ public function testApply()
{
$beforeTheme = 'BcPluginSample';
$afterTheme = 'BcFront';
$this->loadFixtureScenario(SmallSetContentFoldersScenario::class);
SiteFactory::make(['id' => 1, 'title' => 'Test Title', 'name' => 'Test Site', 'theme'=> $beforeTheme, 'status' => 1])->persist();
$site = SiteFactory::get(1);
Router::setRequest($this->getRequest());
Expand Down

0 comments on commit 4c0f144

Please sign in to comment.