diff --git a/src/contracts/Ibexa.php b/src/contracts/Ibexa.php index 60846c500f..5652c9d8d0 100644 --- a/src/contracts/Ibexa.php +++ b/src/contracts/Ibexa.php @@ -13,5 +13,5 @@ final class Ibexa /** * Ibexa DXP Version. */ - public const VERSION = '4.6.19'; + public const VERSION = '4.6.20'; } diff --git a/src/lib/Persistence/Legacy/Content/Location/Mapper.php b/src/lib/Persistence/Legacy/Content/Location/Mapper.php index 4afeb7109e..dc0e933bb0 100644 --- a/src/lib/Persistence/Legacy/Content/Location/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/Location/Mapper.php @@ -14,6 +14,28 @@ */ class Mapper { + public static $IS_PREVIEW_MODE = null; + + /** + * Check if siteaccess is in preview mode. + * Update config/app/services.yaml + * Add the settting in parameters: + * ibexa.{siteaccess_name}.show_hidden_locations: true + * @return bool + */ + public static function isPreviewMode() { + // caching preview mode + if(self::$IS_PREVIEW_MODE === null) { + $container = (method_exists($GLOBALS[ 'app' ], 'getKernel') ? $GLOBALS[ 'app' ]->getKernel()->getContainer() : $GLOBALS[ 'app' ]->getContainer()); + $siteaccessName = $container->get('ibexa.siteaccess')->getCurrent()->name; + if($container->hasParameter( "ibexa.$siteaccessName.show_hidden_locations" )) { + self::$IS_PREVIEW_MODE = $container->getParameter( "ibexa.$siteaccessName.show_hidden_locations" ); + } else { + self::$IS_PREVIEW_MODE = false; + } + } + return self::$IS_PREVIEW_MODE; + } /** * Creates a Location from a $data row. * @@ -33,8 +55,13 @@ public function createLocationFromRow(array $data, $prefix = '', ?Location $loca $location->id = (int)$data[$prefix . 'node_id']; $location->priority = (int)$data[$prefix . 'priority']; - $location->hidden = (bool)$data[$prefix . 'is_hidden']; - $location->invisible = (bool)$data[$prefix . 'is_invisible']; + if(self::isPreviewMode()) { + $location->hidden = false; + $location->invisible = false; + } else { + $location->hidden = (bool)$data[$prefix . 'is_hidden']; + $location->invisible = (bool)$data[$prefix . 'is_invisible']; + } $location->remoteId = $data[$prefix . 'remote_id']; $location->contentId = (int)$data[$prefix . 'contentobject_id']; $location->parentId = (int)$data[$prefix . 'parent_node_id']; diff --git a/src/lib/Search/Legacy/Content/Gateway/CriterionHandler/Visibility.php b/src/lib/Search/Legacy/Content/Gateway/CriterionHandler/Visibility.php index cebcca8901..e74e0499da 100644 --- a/src/lib/Search/Legacy/Content/Gateway/CriterionHandler/Visibility.php +++ b/src/lib/Search/Legacy/Content/Gateway/CriterionHandler/Visibility.php @@ -11,6 +11,7 @@ use Ibexa\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler; +use Ibexa\Core\Persistence\Legacy\Content\Location\Mapper; /** * Visibility criterion handler. @@ -36,29 +37,33 @@ public function handle( array $languageSettings ) { $subSelect = $this->connection->createQueryBuilder(); - - if ($criterion->value[0] === Criterion\Visibility::VISIBLE) { - $expression = $queryBuilder->expr()->andX( - $queryBuilder->expr()->eq( - 'subquery_location.is_hidden', - 0 - ), - $queryBuilder->expr()->eq( - 'subquery_location.is_invisible', - 0 - ) - ); + if(!Mapper::isPreviewMode()) { + if ($criterion->value[0] === Criterion\Visibility::VISIBLE) { + $expression = $queryBuilder->expr()->andX( + $queryBuilder->expr()->eq( + 'subquery_location.is_hidden', + 0 + ), + $queryBuilder->expr()->eq( + 'subquery_location.is_invisible', + 0 + ) + ); + } else { + $expression = $queryBuilder->expr()->orX( + $queryBuilder->expr()->eq( + 'subquery_location.is_hidden', + 1 + ), + $queryBuilder->expr()->eq( + 'subquery_location.is_invisible', + 1 + ) + ); + } } else { - $expression = $queryBuilder->expr()->orX( - $queryBuilder->expr()->eq( - 'subquery_location.is_hidden', - 1 - ), - $queryBuilder->expr()->eq( - 'subquery_location.is_invisible', - 1 - ) - ); + // Dummy query to not break the WHERE statement + $expression = $queryBuilder->expr()->eq( '1', '1' ); } $subSelect diff --git a/src/lib/Search/Legacy/Content/Location/Gateway/CriterionHandler/Visibility.php b/src/lib/Search/Legacy/Content/Location/Gateway/CriterionHandler/Visibility.php index 45fd8742a0..a513296cac 100644 --- a/src/lib/Search/Legacy/Content/Location/Gateway/CriterionHandler/Visibility.php +++ b/src/lib/Search/Legacy/Content/Location/Gateway/CriterionHandler/Visibility.php @@ -12,6 +12,7 @@ use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter; use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler; use RuntimeException; +use Ibexa\Core\Persistence\Legacy\Content\Location\Mapper; /** * Location visibility criterion handler. @@ -37,24 +38,28 @@ public function handle( array $languageSettings ) { $column = 't.is_invisible'; + if(!Mapper::isPreviewMode()) { + switch ($criterion->value[0]) { + case Criterion\Visibility::VISIBLE: + return $queryBuilder->expr()->eq( + $column, + $queryBuilder->createNamedParameter(0, ParameterType::INTEGER) + ); - switch ($criterion->value[0]) { - case Criterion\Visibility::VISIBLE: - return $queryBuilder->expr()->eq( - $column, - $queryBuilder->createNamedParameter(0, ParameterType::INTEGER) - ); + case Criterion\Visibility::HIDDEN: + return $queryBuilder->expr()->eq( + $column, + $queryBuilder->createNamedParameter(1, ParameterType::INTEGER) + ); - case Criterion\Visibility::HIDDEN: - return $queryBuilder->expr()->eq( - $column, - $queryBuilder->createNamedParameter(1, ParameterType::INTEGER) - ); - - default: - throw new RuntimeException( - "Unknown value '{$criterion->value[0]}' for Visibility Criterion handler." - ); + default: + throw new RuntimeException( + "Unknown value '{$criterion->value[0]}' for Visibility Criterion handler." + ); + } + } else { + // Dummy query to not break the WHERE statement + return $queryBuilder->expr()->eq( '1', '1' ); } } }