diff --git a/config/test_install.php b/config/test_install.php deleted file mode 100644 index f34061f9e8..0000000000 --- a/config/test_install.php +++ /dev/null @@ -1,42 +0,0 @@ - - * Copyright (c) NPO baser foundation - * - * @copyright Copyright (c) NPO baser foundation - * @link https://basercms.net baserCMS Project - * @since 5.0.0 - * @license https://basercms.net/license/index.html MIT License - */ -/** - * ユニットテスト用のインストール設定ファイル - */ -return [ - 'Security.salt' => 'af0aa6bb8bad3bf5f9a39e928c645745cc008d67d82ac4edd16ec17e99539725', - 'Datasources.default' => [ - 'className' => 'Cake\\Database\\Connection', - 'driver' => 'Cake\\Database\\Driver\\Mysql', - 'host' => 'bc-db', - 'port' => '3306', - 'username' => 'root', - 'password' => 'root', - 'database' => 'basercms', - 'prefix' => 'mysite_', - 'schema' => '', - 'encoding' => 'utf8', - 'persistent' => '', - ], - 'Datasources.test' => [ - 'className' => 'Cake\\Database\\Connection', - 'driver' => 'Cake\\Database\\Driver\\Mysql', - 'host' => 'bc-db', - 'port' => '3306', - 'username' => 'root', - 'password' => 'root', - 'database' => 'test_basercms', - 'prefix' => 'mysite_', - 'schema' => '', - 'encoding' => 'utf8', - 'persistent' => '', - ], -]; diff --git a/plugins/BcThemeSample/config/data/default/BaserCore/site_configs.csv b/plugins/BcThemeSample/config/data/default/BaserCore/site_configs.csv index af4c47ce9e..0e70851c12 100755 --- a/plugins/BcThemeSample/config/data/default/BaserCore/site_configs.csv +++ b/plugins/BcThemeSample/config/data/default/BaserCore/site_configs.csv @@ -52,10 +52,9 @@ q {}","","" "23","use_site_device_setting","0","","" "24","use_site_lang_setting","0","","" "25","use_update_notice","1","","" -"26","contents_sort_last_modified","","","" -"27","mail_additional_parameters","","","" -"28","outer_service_output_header","","","" -"29","outer_service_output_footer","","","" -"30","allow_simple_password","0","","" -"31","password_reset_days","","","" -"32","use_two_factor_authentication","0","","" +"26","mail_additional_parameters","","","" +"27","outer_service_output_header","","","" +"28","outer_service_output_footer","","","" +"29","allow_simple_password","0","","" +"30","password_reset_days","","","" +"31","use_two_factor_authentication","0","","" diff --git a/plugins/BcThemeSample/config/data/empty/BaserCore/site_configs.csv b/plugins/BcThemeSample/config/data/empty/BaserCore/site_configs.csv index 48a2483e6b..cf27f2259c 100755 --- a/plugins/BcThemeSample/config/data/empty/BaserCore/site_configs.csv +++ b/plugins/BcThemeSample/config/data/empty/BaserCore/site_configs.csv @@ -52,10 +52,9 @@ q {}","","" "23","use_site_device_setting","0","","" "24","use_site_lang_setting","0","","" "25","use_update_notice","1","","" -"26","contents_sort_last_modified","","","" -"27","mail_additional_parameters","","","" -"28","outer_service_output_header","","","" -"29","outer_service_output_footer","","","" -"30","allow_simple_password","0","","" -"31","password_reset_days","","","" -"32","use_two_factor_authentication","0","","" +"26","mail_additional_parameters","","","" +"27","outer_service_output_header","","","" +"28","outer_service_output_footer","","","" +"29","allow_simple_password","0","","" +"30","password_reset_days","","","" +"31","use_two_factor_authentication","0","","" diff --git a/plugins/baser-core/config/Seeds/SiteConfigsSeed.php b/plugins/baser-core/config/Seeds/SiteConfigsSeed.php index 9ec615fdda..e054a3c43b 100644 --- a/plugins/baser-core/config/Seeds/SiteConfigsSeed.php +++ b/plugins/baser-core/config/Seeds/SiteConfigsSeed.php @@ -211,13 +211,6 @@ public function run(): void 'created' => '', 'modified' => '' ], - [ - 'id' => '25', - 'name' => 'contents_sort_last_modified', - 'value' => '', - 'created' => '', - 'modified' => '' - ], [ 'id' => '26', 'name' => 'mail_additional_parameters', diff --git a/plugins/baser-core/src/Controller/Admin/ContentsController.php b/plugins/baser-core/src/Controller/Admin/ContentsController.php index a8a97d4ec0..62d7d58ee4 100644 --- a/plugins/baser-core/src/Controller/Admin/ContentsController.php +++ b/plugins/baser-core/src/Controller/Admin/ContentsController.php @@ -96,8 +96,6 @@ public function index(ContentsAdminServiceInterface $service, SiteConfigsService switch($this->getRequest()->getQuery('list_type')) { case 1: - // 並び替え最終更新時刻をリセット - $siteConfigService->resetValue('contents_sort_last_modified'); $contents = $service->getTreeIndex($this->getRequest()->getQueryParams()); break; case 2: diff --git a/plugins/baser-core/src/Controller/Api/Admin/ContentsController.php b/plugins/baser-core/src/Controller/Api/Admin/ContentsController.php index 73e32bacbe..72c6abffa0 100644 --- a/plugins/baser-core/src/Controller/Api/Admin/ContentsController.php +++ b/plugins/baser-core/src/Controller/Api/Admin/ContentsController.php @@ -490,30 +490,26 @@ public function move(ContentsServiceInterface $service) { $this->request->allowMethod(['post', 'put', 'patch']); $url = $content = $errors = null; - if (!$service->isTreeModifiedByAnotherUser($this->getRequest()->getData('listDisplayed'))) { - try { - $beforeContent = $service->get($this->request->getData('origin.id')); - $beforeUrl = $beforeContent->url; - $content = $service->move($this->request->getData('origin'), $this->request->getData('target')); - $message = sprintf( - __d('baser_core', "コンテンツ「%s」の配置を移動しました。\n%s > %s"), - $content->title, - rawurldecode($beforeUrl), - rawurldecode($content->url) - ); - $url = $service->getUrlById($content->id, true); - $this->BcMessage->setSuccess($message, true, false); - } catch (PersistenceFailedException $e) { - $errors = $e->getEntity()->getErrors(); - $message = __d('baser_core', "入力エラーです。内容を修正してください。"); - $this->setResponse($this->response->withStatus(400)); - } catch (\Throwable $e) { - $message = __d('baser_core', 'データベース処理中にエラーが発生しました。' . $e->getMessage()); - $this->setResponse($this->response->withStatus(500)); - } - } else { - $message = __d('baser_core', 'コンテンツ一覧を表示後、他のログインユーザーがコンテンツの並び順を更新しました。
一度リロードしてから並び替えてください。'); + + try { + $beforeContent = $service->get($this->request->getData('origin.id')); + $beforeUrl = $beforeContent->url; + $content = $service->move($this->request->getData('origin'), $this->request->getData('target')); + $message = sprintf( + __d('baser_core', "コンテンツ「%s」の配置を移動しました。\n%s > %s"), + $content->title, + rawurldecode($beforeUrl), + rawurldecode($content->url) + ); + $url = $service->getUrlById($content->id, true); + $this->BcMessage->setSuccess($message, true, false); + } catch (PersistenceFailedException $e) { + $errors = $e->getEntity()->getErrors(); + $message = __d('baser_core', "入力エラーです。内容を修正してください。"); $this->setResponse($this->response->withStatus(400)); + } catch (\Throwable $e) { + $message = __d('baser_core', 'データベース処理中にエラーが発生しました。' . $e->getMessage()); + $this->setResponse($this->response->withStatus(500)); } $this->set([ diff --git a/plugins/baser-core/src/Model/Table/AppTable.php b/plugins/baser-core/src/Model/Table/AppTable.php index feebf67d9b..f951947c4c 100755 --- a/plugins/baser-core/src/Model/Table/AppTable.php +++ b/plugins/baser-core/src/Model/Table/AppTable.php @@ -13,9 +13,7 @@ use BaserCore\Utility\BcUtil; use Cake\ORM\Association\BelongsToMany; -use Cake\ORM\Query; use Cake\ORM\Table; -use Cake\I18n\FrozenTime; use BaserCore\Annotation\NoTodo; use BaserCore\Annotation\Checked; use BaserCore\Annotation\UnitTest; @@ -83,6 +81,7 @@ public function setTable(string $table) * @return string * @checked * @noTodo + * @unitTest */ public function getTable(): string { diff --git a/plugins/baser-core/src/Model/Table/ContentsTable.php b/plugins/baser-core/src/Model/Table/ContentsTable.php index ea15024781..bb74162a45 100644 --- a/plugins/baser-core/src/Model/Table/ContentsTable.php +++ b/plugins/baser-core/src/Model/Table/ContentsTable.php @@ -99,15 +99,6 @@ public function initialize(array $config): void */ protected $updatingSystemData = true; - /** - * 保存前の親ID - * - * IDの変更比較に利用 - * - * @var null - */ - public $beforeSaveParentId = null; - /** * Implemented Events * @@ -366,12 +357,10 @@ public function beforeMarshal(EventInterface $event, ArrayObject $content, Array } } else { if (isset($content['name'])) { - try { - $oldName = $this->get($content['id'])->name; - } catch (\Exception $e) { - $oldName = null; - } - if($content['name'] !== $oldName) { + $old = $this->get($content['id']); + $content['lft'] = $old->lft; + $content['rght'] = $old->rght; + if($content['name'] !== $old->name) { $content['name'] = BcUtil::urlencode(mb_substr($content['name'], 0, 230, 'UTF-8')); } } @@ -468,15 +457,6 @@ public function getUniqueName($name, $parentId, $contentId = null) */ public function beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options) { - if (!empty($entity->id)) { - try { - $this->beforeSaveParentId = $this->get($entity->id)->parent_id; - } catch (RecordNotFoundException) { - try { - $this->beforeSaveParentId = $this->getTrash($entity->id)->parent_id; - } catch (\Throwable) {} - } - } if (!empty($entity->name)) { $entity->name = $this->urlEncode(mb_substr(rawurldecode($entity->name), 0, 230, 'UTF-8')); } @@ -504,11 +484,6 @@ public function afterSave(EventInterface $event, EntityInterface $entity, ArrayO $this->updateChildren($entity->id); } $this->updateRelateSubSiteContent($entity); - if (!empty($entity->parent_id) && $this->beforeSaveParentId != $entity->parent_id) { - $SiteConfig = TableRegistry::getTableLocator()->get('BaserCore.SiteConfigs'); - $SiteConfig->updateContentsSortLastModified(); - $this->beforeSaveParentId = null; - } } } diff --git a/plugins/baser-core/src/Model/Table/SiteConfigsTable.php b/plugins/baser-core/src/Model/Table/SiteConfigsTable.php index d691bcba08..01b5202d74 100755 --- a/plugins/baser-core/src/Model/Table/SiteConfigsTable.php +++ b/plugins/baser-core/src/Model/Table/SiteConfigsTable.php @@ -113,67 +113,6 @@ public function getControlSource($field) } } - /** - * コンテンツ一覧を表示してから、コンテンツの並び順が変更されていないかどうか - * 60秒をブラウザのロード時間を加味したバッファとする - * @param $listDisplayed - * @return bool - * @checked - * @noTodo - * @unitTest - */ - public function isChangedContentsSortLastModified($listDisplayed) - { - $lastModified = $this->getValue('contents_sort_last_modified'); - $changed = false; - if ($lastModified) { - $user = BcUtil::loginUser(); - if (!$user) { - return false; - } - [$lastModified, $userId] = explode('|', $lastModified); - $lastModified = strtotime($lastModified); - if ($user->id !== (int)$userId) { - $listDisplayed = strtotime($listDisplayed); - if ($lastModified >= ($listDisplayed - 60)) { - $changed = true; - } - } - } - return $changed; - } - - /** - * コンテンツ並び順変更時間を更新する - * @return bool - * @checked - * @noTodo - * @unitTest - */ - public function updateContentsSortLastModified() - { - $user = BcUtil::loginUser(); - if (!$user) { - return false; - } - return $this->saveValue( - 'contents_sort_last_modified', - date('Y-m-d H:i:s') . '|' . $user->id - ); - } - - /** - * コンテンツ並び替え順変更時間をリセットする - * @return bool - * @checked - * @noTodo - * @unitTest - */ - public function resetContentsSortLastModified() - { - return $this->saveValue('contents_sort_last_modified', ''); - } - /** * 指定したフィールドの値がDBのデータと比較して変更状態か確認 * diff --git a/plugins/baser-core/src/Service/ContentsService.php b/plugins/baser-core/src/Service/ContentsService.php index b9000ff9e2..89d79f2824 100644 --- a/plugins/baser-core/src/Service/ContentsService.php +++ b/plugins/baser-core/src/Service/ContentsService.php @@ -971,19 +971,6 @@ public function exists($id, $withTrash = false): bool return $exists; } - /** - * - * - * @checked - * @noTodo - * @unitTest - */ - public function isTreeModifiedByAnotherUser($listDisplayed) - { - $siteConfig = TableRegistry::getTableLocator()->get('BaserCore.SiteConfigs'); - return $siteConfig->isChangedContentsSortLastModified($listDisplayed); - } - /** * コンテンツを移動する * @@ -1035,11 +1022,6 @@ public function move($origin, $target) } // オフセットを元に移動 $result = $this->Contents->moveOffset($origin['id'], $offset); - if ($result && $origin['parentId'] === $target['parentId']) { - // 親が違う場合は、Contentモデルで更新してくれるが同じ場合更新しない仕様のためここで更新する - $siteConfig = TableRegistry::getTableLocator()->get('BaserCore.SiteConfigs'); - $siteConfig->updateContentsSortLastModified(); - } if ($result) $this->saveSearchIndex($origin['id']); return $result; } diff --git a/plugins/baser-core/tests/Scenario/SiteConfigsScenario.php b/plugins/baser-core/tests/Scenario/SiteConfigsScenario.php index 8176a78c00..070ae82408 100644 --- a/plugins/baser-core/tests/Scenario/SiteConfigsScenario.php +++ b/plugins/baser-core/tests/Scenario/SiteConfigsScenario.php @@ -247,14 +247,6 @@ public function load(...$args): mixed 'modified' => '2021-01-27 12:58:25' ] )->persist(); - SiteConfigFactory::make([ - 'id' => '30', - 'name' => 'contents_sort_last_modified', - 'value' => '', - 'created' => '2021-01-27 12:58:10', - 'modified' => '2021-01-27 12:58:25' - ] - )->persist(); SiteConfigFactory::make([ 'id' => '31', 'name' => 'editor', diff --git a/plugins/baser-core/tests/TestCase/Model/Table/AppTableTest.php b/plugins/baser-core/tests/TestCase/Model/Table/AppTableTest.php index b95038b1f8..71f2d88c87 100644 --- a/plugins/baser-core/tests/TestCase/Model/Table/AppTableTest.php +++ b/plugins/baser-core/tests/TestCase/Model/Table/AppTableTest.php @@ -12,13 +12,12 @@ namespace BaserCore\Test\TestCase\Model\Table; use BaserCore\Model\Table\AppTable; -use BaserCore\Test\Factory\ContentFolderFactory; -use BaserCore\Test\Factory\PluginFactory; use BaserCore\Test\Scenario\PermissionGroupsScenario; use BaserCore\Test\Scenario\PluginsScenario; use BaserCore\TestSuite\BcTestCase; use BaserCore\Model\Table\PermissionsTable as TablePermissionsTable; -use Cake\Event\Event; +use BaserCore\Utility\BcUtil; +use Cake\Database\Connection; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; /** @@ -78,6 +77,23 @@ public function testInitialize() ); } + /** + * test getTable + */ + public function testGetTable() + { + //デフォルトテーブル + $this->assertEquals('app', $this->App->getTable()); + + //プレフィックスを追加場合、 + $dbConfig = BcUtil::getCurrentDbConfig(); + $dbConfig['prefix'] = 'unittest_'; + $connection = new Connection($dbConfig); + $this->App = $this->getTableLocator()->get('BaserCore.App')->setConnection($connection); + + $this->assertEquals('unittest_app', $this->App->getTable()); + } + /** * Test getUrlPattern * diff --git a/plugins/baser-core/tests/TestCase/Model/Table/ContentsTableTest.php b/plugins/baser-core/tests/TestCase/Model/Table/ContentsTableTest.php index 8af2bbd3f8..1945b0454f 100644 --- a/plugins/baser-core/tests/TestCase/Model/Table/ContentsTableTest.php +++ b/plugins/baser-core/tests/TestCase/Model/Table/ContentsTableTest.php @@ -295,7 +295,6 @@ public function testBeforeSave() ])->persist(); $data = ContentFactory::get(100); $result = $this->Contents->dispatchEvent('Model.beforeSave', ['entity' => $data, 'options' => new ArrayObject()]); - $this->assertEquals(6, $this->Contents->beforeSaveParentId); // nameフィールドがエンコードされてるかをテスト $entity = $result->getData('entity'); $this->assertEquals(urlencode($value), $entity->name); @@ -540,6 +539,7 @@ public function testUpdateSystemData() $result = $this->execPrivateMethod($this->Contents, 'updateSystemData', [$content]); $this->assertFalse($result); // self_*を元にstatusなど補完する + ContentFactory::make(['id' => 100, 'name' => ''])->persist(); $data = [ 'id' => 100, 'site_id' => 1, diff --git a/plugins/baser-core/tests/TestCase/Model/Table/SiteConfigsTableTest.php b/plugins/baser-core/tests/TestCase/Model/Table/SiteConfigsTableTest.php index c2b4126a25..9d53148a08 100644 --- a/plugins/baser-core/tests/TestCase/Model/Table/SiteConfigsTableTest.php +++ b/plugins/baser-core/tests/TestCase/Model/Table/SiteConfigsTableTest.php @@ -151,65 +151,6 @@ public static function getControlSourceDataProvider() ]; } - /** - * コンテンツ一覧を表示してから、コンテンツの並び順が変更されていないかどうか - * @param bool $isLogin ログインしているかどうか - * @param string $saveValue 保存値 - * @param string $listDisplayed 表示した時間 - * @param bool $expected 期待値 - * @dataProvider isChangedContentsSortLastModifiedDataProvider - */ - public function testIsChangedContentsSortLastModified($isLogin, $saveValue, $listDisplayed, $expected) - { - $this->loadFixtureScenario(InitAppScenario::class); - if($isLogin) Router::setRequest($this->loginAdmin($this->getRequest())); - $this->SiteConfigs->saveValue('contents_sort_last_modified', $saveValue); - $result = $this->SiteConfigs->isChangedContentsSortLastModified($listDisplayed); - $this->assertEquals($expected, $result); - } - - public static function isChangedContentsSortLastModifiedDataProvider() - { - return [ - [false, '', '2021/08/01', false], // 保存値なし - [false, '2021/08/01|1', '2021/08/01', false], // 未ログイン - [true, '2021/08/01|1', '2021/08/01', false], // 同じユーザーの変更 - [true, '2021/08/01 10:00:00|2', '2021/08/01 10:00:30', true], // バッファ内 - [true, '2021/08/01 10:00:00|2', '2021/08/01 10:01:01', false], // バッファ外 - ]; - } - - /** - * コンテンツ並び順変更時間を更新する - */ - public function testUpdateContentsSortLastModified() - { - $this->loadFixtureScenario(InitAppScenario::class); - // 未ログイン - $this->SiteConfigs->saveValue('contents_sort_last_modified', ''); - $this->SiteConfigs->updateContentsSortLastModified(); - $this->assertEquals('', $this->SiteConfigs->getValue('contents_sort_last_modified')); - // ログイン - Router::setRequest($this->loginAdmin($this->getRequest())); - $this->SiteConfigs->updateContentsSortLastModified(); - $lastModified = $this->SiteConfigs->getValue('contents_sort_last_modified'); - [$lastModified, $userId] = explode('|', $lastModified); - $this->assertEquals(1, $userId); - $this->assertNotEmpty($lastModified); - } - - /** - * コンテンツ並び替え順変更時間をリセットする - */ - public function testResetContentsSortLastModified() - { - $this->loadFixtureScenario(InitAppScenario::class); - $this->loginAdmin($this->getRequest()); - $this->SiteConfigs->updateContentsSortLastModified(); - $this->SiteConfigs->resetContentsSortLastModified(); - $this->assertEmpty($this->SiteConfigs->getValue('contents_sort_last_modified')); - } - /** * testIsChanged * diff --git a/plugins/bc-blog/tests/TestCase/Controller/Api/Admin/BlogContentsControllerTest.php b/plugins/bc-blog/tests/TestCase/Controller/Api/Admin/BlogContentsControllerTest.php index fddf050dee..f35c5ece54 100755 --- a/plugins/bc-blog/tests/TestCase/Controller/Api/Admin/BlogContentsControllerTest.php +++ b/plugins/bc-blog/tests/TestCase/Controller/Api/Admin/BlogContentsControllerTest.php @@ -256,10 +256,6 @@ public function test_copy() 'level' => 1, ])->persist(); - SiteConfigFactory::make([ - 'name' => 'contents_sort_last_modified', - 'value' => '' - ])->persist(); $data = [ 'entity_id' => 2, 'parent_id' => 2, diff --git a/plugins/bc-blog/tests/TestCase/Service/BlogContentsServiceTest.php b/plugins/bc-blog/tests/TestCase/Service/BlogContentsServiceTest.php index b73ad3e107..c7d8d80d29 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogContentsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogContentsServiceTest.php @@ -217,10 +217,6 @@ public function test_copy() 'level' => 1, ])->persist(); - SiteConfigFactory::make([ - 'name' => 'contents_sort_last_modified', - 'value' => '' - ])->persist(); $data = [ 'entity_id' => 2, 'parent_id' => 2, diff --git a/plugins/bc-front/config/data/default/BaserCore/site_configs.csv b/plugins/bc-front/config/data/default/BaserCore/site_configs.csv index 716a749f43..52e5e0e4e8 100755 --- a/plugins/bc-front/config/data/default/BaserCore/site_configs.csv +++ b/plugins/bc-front/config/data/default/BaserCore/site_configs.csv @@ -52,10 +52,9 @@ q {}","","" "23","use_site_device_setting","0","","" "24","use_site_lang_setting","0","","" "25","use_update_notice","1","","" -"26","contents_sort_last_modified","","","" -"27","mail_additional_parameters","","","" -"28","outer_service_output_header","","","" -"29","outer_service_output_footer","","","" -"30","allow_simple_password","0","","" -"31","password_reset_days","","","" -"32","use_two_factor_authentication","0","","" +"26","mail_additional_parameters","","","" +"27","outer_service_output_header","","","" +"28","outer_service_output_footer","","","" +"29","allow_simple_password","0","","" +"30","password_reset_days","","","" +"31","use_two_factor_authentication","0","","" diff --git a/plugins/bc-installer/src/Command/InstallCommand.php b/plugins/bc-installer/src/Command/InstallCommand.php index b2c9886160..199128b6cb 100644 --- a/plugins/bc-installer/src/Command/InstallCommand.php +++ b/plugins/bc-installer/src/Command/InstallCommand.php @@ -169,7 +169,6 @@ public function install(Arguments $args, ConsoleIo $io, array $dbConfig) // Init admin $service->setAdminEmailAndVersion($args->getArgument('adminemail')); $service->setSiteName($args->getOption('sitename')); - $salt = $service->setSecuritySalt(); $service->addDefaultUser([ 'password_1' => $args->getArgument('adminpassword'), 'password_2' => $args->getArgument('adminpassword'), @@ -177,8 +176,8 @@ public function install(Arguments $args, ConsoleIo $io, array $dbConfig) ]); // Init files - $service->createInstallFile($dbConfig, $salt); - BcApiUtil::createJwt(); + $service->createInstallFile($dbConfig); + $service->createJwt(); // Init db $service->createDefaultFiles(); diff --git a/plugins/bc-installer/src/Service/Admin/InstallationsAdminService.php b/plugins/bc-installer/src/Service/Admin/InstallationsAdminService.php index 8c7c89271e..c6cc0234bb 100644 --- a/plugins/bc-installer/src/Service/Admin/InstallationsAdminService.php +++ b/plugins/bc-installer/src/Service/Admin/InstallationsAdminService.php @@ -255,10 +255,6 @@ public function initAdmin(ServerRequest $request): void $this->setAdminEmailAndVersion($request->getData('admin_email')); $this->setSiteName($request->getData('site_name')); - // SecuritySalt設定 - $salt = $this->setSecuritySalt(); - $request->getSession()->write('Installation.salt', $salt); - // 管理ユーザー登録 $user = [ 'password_1' => $request->getData('admin_password'), @@ -284,8 +280,7 @@ public function initAdmin(ServerRequest $request): void public function initFiles(ServerRequest $request): void { // インストールファイルを生成する - $securitySalt = $request->getSession()->read('Installation.salt'); - $this->createInstallFile($this->readDbSetting($request), $securitySalt); + $this->createInstallFile($this->readDbSetting($request)); // JWTキーを作成する BcApiUtil::createJwt(); // アップロード用初期フォルダを作成する @@ -321,7 +316,6 @@ public function login(ServerRequest $request, Response $response): void { // ログインするとセッションが初期化されてしまうので一旦取得しておく $installationSetting = $request->getSession()->read('Installation'); - Configure::write('Security.salt', $installationSetting['salt']); /* @var UsersService $usersService */ $usersService = $this->getService(UsersServiceInterface::class); $usersService->login($request, $response, $installationSetting['id']); diff --git a/plugins/bc-installer/src/Service/InstallationsService.php b/plugins/bc-installer/src/Service/InstallationsService.php index 75aca95d61..fb892fecff 100644 --- a/plugins/bc-installer/src/Service/InstallationsService.php +++ b/plugins/bc-installer/src/Service/InstallationsService.php @@ -283,26 +283,6 @@ public function setAdminEmailAndVersion(string $email) $siteConfigsService->setValue('version', BcUtil::getVersion())); } - /** - * セキュリティ用のキーを生成する - * - * @param int $length - * @return string キー - * @checked - * @noTodo - * @unitTest - */ - public function setSecuritySalt($length = 40): string - { - $keyset = "abcdefghijklmABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - $randkey = ""; - for($i = 0; $i < $length; $i++) { - $randkey .= substr($keyset, rand(0, strlen($keyset) - 1), 1); - } - Configure::write('Security.salt', $randkey); - return $randkey; - } - /** * 初期ユーザーを登録する * @@ -312,11 +292,8 @@ public function setSecuritySalt($length = 40): string * @checked * @noTodo */ - public function addDefaultUser(array $user, $securitySalt = '') + public function addDefaultUser(array $user) { - if ($securitySalt) { - Configure::write('Security.salt', $securitySalt); - } $user = array_merge([ 'name' => '', 'real_name_1' => preg_replace('/@.+$/', '', $user['email']), @@ -415,12 +392,11 @@ public function installPlugin($name) * インストール設定ファイルを生成する * * @param array $dbConfig - * @param string $securitySalt * @return boolean * @checked * @noTodo */ - public function createInstallFile(array $dbConfig, string $securitySalt): bool + public function createInstallFile(array $dbConfig): bool { if (!is_writable(ROOT . DS . 'config' . DS)) { return false; @@ -443,18 +419,11 @@ public function createInstallFile(array $dbConfig, string $securitySalt): bool $dbConfig[$key] = addcslashes($value, '\'\\'); } - $basicSettings = [ - 'Security.salt' => $securitySalt - ]; - $installCoreData = [ ' $value) { - $installCoreData[] = ' \'' . $key . '\' => \'' . $value . '\','; - } $installCoreData[] = ' \'Datasources.default\' => ['; foreach($dbConfig as $key => $value) { if($key === 'datasource' || $key === 'dataPattern') continue; diff --git a/plugins/bc-installer/tests/TestCase/Service/InstallationsServiceTest.php b/plugins/bc-installer/tests/TestCase/Service/InstallationsServiceTest.php index 37e42dfe58..28a6073b30 100644 --- a/plugins/bc-installer/tests/TestCase/Service/InstallationsServiceTest.php +++ b/plugins/bc-installer/tests/TestCase/Service/InstallationsServiceTest.php @@ -153,25 +153,6 @@ public function testSetAdminEmailAndVersion() $this->markTestIncomplete('このテストは、まだ実装されていません。'); } - /** - * test setSecuritySalt - */ - public function testSetSecuritySalt() - { - // Test default length (40 characters) - $salt = $this->Installations->setSecuritySalt(); - $this->assertEquals(40, strlen($salt)); - - // Test custom length (e.g., 50 characters) - $customLength = 50; - $customSalt = $this->Installations->setSecuritySalt($customLength); - $this->assertEquals($customLength, strlen($customSalt)); - - // Verify that the salt is correctly written to the configuration - $config = Configure::read('Security.salt'); - $this->assertEquals($customSalt, $config); - } - /** * test addDefaultUser */