From fd66137fabece5191e0c60b08678e36e3ce6d61c Mon Sep 17 00:00:00 2001 From: Ryuichi Date: Wed, 2 Dec 2026 11:41:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix=20#4691=20=E5=85=AC=E9=96=8B=E5=81=B4?= =?UTF-8?q?=E3=81=AE=E3=82=B5=E3=82=A4=E3=83=88=E5=86=85=E6=A4=9C=E7=B4=A2?= =?UTF-8?q?=E3=81=AE=E3=82=AB=E3=83=86=E3=82=B4=E3=83=AA=E3=81=AE=E9=81=B8?= =?UTF-8?q?=E6=8A=9E=E8=82=A2=E3=81=AB=E9=9D=9E=E5=85=AC=E9=96=8B=E3=81=AE?= =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AB=E3=83=80=E3=81=8C=E5=87=BA=E3=82=8B?= =?UTF-8?q?=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Front/SearchIndexesFrontService.php | 8 ++++- .../Front/SearchIndexesFrontServiceTest.php | 36 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/plugins/bc-search-index/src/Service/Front/SearchIndexesFrontService.php b/plugins/bc-search-index/src/Service/Front/SearchIndexesFrontService.php index aac076ef19..4f483de9f8 100644 --- a/plugins/bc-search-index/src/Service/Front/SearchIndexesFrontService.php +++ b/plugins/bc-search-index/src/Service/Front/SearchIndexesFrontService.php @@ -20,6 +20,7 @@ use Cake\Datasource\Paging\PaginatedInterface; use Cake\Datasource\ResultSetInterface; use Cake\Http\ServerRequest; +use Cake\ORM\TableRegistry; /** * SearchIndexesFrontService @@ -50,12 +51,17 @@ public function getViewVarsForSearch(PaginatedInterface|ResultSetInterface $sear $currentSiteId = $request->getAttribute('currentSite')->id; $frontForm = new SearchIndexesFrontForm(); $frontForm->setData($request->getQuery()); + // 公開側なので、公開中のフォルダだけにする(親フォルダの公開状態は status・publish_begin・publish_end に反映されている) + $contentsTable = TableRegistry::getTableLocator()->get('BaserCore.Contents'); return [ 'searchIndexes' => $searchIndexes, 'query' => $this->parseQuery($request->getQuery('q')), 'contentFolders' => $contentsService->getContentFolderList( $currentSiteId, - ['excludeId' => $contentsService->getSiteRoot($currentSiteId)['id']] + [ + 'excludeId' => $contentsService->getSiteRoot($currentSiteId)['id'], + 'conditions' => $contentsTable->getConditionAllowPublish() + ] ), 'searchIndexesFront' => $frontForm ]; diff --git a/plugins/bc-search-index/tests/TestCase/Service/Front/SearchIndexesFrontServiceTest.php b/plugins/bc-search-index/tests/TestCase/Service/Front/SearchIndexesFrontServiceTest.php index a11f5cbf4e..a90ec093ba 100644 --- a/plugins/bc-search-index/tests/TestCase/Service/Front/SearchIndexesFrontServiceTest.php +++ b/plugins/bc-search-index/tests/TestCase/Service/Front/SearchIndexesFrontServiceTest.php @@ -19,6 +19,7 @@ use BcSearchIndex\Controller\SearchIndexesController; use BcSearchIndex\Service\Front\SearchIndexesFrontServiceInterface; use BcSearchIndex\Service\SearchIndexesServiceInterface; +use Cake\ORM\TableRegistry; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; /** @@ -76,4 +77,39 @@ public function test_getViewVarsForSearch(): void $this->assertTrue(isset($vars['searchIndexesFront'])); } + /** + * Test getViewVarsForSearch + * contentFolders に公開中のフォルダだけが入る + * + * @return void + */ + public function test_getViewVarsForSearch_contentFoldersPublishedOnly(): void + { + $this->loadFixtureScenario(InitAppScenario::class); + ContentFactory::make()->treeNode(1, 1, null, 'root', '/', 1, true)->setField('type', 'ContentFolder')->persist(); + // 公開 + ContentFactory::make()->treeNode(2, 1, 1, 'public', '/public/', 2, false, 'public')->setField('type', 'ContentFolder')->persist(); + // 非公開 + ContentFactory::make()->treeNode(3, 1, 1, 'private', '/private/', 3, false, 'private')->setField('type', 'ContentFolder') + ->setField('status', false)->persist(); + // 公開期間(終了) + ContentFactory::make()->treeNode(4, 1, 1, 'ended', '/ended/', 4, false, 'ended')->setField('type', 'ContentFolder') + ->setField('publish_end', '2000-01-01 00:00:00')->persist(); + // 公開期間(開始前) + ContentFactory::make()->treeNode(5, 1, 1, 'future', '/future/', 5, false, 'future')->setField('type', 'ContentFolder') + ->setField('publish_begin', '2100-01-01 00:00:00')->persist(); + // 非公開のフォルダの下のフォルダ(親に合わせて status が false になる) + ContentFactory::make()->treeNode(6, 1, 3, 'child', '/private/child/', 6, false, 'child')->setField('type', 'ContentFolder') + ->setField('status', false)->persist(); + TableRegistry::getTableLocator()->get('BaserCore.Contents')->recover(); + + $controller = new SearchIndexesController($this->getRequest()); + $service = $this->getService(SearchIndexesServiceInterface::class); + $frontService = $this->getService(SearchIndexesFrontServiceInterface::class); + $searchIndexes = $controller->paginate($service->getIndex()); + $request = $this->getRequest()->withAttribute('currentSite', SiteFactory::get(1))->withQueryParams(['q' => 'test']); + $vars = $frontService->getViewVarsForSearch($searchIndexes, $request); + $this->assertEquals([2], array_keys($vars['contentFolders'])); + } + } From 3487c4c527822e1057ea085de405ba7b757adf40 Mon Sep 17 00:00:00 2001 From: Ryuichi Date: Wed, 2 Dec 2026 12:50:00 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E3=83=AC=E3=83=93=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Service/Front/SearchIndexesFrontService.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/bc-search-index/src/Service/Front/SearchIndexesFrontService.php b/plugins/bc-search-index/src/Service/Front/SearchIndexesFrontService.php index 4f483de9f8..067b2447fd 100644 --- a/plugins/bc-search-index/src/Service/Front/SearchIndexesFrontService.php +++ b/plugins/bc-search-index/src/Service/Front/SearchIndexesFrontService.php @@ -20,7 +20,6 @@ use Cake\Datasource\Paging\PaginatedInterface; use Cake\Datasource\ResultSetInterface; use Cake\Http\ServerRequest; -use Cake\ORM\TableRegistry; /** * SearchIndexesFrontService @@ -51,8 +50,6 @@ public function getViewVarsForSearch(PaginatedInterface|ResultSetInterface $sear $currentSiteId = $request->getAttribute('currentSite')->id; $frontForm = new SearchIndexesFrontForm(); $frontForm->setData($request->getQuery()); - // 公開側なので、公開中のフォルダだけにする(親フォルダの公開状態は status・publish_begin・publish_end に反映されている) - $contentsTable = TableRegistry::getTableLocator()->get('BaserCore.Contents'); return [ 'searchIndexes' => $searchIndexes, 'query' => $this->parseQuery($request->getQuery('q')), @@ -60,7 +57,7 @@ public function getViewVarsForSearch(PaginatedInterface|ResultSetInterface $sear $currentSiteId, [ 'excludeId' => $contentsService->getSiteRoot($currentSiteId)['id'], - 'conditions' => $contentsTable->getConditionAllowPublish() + 'conditions' => $contentsService->getConditionAllowPublish() ] ), 'searchIndexesFront' => $frontForm