From 7074cfa1e148aabb76b31b89e73eded2ad7e74de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20LIMOUZIN?= Date: Tue, 27 May 2025 14:45:06 +0200 Subject: [PATCH] Add a state --- .../Admin/ProtectedAccessController.php | 48 +++++++------------ ...8334803_105270_nova_content_protected.yaml | 43 +++++++++++++++++ 2 files changed, 61 insertions(+), 30 deletions(-) create mode 100644 bundle/Migrations/Ibexa/migrations/1748334803_105270_nova_content_protected.yaml diff --git a/bundle/Controller/Admin/ProtectedAccessController.php b/bundle/Controller/Admin/ProtectedAccessController.php index e57ef69..cb06456 100644 --- a/bundle/Controller/Admin/ProtectedAccessController.php +++ b/bundle/Controller/Admin/ProtectedAccessController.php @@ -31,6 +31,10 @@ class ProtectedAccessController { + public const GROUP='nova_protected_content'; + public const STATE_DEFAULT='default'; + public const STATE_PROTECTED='protected'; + public function __construct( protected readonly Repository $repository, protected readonly \Ibexa\Contracts\Core\Search\Handler $searchHandler, @@ -69,9 +73,9 @@ public function handle( $responseTagger->addParentLocationTags([$location->parentLocationId]); $content = $location->getContent(); - $this->reindexContent($content); + $this->setState($content, SELF::STATE_DEFAULT); if ($access->isProtectChildren()) { - $this->reindexChildren($content); + $this->updateChildrenState($content, SELF::STATE_DEFAULT); } } } @@ -99,9 +103,9 @@ public function remove( $responseTagger->addParentLocationTags([$location->parentLocationId]); $content = $location->getContent(); - $this->reindexContent($content); + $this->setState($content, SELF::STATE_DEFAULT); if ($access->isProtectChildren()) { - $this->reindexChildren($content); + $this->updateChildrenState($content, SELF::STATE_DEFAULT); } return new RedirectResponse( @@ -112,26 +116,7 @@ public function remove( ); } - /** - * @param Content $content - * @return void - */ - protected function reindexContent(Content $content) - { - $contentId = $content->id; - $contentVersionNo = $content->getVersionInfo()->versionNo; - - $this->searchHandler->indexContent( - $this->persistenceHandler->contentHandler()->load($contentId, $contentVersionNo) - ); - - $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentId); - foreach ($locations as $location) { - $this->searchHandler->indexLocation($location); - } - } - - protected function reindexChildren(Content $content, int $limit = 100) + protected function updateChildrenState(Content $content, string $state): void { $locations = $this->repository->getLocationService()->loadLocations($content->contentInfo); $pathStringArray = []; @@ -142,18 +127,21 @@ protected function reindexChildren(Content $content, int $limit = 100) if ($pathStringArray) { $query = new Query(); - $query->limit = $limit; + $query->limit = 100; $query->filter = new Query\Criterion\LogicalAnd([ new Query\Criterion\Subtree($pathStringArray) ]); - $query->sortClauses = [ - new Query\SortClause\ContentId(), - // new Query\SortClause\Visibility(), // domage.. - ]; $searchResult = $this->repository->getSearchService()->findContent($query); foreach ($searchResult->searchHits as $hit) { - $this->reindexContent($hit->valueObject); + $this->setState($hit->valueObject, $state); } } } + + public function setState(Content $content, string $state): void + { + $group = $this->repository->getObjectStateService()->loadObjectStateGroupByIdentifier(self::GROUP); + $state = $this->repository->getObjectStateService()->loadObjectStateByIdentifier($group,$state); + $this->repository->getObjectStateService()->setContentState($content->getContentInfo(), $group, $state); + } } diff --git a/bundle/Migrations/Ibexa/migrations/1748334803_105270_nova_content_protected.yaml b/bundle/Migrations/Ibexa/migrations/1748334803_105270_nova_content_protected.yaml new file mode 100644 index 0000000..e616adf --- /dev/null +++ b/bundle/Migrations/Ibexa/migrations/1748334803_105270_nova_content_protected.yaml @@ -0,0 +1,43 @@ +- + type: object_state_group + mode: create + metadata: + identifier: nova_content_protected + mainTranslation: fre-FR + translations: + fre-FR: + name: Nova Protection des contenus + description: 'Par mot de passe ou email. Ne pas changer manuellement !' +# eng-US: +# name: Nova-Content-Protected +# description: 'By password or email. Do not change manually!' +- + type: object_state + mode: create + metadata: + identifier: default + mainTranslation: fre-FR + objectStateGroup: nova_content_protected + priority: 1 + translations: + fre-FR: + name: Défaut + description: 'Pas de protection par défaut. Ne pas changer manuellement !' +# eng-US: +# name: Default +# description: 'No protection by default. Do not change manually!' +- + type: object_state + mode: create + metadata: + identifier: protected + mainTranslation: fre-FR + objectStateGroup: nova_content_protected + priority: 1 + translations: + fre-FR: + name: Protégé + description: 'Protégé par un mot de passe ou par email. Ne pas changer manuellement !' +# eng-US: +# name: Protected +# description: 'Protected by password or email. Do not change manually!'