Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 18 additions & 30 deletions bundle/Controller/Admin/ProtectedAccessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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(
Expand All @@ -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 = [];
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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!'