From 8d505718675e48db5255d0de37a3ddb8d557e5fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 26 Nov 2014 13:46:15 +0100 Subject: [PATCH 01/16] EZP-23129: update sort clause handlers to use field map --- .../Common/Gateway/SortClauseConverter.php | 6 +- .../Common/Gateway/SortClauseHandler.php | 3 +- .../Gateway/SortClauseHandler/Field.php | 92 +++++++++---------- .../SortClauseHandler/MapLocationDistance.php | 61 ++++-------- .../Gateway/SortClauseHandler/SectionName.php | 3 +- 5 files changed, 66 insertions(+), 99 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseConverter.php b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseConverter.php index 3cfad5201c0..deb0ca06922 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseConverter.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseConverter.php @@ -88,8 +88,9 @@ public function applySelect( SelectQuery $query, array $sortClauses ) * * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause[] $sortClauses + * @param array $fieldMap */ - public function applyJoin( SelectQuery $query, array $sortClauses ) + public function applyJoin( SelectQuery $query, array $sortClauses, array $fieldMap ) { foreach ( $sortClauses as $nr => $sortClause ) { @@ -97,7 +98,7 @@ public function applyJoin( SelectQuery $query, array $sortClauses ) { if ( $handler->accept( $sortClause ) ) { - $handler->applyJoin( $query, $sortClause, $nr ); + $handler->applyJoin( $query, $sortClause, $nr, $fieldMap ); continue 2; } } @@ -120,7 +121,6 @@ public function applyOrderBy( SelectQuery $query ) $direction === Query::SORT_ASC ? SelectQuery::ASC : SelectQuery::DESC ); } - // @todo Review needed // The following line was added because without it, loading sub user groups through the Public API // fails with the database error "Unknown column sort_column_0". The change does not break any diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler.php b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler.php index fb0685f9034..cbe65877148 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler.php @@ -64,8 +64,9 @@ abstract public function applySelect( SelectQuery $query, SortClause $sortClause * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause $sortClause * @param int $number + * @param array $fieldMap */ - public function applyJoin( SelectQuery $query, SortClause $sortClause, $number ) + public function applyJoin( SelectQuery $query, SortClause $sortClause, $number, array $fieldMap ) { } diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/Field.php b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/Field.php index df88a84355f..637eae8e9e0 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/Field.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/Field.php @@ -15,6 +15,7 @@ use eZ\Publish\API\Repository\Values\Content\Query\SortClause; use eZ\Publish\SPI\Persistence\Content\Type; use eZ\Publish\Core\Persistence\Database\SelectQuery; +use PDO; /** * Content locator gateway implementation using the DoctrineDatabase. @@ -68,23 +69,45 @@ public function applySelect( SelectQuery $query, SortClause $sortClause, $number { $query ->select( + $query->alias( + $query->expr->not( + $query->expr->isNull( + $this->dbHandler->quoteColumn( + "sort_key_int", + $this->getSortTableName( $number ) + ) + ) + ), + $column1 = $this->getSortColumnName( $number . "_null" ) + ), + $query->alias( + $query->expr->not( + $query->expr->isNull( + $this->dbHandler->quoteColumn( + "sort_key_string", + $this->getSortTableName( $number ) + ) + ) + ), + $column2 = $this->getSortColumnName( $number . "_bis_null" ) + ), $query->alias( $this->dbHandler->quoteColumn( "sort_key_int", $this->getSortTableName( $number ) ), - $column1 = $this->getSortColumnName( $number ) + $column3 = $this->getSortColumnName( $number ) ), $query->alias( $this->dbHandler->quoteColumn( "sort_key_string", $this->getSortTableName( $number ) ), - $column2 = $this->getSortColumnName( $number . "_bis" ) + $column4 = $this->getSortColumnName( $number . "_bis" ) ) ); - return array( $column1, $column2 ); + return array( $column1, $column2, $column3, $column4 ); } /** @@ -93,25 +116,30 @@ public function applySelect( SelectQuery $query, SortClause $sortClause, $number * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause $sortClause * @param int $number + * @param array $fieldMap * * @return void */ - public function applyJoin( SelectQuery $query, SortClause $sortClause, $number ) + public function applyJoin( SelectQuery $query, SortClause $sortClause, $number, array $fieldMap ) { /** @var \eZ\Publish\API\Repository\Values\Content\Query\SortClause\Target\FieldTarget $fieldTarget */ $fieldTarget = $sortClause->targetData; + $fieldDefinitionId = $fieldMap[$fieldTarget->typeIdentifier][$fieldTarget->fieldIdentifier]; $table = $this->getSortTableName( $number ); if ( $fieldTarget->languageCode === null ) { - $linkTable = $table; $query - ->innerJoin( + ->leftJoin( $query->alias( $this->dbHandler->quoteTable( "ezcontentobject_attribute" ), $this->dbHandler->quoteIdentifier( $table ) ), $query->expr->lAnd( + $query->expr->eq( + $query->bindValue( $fieldDefinitionId, null, PDO::PARAM_INT ), + $this->dbHandler->quoteColumn( "contentclassattribute_id", $table ) + ), $query->expr->eq( $this->dbHandler->quoteColumn( "contentobject_id", $table ), $this->dbHandler->quoteColumn( "id", "ezcontentobject" ) @@ -134,12 +162,16 @@ public function applyJoin( SelectQuery $query, SortClause $sortClause, $number ) { $linkTable = $table . "_main_language"; $query - ->innerJoin( + ->leftJoin( $query->alias( $this->dbHandler->quoteTable( "ezcontentobject_attribute" ), $this->dbHandler->quoteIdentifier( $linkTable ) ), $query->expr->lAnd( + $query->expr->eq( + $query->bindValue( $fieldDefinitionId, null, PDO::PARAM_INT ), + $this->dbHandler->quoteColumn( "contentclassattribute_id", $linkTable ) + ), $query->expr->eq( $this->dbHandler->quoteColumn( "contentobject_id", $linkTable ), $this->dbHandler->quoteColumn( "id", "ezcontentobject" ) @@ -163,6 +195,10 @@ public function applyJoin( SelectQuery $query, SortClause $sortClause, $number ) $this->dbHandler->quoteIdentifier( $table ) ), $query->expr->lAnd( + $query->expr->eq( + $query->bindValue( $fieldDefinitionId, null, PDO::PARAM_INT ), + $this->dbHandler->quoteColumn( "contentclassattribute_id", $table ) + ), $query->expr->eq( $this->dbHandler->quoteColumn( "contentobject_id", $linkTable ), $this->dbHandler->quoteColumn( "contentobject_id", $table ) @@ -189,47 +225,5 @@ public function applyJoin( SelectQuery $query, SortClause $sortClause, $number ) ) ); } - - $query - ->innerJoin( - $query->alias( - $this->dbHandler->quoteTable( "ezcontentclass_attribute" ), - $this->dbHandler->quoteIdentifier( "cc_attr_$number" ) - ), - $query->expr->lAnd( - $query->expr->eq( - $this->dbHandler->quoteColumn( "contentclassattribute_id", $linkTable ), - $this->dbHandler->quoteColumn( "id", "cc_attr_$number" ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "identifier", "cc_attr_$number" ), - $query->bindValue( $fieldTarget->fieldIdentifier ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "version", "cc_attr_$number" ), - $query->bindValue( Type::STATUS_DEFINED, null, \PDO::PARAM_INT ) - ) - ) - ) - ->innerJoin( - $query->alias( - $this->dbHandler->quoteTable( "ezcontentclass" ), - $this->dbHandler->quoteIdentifier( "cc_$number" ) - ), - $query->expr->lAnd( - $query->expr->eq( - $this->dbHandler->quoteColumn( "contentclass_id", "cc_attr_$number" ), - $this->dbHandler->quoteColumn( "id", "cc_$number" ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "identifier", "cc_$number" ), - $query->bindValue( $fieldTarget->typeIdentifier ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "version", "cc_$number" ), - $query->bindValue( Type::STATUS_DEFINED, null, \PDO::PARAM_INT ) - ) - ) - ); } } diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/MapLocationDistance.php b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/MapLocationDistance.php index f966e60f2a4..2390fcc42c3 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/MapLocationDistance.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/MapLocationDistance.php @@ -15,6 +15,7 @@ use eZ\Publish\API\Repository\Values\Content\Query\SortClause; use eZ\Publish\SPI\Persistence\Content\Type; use eZ\Publish\Core\Persistence\Database\SelectQuery; +use PDO; /** * Content locator gateway implementation using the DoctrineDatabase. @@ -114,25 +115,31 @@ public function applySelect( SelectQuery $query, SortClause $sortClause, $number * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause $sortClause * @param int $number + * @param array $fieldMap * * @return void */ - public function applyJoin( SelectQuery $query, SortClause $sortClause, $number ) + public function applyJoin( SelectQuery $query, SortClause $sortClause, $number, array $fieldMap ) { /** @var \eZ\Publish\API\Repository\Values\Content\Query\SortClause\Target\FieldTarget $fieldTarget */ $fieldTarget = $sortClause->targetData; + $fieldDefinitionId = $fieldMap[$fieldTarget->typeIdentifier][$fieldTarget->fieldIdentifier]; $table = $this->getSortTableName( $number ); $externalTable = $this->getSortTableName( $number, "ezgmaplocation" ); if ( $fieldTarget->languageCode === null ) { $query - ->innerJoin( + ->leftJoin( $query->alias( $this->dbHandler->quoteTable( "ezcontentobject_attribute" ), $this->dbHandler->quoteIdentifier( $table ) ), $query->expr->lAnd( + $query->expr->eq( + $query->bindValue( $fieldDefinitionId, null, PDO::PARAM_INT ), + $this->dbHandler->quoteColumn( "contentclassattribute_id", $table ) + ), $query->expr->eq( $this->dbHandler->quoteColumn( "contentobject_id", $table ), $this->dbHandler->quoteColumn( "id", "ezcontentobject" ) @@ -154,12 +161,16 @@ public function applyJoin( SelectQuery $query, SortClause $sortClause, $number ) else { $query - ->innerJoin( + ->leftJoin( $query->alias( $this->dbHandler->quoteTable( "ezcontentobject_attribute" ), $this->dbHandler->quoteIdentifier( $table ) ), $query->expr->lAnd( + $query->expr->eq( + $query->bindValue( $fieldDefinitionId, null, PDO::PARAM_INT ), + $this->dbHandler->quoteColumn( "contentclassattribute_id", $table ) + ), $query->expr->eq( $this->dbHandler->quoteColumn( "contentobject_id", $table ), $this->dbHandler->quoteColumn( "id", "ezcontentobject" ) @@ -174,7 +185,7 @@ public function applyJoin( SelectQuery $query, SortClause $sortClause, $number ) $query->bindValue( $this->languageHandler->loadByLanguageCode( $fieldTarget->languageCode )->id, null, - \PDO::PARAM_INT + PDO::PARAM_INT ) ), 0 @@ -184,7 +195,7 @@ public function applyJoin( SelectQuery $query, SortClause $sortClause, $number ) } $query - ->innerJoin( + ->leftJoin( $query->alias( $this->dbHandler->quoteTable( "ezgmaplocation" ), $this->dbHandler->quoteIdentifier( $externalTable ) @@ -199,46 +210,6 @@ public function applyJoin( SelectQuery $query, SortClause $sortClause, $number ) $this->dbHandler->quoteColumn( "id", $table ) ) ) - ) - ->innerJoin( - $query->alias( - $this->dbHandler->quoteTable( "ezcontentclass_attribute" ), - $this->dbHandler->quoteIdentifier( "cc_attr_$number" ) - ), - $query->expr->lAnd( - $query->expr->eq( - $this->dbHandler->quoteColumn( "contentclassattribute_id", $table ), - $this->dbHandler->quoteColumn( "id", "cc_attr_$number" ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "identifier", "cc_attr_$number" ), - $query->bindValue( $fieldTarget->fieldIdentifier ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "version", "cc_attr_$number" ), - $query->bindValue( Type::STATUS_DEFINED, null, \PDO::PARAM_INT ) - ) - ) - ) - ->innerJoin( - $query->alias( - $this->dbHandler->quoteTable( "ezcontentclass" ), - $this->dbHandler->quoteIdentifier( "cc_$number" ) - ), - $query->expr->lAnd( - $query->expr->eq( - $this->dbHandler->quoteColumn( "contentclass_id", "cc_attr_$number" ), - $this->dbHandler->quoteColumn( "id", "cc_$number" ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "identifier", "cc_$number" ), - $query->bindValue( $fieldTarget->typeIdentifier ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "version", "cc_$number" ), - $query->bindValue( Type::STATUS_DEFINED, null, \PDO::PARAM_INT ) - ) - ) ); } } diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/SectionName.php b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/SectionName.php index d7783058ffa..630e91f8741 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/SectionName.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/SectionName.php @@ -64,10 +64,11 @@ public function applySelect( SelectQuery $query, SortClause $sortClause, $number * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause $sortClause * @param int $number + * @param array $fieldMap * * @return void */ - public function applyJoin( SelectQuery $query, SortClause $sortClause, $number ) + public function applyJoin( SelectQuery $query, SortClause $sortClause, $number, array $fieldMap ) { $table = $this->getSortTableName( $number ); $query From 33b09479d74682ab5b52c09a0f15f94baf9b5705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 26 Nov 2014 13:46:56 +0100 Subject: [PATCH 02/16] EZP-23129: dispatch field map to sort clause handlers --- .../Search/Gateway/DoctrineDatabase.php | 69 +++++++++++++++++-- .../Location/Gateway/DoctrineDatabase.php | 63 +++++++++++++++-- 2 files changed, 122 insertions(+), 10 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php index 6bacf9acd1a..0a2b5987405 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php @@ -118,13 +118,14 @@ public function find( Criterion $filter, $offset = 0, $limit = null, array $sort { $limit = $limit !== null ? $limit : self::MAX_LIMIT; - $count = $this->getResultCount( $filter, $sort, $translations ); + $fieldMap = $this->getFieldMap(); + $count = $this->getResultCount( $filter, $sort, $translations, $fieldMap ); if ( $limit === 0 || $count <= $offset ) { return array( 'count' => $count, 'rows' => array() ); } - $contentInfoList = $this->getContentInfoList( $filter, $sort, $offset, $limit, $translations ); + $contentInfoList = $this->getContentInfoList( $filter, $sort, $offset, $limit, $translations, $fieldMap ); return array( 'count' => $count, @@ -188,8 +189,9 @@ protected function getQueryCondition( Criterion $filter, SelectQuery $query, $tr * @param array $sort * @param mixed $translations * @return int + * @param array $fieldMap */ - protected function getResultCount( Criterion $filter, $sort, $translations ) + protected function getResultCount( Criterion $filter, $sort, $translations, array $fieldMap ) { $query = $this->handler->createSelectQuery(); @@ -203,9 +205,10 @@ protected function getResultCount( Criterion $filter, $sort, $translations ) 'ezcontentobject_version.contentobject_id' ); + // Should be possible to remove it now, since Field sort clauses do not filter any more if ( $sort !== null ) { - $this->sortClauseConverter->applyJoin( $query, $sort ); + $this->sortClauseConverter->applyJoin( $query, $sort, $fieldMap ); } $query->where( @@ -226,10 +229,11 @@ protected function getResultCount( Criterion $filter, $sort, $translations ) * @param mixed $offset * @param mixed $limit * @param mixed $translations + * @param array $fieldMap * * @return int[] */ - protected function getContentInfoList( Criterion $filter, $sort, $offset, $limit, $translations ) + protected function getContentInfoList( Criterion $filter, $sort, $offset, $limit, $translations, array $fieldMap ) { $query = $this->handler->createSelectQuery(); $query->select( @@ -268,7 +272,7 @@ protected function getContentInfoList( Criterion $filter, $sort, $offset, $limit if ( $sort !== null ) { - $this->sortClauseConverter->applyJoin( $query, $sort ); + $this->sortClauseConverter->applyJoin( $query, $sort, $fieldMap ); } $query->where( @@ -287,5 +291,58 @@ protected function getContentInfoList( Criterion $filter, $sort, $offset, $limit return $statement->fetchAll( \PDO::FETCH_ASSOC ); } + + /** + * Returns field mapping data + * + * Returns an associative array with ContentType and FieldDefinition identifiers as + * first and second level keys respectively, and FieldDefinition ID as value. + * + * @todo Implement this in ContentType Handler using stash + * + * @return array + */ + protected function getFieldMap() + { + $query = $this->handler->createSelectQuery(); + $query + ->select( + $this->handler->alias( + $this->handler->quoteColumn( "id", "ezcontentclass_attribute" ), + $this->handler->quoteIdentifier( "field_id" ) + ), + $this->handler->alias( + $this->handler->quoteColumn( "identifier", "ezcontentclass_attribute" ), + $this->handler->quoteIdentifier( "field_identifier" ) + ), + $this->handler->alias( + $this->handler->quoteColumn( "identifier", "ezcontentclass" ), + $this->handler->quoteIdentifier( "type_identifier" ) + ) + ) + ->from( + $this->handler->quoteTable( "ezcontentclass_attribute" ) + ) + ->innerJoin( + $this->handler->quoteTable( "ezcontentclass" ), + $query->expr->eq( + $this->handler->quoteColumn( "contentclass_id", "ezcontentclass_attribute" ), + $this->handler->quoteColumn( "id", "ezcontentclass" ) + ) + ); + + $statement = $query->prepare( $query ); + $statement->execute(); + + $map = array(); + $rows= $statement->fetchAll( \PDO::FETCH_ASSOC ); + + foreach ( $rows as $row ) + { + $map[$row["type_identifier"]][$row["field_identifier"]] = $row["field_id"]; + } + + return $map; + } } diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Location/Gateway/DoctrineDatabase.php b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Location/Gateway/DoctrineDatabase.php index 9c36112521a..b514101e084 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Location/Gateway/DoctrineDatabase.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Location/Gateway/DoctrineDatabase.php @@ -75,7 +75,8 @@ public function __construct( */ public function find( Criterion $criterion, $offset = 0, $limit = null, array $sortClauses = null ) { - $count = $this->getTotalCount( $criterion, $sortClauses ); + $fieldMap = $this->getFieldMap(); + $count = $this->getTotalCount( $criterion, $sortClauses, $fieldMap ); if ( $limit === 0 ) { return array( "count" => $count, "rows" => array() ); @@ -104,7 +105,7 @@ public function find( Criterion $criterion, $offset = 0, $limit = null, array $s if ( $sortClauses !== null ) { - $this->sortClauseConverter->applyJoin( $selectQuery, $sortClauses ); + $this->sortClauseConverter->applyJoin( $selectQuery, $sortClauses, $fieldMap ); } $selectQuery->where( @@ -149,10 +150,11 @@ public function find( Criterion $criterion, $offset = 0, $limit = null, array $s * * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * @param null|\eZ\Publish\API\Repository\Values\Content\Query\SortClause[] $sortClauses + * @param array $fieldMap * * @return array */ - protected function getTotalCount( Criterion $criterion, $sortClauses ) + protected function getTotalCount( Criterion $criterion, $sortClauses, array $fieldMap ) { $query = $this->handler->createSelectQuery(); $query @@ -171,7 +173,7 @@ protected function getTotalCount( Criterion $criterion, $sortClauses ) if ( $sortClauses !== null ) { - $this->sortClauseConverter->applyJoin( $query, $sortClauses ); + $this->sortClauseConverter->applyJoin( $query, $sortClauses, $fieldMap ); } $query->where( @@ -198,4 +200,57 @@ protected function getTotalCount( Criterion $criterion, $sortClauses ) $res = $statement->fetchAll( PDO::FETCH_ASSOC ); return (int)$res[0]['count']; } + + /** + * Returns field mapping data + * + * Returns an associative array with ContentType and FieldDefinition identifiers as + * first and second level keys respectively, and FieldDefinition ID as value. + * + * @todo Implement this in ContentType Handler using stash + * + * @return array + */ + protected function getFieldMap() + { + $query = $this->handler->createSelectQuery(); + $query + ->select( + $this->handler->alias( + $this->handler->quoteColumn( "id", "ezcontentclass_attribute" ), + $this->handler->quoteIdentifier( "field_id" ) + ), + $this->handler->alias( + $this->handler->quoteColumn( "identifier", "ezcontentclass_attribute" ), + $this->handler->quoteIdentifier( "field_identifier" ) + ), + $this->handler->alias( + $this->handler->quoteColumn( "identifier", "ezcontentclass" ), + $this->handler->quoteIdentifier( "type_identifier" ) + ) + ) + ->from( + $this->handler->quoteTable( "ezcontentclass_attribute" ) + ) + ->innerJoin( + $this->handler->quoteTable( "ezcontentclass" ), + $query->expr->eq( + $this->handler->quoteColumn( "contentclass_id", "ezcontentclass_attribute" ), + $this->handler->quoteColumn( "id", "ezcontentclass" ) + ) + ); + + $statement = $query->prepare( $query ); + $statement->execute(); + + $map = array(); + $rows= $statement->fetchAll( \PDO::FETCH_ASSOC ); + + foreach ( $rows as $row ) + { + $map[$row["type_identifier"]][$row["field_identifier"]] = $row["field_id"]; + } + + return $map; + } } From 69a7e8eb2943c36bd0971f3940711545875bdca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 26 Nov 2014 13:47:40 +0100 Subject: [PATCH 03/16] EZP-23129: update fixture for changed behaviour --- .../_fixtures/Legacy/SortTemplateTitle.php | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortTemplateTitle.php b/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortTemplateTitle.php index 7acfe40bc62..e0965f12341 100644 --- a/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortTemplateTitle.php +++ b/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortTemplateTitle.php @@ -1,27 +1,38 @@ - array ( - ), - 'searchHits' => - array ( - 0 => - eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( - 'valueObject' => - array ( - 'id' => 54, - 'title' => 'eZ Publish Demo Design (without demo content)', - ), - 'score' => NULL, - 'index' => NULL, - 'highlight' => NULL, - )), - ), - 'spellSuggestion' => NULL, - 'time' => 1, - 'timedOut' => NULL, - 'maxScore' => NULL, - 'totalCount' => 1, + 'facets' => + array ( + ), + 'searchHits' => + array ( + 0 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 56, + 'title' => 'Design', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 1 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 54, + 'title' => 'eZ Publish Demo Design (without demo content)', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + ), + 'spellSuggestion' => NULL, + 'time' => 1, + 'timedOut' => NULL, + 'maxScore' => NULL, + 'totalCount' => 2, )); From b8a51495be158c600cda7cc48ed4ac736f48a62c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 26 Nov 2014 13:48:21 +0100 Subject: [PATCH 04/16] EZP-23129: add tests --- .../Repository/Tests/SearchServiceTest.php | 25 +++ .../Legacy/SortFieldMultipleTypes.php | 148 ++++++++++++++++++ .../Legacy/SortFieldMultipleTypesSlice.php | 70 +++++++++ 3 files changed, 243 insertions(+) create mode 100644 eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypes.php create mode 100644 eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypesSlice.php diff --git a/eZ/Publish/API/Repository/Tests/SearchServiceTest.php b/eZ/Publish/API/Repository/Tests/SearchServiceTest.php index a7d08a1e87c..ec951819eed 100644 --- a/eZ/Publish/API/Repository/Tests/SearchServiceTest.php +++ b/eZ/Publish/API/Repository/Tests/SearchServiceTest.php @@ -1133,6 +1133,31 @@ function ( $a, $b ) ), $fixtureDir . 'SortFolderName.php', ), + array( + array( + 'filter' => new Criterion\ContentTypeId( array( 1, 3 ) ), + 'offset' => 0, + 'limit' => null, + 'sortClauses' => array( + new SortClause\Field( "folder", "name", Query::SORT_ASC, "eng-US" ), + new SortClause\ContentId(), + ) + ), + $fixtureDir . 'SortFieldMultipleTypes.php', + ), + array( + array( + 'filter' => new Criterion\ContentTypeId( array( 1, 3 ) ), + 'offset' => 3, + 'limit' => 5, + 'sortClauses' => array( + new SortClause\Field( "folder", "name", Query::SORT_ASC, "eng-US" ), + new SortClause\Field( "template_look", "title", Query::SORT_ASC ), + new SortClause\ContentId(), + ) + ), + $fixtureDir . 'SortFieldMultipleTypesSlice.php', + ), ); } diff --git a/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypes.php b/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypes.php new file mode 100644 index 00000000000..f445a4f766b --- /dev/null +++ b/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypes.php @@ -0,0 +1,148 @@ + + array ( + ), + 'searchHits' => + array ( + 0 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 4, + 'title' => 'Users', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 1 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 11, + 'title' => 'Members', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 2 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 12, + 'title' => 'Administrator users', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 3 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 13, + 'title' => 'Editors', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 4 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 42, + 'title' => 'Anonymous Users', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 5 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 59, + 'title' => 'Partners', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 6 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 56, + 'title' => 'Design', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 7 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 50, + 'title' => 'Files', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 8 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 49, + 'title' => 'Images', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 9 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 41, + 'title' => 'Media', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 10 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 51, + 'title' => 'Multimedia', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 11 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 45, + 'title' => 'Setup', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + + ), + 'spellSuggestion' => NULL, + 'time' => 1, + 'timedOut' => NULL, + 'maxScore' => NULL, + 'totalCount' => 12, +)); diff --git a/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypesSlice.php b/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypesSlice.php new file mode 100644 index 00000000000..414c52165a6 --- /dev/null +++ b/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypesSlice.php @@ -0,0 +1,70 @@ + + array ( + ), + 'searchHits' => + array ( + 0 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 13, + 'title' => 'Editors', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 1 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 42, + 'title' => 'Anonymous Users', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 2 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 59, + 'title' => 'Partners', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 3 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 56, + 'title' => 'Design', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 4 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 50, + 'title' => 'Files', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + ), + 'spellSuggestion' => NULL, + 'time' => 1, + 'timedOut' => NULL, + 'maxScore' => NULL, + 'totalCount' => 12, +)); From b60dcfc645c558e8ca48d48e3c40f7193dbc2af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 26 Nov 2014 13:50:17 +0100 Subject: [PATCH 05/16] EZP-23129: update test for non-filtering behaviour --- .../Content/LocationSearchHandlerSortTest.php | 15 +++++++++++++-- .../Tests/Content/SearchHandlerSortTest.php | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LocationSearchHandlerSortTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LocationSearchHandlerSortTest.php index 8d71dd7baa4..067519a0980 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LocationSearchHandlerSortTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LocationSearchHandlerSortTest.php @@ -93,6 +93,7 @@ protected function getLocationSearchHandler() new CommonCriterionHandler\LogicalAnd( $this->getDatabaseHandler() ), new CommonCriterionHandler\MatchAll( $this->getDatabaseHandler() ), new CommonCriterionHandler\SectionId( $this->getDatabaseHandler() ), + new CommonCriterionHandler\ContentTypeIdentifier( $this->getDatabaseHandler() ), ) ), new SortClauseConverter( @@ -526,7 +527,12 @@ public function testSortFieldText() $result = $handler->findLocations( new LocationQuery( array( - 'filter' => new Criterion\SectionId( array( 1 ) ), + 'filter' => new Criterion\LogicalAnd( + array( + new Criterion\SectionId( array( 1 ) ), + new Criterion\ContentTypeIdentifier( array( "article" ) ), + ) + ), 'offset' => 0, 'limit' => null, 'sortClauses' => array( @@ -593,7 +599,12 @@ public function testSortFieldNumeric() $result = $handler->findLocations( new LocationQuery( array( - 'filter' => new Criterion\SectionId( array( 1 ) ), + 'filter' => new Criterion\LogicalAnd( + array( + new Criterion\SectionId( array( 1 ) ), + new Criterion\ContentTypeIdentifier( "product" ), + ) + ), 'offset' => 0, 'limit' => null, 'sortClauses' => array( diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerSortTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerSortTest.php index e2f63b17e99..c812d838b1f 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerSortTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerSortTest.php @@ -76,6 +76,7 @@ protected function getContentSearchHandler( array $fullTextSearchConfiguration = new Content\Search\Common\Gateway\CriterionHandler\MatchAll( $db ), new Content\Search\Common\Gateway\CriterionHandler\LogicalAnd( $db ), new Content\Search\Common\Gateway\CriterionHandler\SectionId( $db ), + new Content\Search\Common\Gateway\CriterionHandler\ContentTypeIdentifier( $db ), ) ), new Content\Search\Common\Gateway\SortClauseConverter( @@ -526,7 +527,12 @@ public function testSortFieldText() $result = $locator->findContent( new Query( array( - 'filter' => new Criterion\SectionId( array( 1 ) ), + 'filter' => new Criterion\LogicalAnd( + array( + new Criterion\SectionId( array( 1 ) ), + new Criterion\ContentTypeIdentifier( array( "article" ) ), + ) + ), 'offset' => 0, 'limit' => null, 'sortClauses' => array( @@ -593,7 +599,12 @@ public function testSortFieldNumeric() $result = $locator->findContent( new Query( array( - 'filter' => new Criterion\SectionId( array( 1 ) ), + 'filter' => new Criterion\LogicalAnd( + array( + new Criterion\SectionId( array( 1 ) ), + new Criterion\ContentTypeIdentifier( "product" ), + ) + ), 'offset' => 0, 'limit' => null, 'sortClauses' => array( From 91f38e894c8608a912a6a310ba0450f72fb71cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 26 Nov 2014 13:51:03 +0100 Subject: [PATCH 06/16] EZP-23129: fixed: assert total count, add missing id to last slice --- .../Tests/Content/LocationSearchHandlerSortTest.php | 12 ++++++++++-- .../Legacy/Tests/Content/SearchHandlerSortTest.php | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LocationSearchHandlerSortTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LocationSearchHandlerSortTest.php index 067519a0980..17d2df4341f 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LocationSearchHandlerSortTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LocationSearchHandlerSortTest.php @@ -497,7 +497,7 @@ public function testSortSectionName() "media" => array( 43, 51, 52, 53, 59, 60, 61, 62, 63, 64, 65, 66, 68, 202, 203 ), "protected" => array( 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166 ), "setup" => array( 48, 54 ), - "users" => array( 5, 12, 13, 14, 15, 44, 45 ), + "users" => array( 5, 12, 13, 14, 15, 44, 45, 228 ), ); $locationIds = array_map( function ( $hit ) @@ -506,8 +506,16 @@ function ( $hit ) }, $result->searchHits ); - $index = 0; + $expectedCount = 0; + foreach ( $idMapSet as $set ) + { + $expectedCount += count( $set ); + } + + $this->assertEquals( $expectedCount, $result->totalCount ); + + $index = 0; foreach ( $idMapSet as $idSet ) { $locationIdsSubset = array_slice( $locationIds, $index, $count = count( $idSet ) ); diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerSortTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerSortTest.php index c812d838b1f..3ca1e408b86 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerSortTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerSortTest.php @@ -468,7 +468,7 @@ public function testSortSectionName() "media" => array( 41, 49, 50, 51, 57, 58, 59, 60, 61, 62, 63, 64, 66, 200, 201 ), "protected" => array( 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164 ), "setup" => array( 45, 52 ), - "users" => array( 4, 10, 11, 12, 13, 14, 42 ), + "users" => array( 4, 10, 11, 12, 13, 14, 42, 226 ), ); $contentIds = array_map( function ( $hit ) @@ -477,8 +477,16 @@ function ( $hit ) }, $result->searchHits ); - $index = 0; + $expectedCount = 0; + foreach ( $idMapSet as $set ) + { + $expectedCount += count( $set ); + } + + $this->assertEquals( $expectedCount, $result->totalCount ); + + $index = 0; foreach ( $idMapSet as $idSet ) { $contentIdsSubset = array_slice( $contentIds, $index, $count = count( $idSet ) ); From 6329a79f8c57013817b1b88bcf3e72eba7ef7765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 26 Nov 2014 14:15:43 +0100 Subject: [PATCH 07/16] EZP-23129: simplify join code --- .../Gateway/SortClauseHandler/Field.php | 131 ++++++------------ .../SortClauseHandler/MapLocationDistance.php | 97 +++++-------- 2 files changed, 78 insertions(+), 150 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/Field.php b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/Field.php index 637eae8e9e0..2fd89518e7b 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/Field.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/Field.php @@ -129,101 +129,50 @@ public function applyJoin( SelectQuery $query, SortClause $sortClause, $number, if ( $fieldTarget->languageCode === null ) { - $query - ->leftJoin( - $query->alias( - $this->dbHandler->quoteTable( "ezcontentobject_attribute" ), - $this->dbHandler->quoteIdentifier( $table ) - ), - $query->expr->lAnd( - $query->expr->eq( - $query->bindValue( $fieldDefinitionId, null, PDO::PARAM_INT ), - $this->dbHandler->quoteColumn( "contentclassattribute_id", $table ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "contentobject_id", $table ), - $this->dbHandler->quoteColumn( "id", "ezcontentobject" ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "version", $table ), - $this->dbHandler->quoteColumn( "current_version", "ezcontentobject" ) - ), - $query->expr->gt( - $query->expr->bitAnd( - $query->expr->bitAnd( $this->dbHandler->quoteColumn( "language_id", $table ), ~1 ), - $this->dbHandler->quoteColumn( "initial_language_id", "ezcontentobject" ) - ), - 0 - ) - ) - ); + $languageExpression = $query->expr->gt( + $query->expr->bitAnd( + $query->expr->bitAnd( $this->dbHandler->quoteColumn( "language_id", $table ), ~1 ), + $this->dbHandler->quoteColumn( "initial_language_id", "ezcontentobject" ) + ), + 0 + ); } else { - $linkTable = $table . "_main_language"; - $query - ->leftJoin( - $query->alias( - $this->dbHandler->quoteTable( "ezcontentobject_attribute" ), - $this->dbHandler->quoteIdentifier( $linkTable ) - ), - $query->expr->lAnd( - $query->expr->eq( - $query->bindValue( $fieldDefinitionId, null, PDO::PARAM_INT ), - $this->dbHandler->quoteColumn( "contentclassattribute_id", $linkTable ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "contentobject_id", $linkTable ), - $this->dbHandler->quoteColumn( "id", "ezcontentobject" ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "version", $linkTable ), - $this->dbHandler->quoteColumn( "current_version", "ezcontentobject" ) - ), - $query->expr->gt( - $query->expr->bitAnd( - $query->expr->bitAnd( $this->dbHandler->quoteColumn( "language_id", $linkTable ), ~1 ), - $this->dbHandler->quoteColumn( "initial_language_id", "ezcontentobject" ) - ), - 0 - ) - ) - ) - ->leftJoin( - $query->alias( - $this->dbHandler->quoteTable( "ezcontentobject_attribute" ), - $this->dbHandler->quoteIdentifier( $table ) - ), - $query->expr->lAnd( - $query->expr->eq( - $query->bindValue( $fieldDefinitionId, null, PDO::PARAM_INT ), - $this->dbHandler->quoteColumn( "contentclassattribute_id", $table ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "contentobject_id", $linkTable ), - $this->dbHandler->quoteColumn( "contentobject_id", $table ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "contentclassattribute_id", $linkTable ), - $this->dbHandler->quoteColumn( "contentclassattribute_id", $table ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "version", $linkTable ), - $this->dbHandler->quoteColumn( "version", $table ) - ), - $query->expr->gt( - $query->expr->bitAnd( - $query->expr->bitAnd( $this->dbHandler->quoteColumn( "language_id", $table ), ~1 ), - $query->bindValue( - $this->languageHandler->loadByLanguageCode( $fieldTarget->languageCode )->id, - null, - \PDO::PARAM_INT - ) - ), - 0 - ) + $languageExpression = $query->expr->gt( + $query->expr->bitAnd( + $query->expr->bitAnd( $this->dbHandler->quoteColumn( "language_id", $table ), ~1 ), + $query->bindValue( + $this->languageHandler->loadByLanguageCode( $fieldTarget->languageCode )->id, + null, + \PDO::PARAM_INT ) - ); + ), + 0 + ); } + + $query + ->leftJoin( + $query->alias( + $this->dbHandler->quoteTable( "ezcontentobject_attribute" ), + $this->dbHandler->quoteIdentifier( $table ) + ), + $query->expr->lAnd( + $query->expr->eq( + $query->bindValue( $fieldDefinitionId, null, PDO::PARAM_INT ), + $this->dbHandler->quoteColumn( "contentclassattribute_id", $table ) + ), + $query->expr->eq( + $this->dbHandler->quoteColumn( "contentobject_id", $table ), + $this->dbHandler->quoteColumn( "id", "ezcontentobject" ) + ), + $query->expr->eq( + $this->dbHandler->quoteColumn( "version", $table ), + $this->dbHandler->quoteColumn( "current_version", "ezcontentobject" ) + ), + $languageExpression + ) + ); } } diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/MapLocationDistance.php b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/MapLocationDistance.php index 2390fcc42c3..54108beefd5 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/MapLocationDistance.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseHandler/MapLocationDistance.php @@ -129,72 +129,51 @@ public function applyJoin( SelectQuery $query, SortClause $sortClause, $number, if ( $fieldTarget->languageCode === null ) { - $query - ->leftJoin( - $query->alias( - $this->dbHandler->quoteTable( "ezcontentobject_attribute" ), - $this->dbHandler->quoteIdentifier( $table ) - ), - $query->expr->lAnd( - $query->expr->eq( - $query->bindValue( $fieldDefinitionId, null, PDO::PARAM_INT ), - $this->dbHandler->quoteColumn( "contentclassattribute_id", $table ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "contentobject_id", $table ), - $this->dbHandler->quoteColumn( "id", "ezcontentobject" ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "version", $table ), - $this->dbHandler->quoteColumn( "current_version", "ezcontentobject" ) - ), - $query->expr->gt( - $query->expr->bitAnd( - $query->expr->bitAnd( $this->dbHandler->quoteColumn( "language_id", $table ), ~1 ), - $this->dbHandler->quoteColumn( "initial_language_id", "ezcontentobject" ) - ), - 0 - ) - ) - ); + $languageExpression = $query->expr->gt( + $query->expr->bitAnd( + $query->expr->bitAnd( $this->dbHandler->quoteColumn( "language_id", $table ), ~1 ), + $this->dbHandler->quoteColumn( "initial_language_id", "ezcontentobject" ) + ), + 0 + ); } else { - $query - ->leftJoin( - $query->alias( - $this->dbHandler->quoteTable( "ezcontentobject_attribute" ), - $this->dbHandler->quoteIdentifier( $table ) - ), - $query->expr->lAnd( - $query->expr->eq( - $query->bindValue( $fieldDefinitionId, null, PDO::PARAM_INT ), - $this->dbHandler->quoteColumn( "contentclassattribute_id", $table ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "contentobject_id", $table ), - $this->dbHandler->quoteColumn( "id", "ezcontentobject" ) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn( "version", $table ), - $this->dbHandler->quoteColumn( "current_version", "ezcontentobject" ) - ), - $query->expr->gt( - $query->expr->bitAnd( - $query->expr->bitAnd( $this->dbHandler->quoteColumn( "language_id", $table ), ~1 ), - $query->bindValue( - $this->languageHandler->loadByLanguageCode( $fieldTarget->languageCode )->id, - null, - PDO::PARAM_INT - ) - ), - 0 - ) + $languageExpression = $query->expr->gt( + $query->expr->bitAnd( + $query->expr->bitAnd( $this->dbHandler->quoteColumn( "language_id", $table ), ~1 ), + $query->bindValue( + $this->languageHandler->loadByLanguageCode( $fieldTarget->languageCode )->id, + null, + PDO::PARAM_INT ) - ); + ), + 0 + ); } $query + ->leftJoin( + $query->alias( + $this->dbHandler->quoteTable( "ezcontentobject_attribute" ), + $this->dbHandler->quoteIdentifier( $table ) + ), + $query->expr->lAnd( + $query->expr->eq( + $query->bindValue( $fieldDefinitionId, null, PDO::PARAM_INT ), + $this->dbHandler->quoteColumn( "contentclassattribute_id", $table ) + ), + $query->expr->eq( + $this->dbHandler->quoteColumn( "contentobject_id", $table ), + $this->dbHandler->quoteColumn( "id", "ezcontentobject" ) + ), + $query->expr->eq( + $this->dbHandler->quoteColumn( "version", $table ), + $this->dbHandler->quoteColumn( "current_version", "ezcontentobject" ) + ), + $languageExpression + ) + ) ->leftJoin( $query->alias( $this->dbHandler->quoteTable( "ezgmaplocation" ), From bf8c5753c8f69563faf229485fa80b743c8db07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 26 Nov 2014 14:27:20 +0100 Subject: [PATCH 08/16] EZP-23129: fixed: removed unused dependencies --- .../Search/Gateway/DoctrineDatabase.php | 35 +------------------ .../Tests/Content/SearchHandlerSortTest.php | 6 +--- .../Tests/Content/SearchHandlerTest.php | 6 +--- .../storage_engines/legacy/search.yml | 3 -- 4 files changed, 3 insertions(+), 47 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php index 0a2b5987405..c6ef5b5826c 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php @@ -13,10 +13,7 @@ use eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\SortClauseConverter; use eZ\Publish\Core\Persistence\Legacy\Content\Search\Gateway; use eZ\Publish\Core\Persistence\Database\DatabaseHandler; -use eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder; -use eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator as LanguageMaskGenerator; use eZ\Publish\SPI\Persistence\Content\ContentInfo; -use eZ\Publish\SPI\Persistence\Content\Language\Handler as LanguageHandler; use eZ\Publish\API\Repository\Values\Content\Query\Criterion; use eZ\Publish\API\Repository\Values\Content\VersionInfo; use eZ\Publish\Core\Persistence\Database\SelectQuery; @@ -53,52 +50,22 @@ class DoctrineDatabase extends Gateway */ protected $sortClauseConverter; - /** - * Content load query builder - * - * @var \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder - */ - protected $queryBuilder; - - /** - * Caching language handler - * - * @var \eZ\Publish\Core\Persistence\Legacy\Content\Language\CachingHandler - */ - protected $languageHandler; - - /** - * Language mask generator - * - * @var \eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator - */ - protected $languageMaskGenerator; - /** * Construct from handler handler * * @param \eZ\Publish\Core\Persistence\Database\DatabaseHandler $handler * @param \eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\CriteriaConverter $criteriaConverter * @param \eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\SortClauseConverter $sortClauseConverter - * @param \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder $queryBuilder - * @param \eZ\Publish\SPI\Persistence\Content\Language\Handler $languageHandler - * @param \eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator $languageMaskGenerator */ public function __construct( DatabaseHandler $handler, CriteriaConverter $criteriaConverter, - SortClauseConverter $sortClauseConverter, - QueryBuilder $queryBuilder, - LanguageHandler $languageHandler, - LanguageMaskGenerator $languageMaskGenerator + SortClauseConverter $sortClauseConverter ) { $this->handler = $handler; $this->criteriaConverter = $criteriaConverter; $this->sortClauseConverter = $sortClauseConverter; - $this->queryBuilder = $queryBuilder; - $this->languageHandler = $languageHandler; - $this->languageMaskGenerator = $languageMaskGenerator; } /** diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerSortTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerSortTest.php index 3ca1e408b86..436a54577e8 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerSortTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerSortTest.php @@ -9,7 +9,6 @@ namespace eZ\Publish\Core\Persistence\Legacy\Tests\Content; -use eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder; use eZ\Publish\Core\Persistence\Legacy\Content; use eZ\Publish\SPI\Persistence\Content as ContentObject; use eZ\Publish\API\Repository\Values\Content\Query\Criterion; @@ -91,10 +90,7 @@ protected function getContentSearchHandler( array $fullTextSearchConfiguration = new Content\Search\Common\Gateway\SortClauseHandler\ContentName( $db ), new Content\Search\Common\Gateway\SortClauseHandler\Field( $db, $this->getLanguageHandler() ), ) - ), - new QueryBuilder( $this->getDatabaseHandler() ), - $this->getLanguageHandler(), - $this->getLanguageMaskGenerator() + ) ), $this->getContentMapperMock() ); diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerTest.php index de5d07f223d..42d2151d5ed 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerTest.php @@ -10,7 +10,6 @@ namespace eZ\Publish\Core\Persistence\Legacy\Tests\Content; use eZ\Publish\Core\Persistence; -use eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder; use eZ\Publish\Core\Persistence\Legacy\Content; use eZ\Publish\SPI\Persistence\Content as ContentObject; use eZ\Publish\API\Repository\Values\Content\Query; @@ -230,10 +229,7 @@ protected function getContentSearchHandler( array $fullTextSearchConfiguration = array( new Content\Search\Common\Gateway\SortClauseHandler\ContentId( $this->getDatabaseHandler() ), ) - ), - new QueryBuilder( $this->getDatabaseHandler() ), - $this->getLanguageHandler(), - $this->getLanguageMaskGenerator() + ) ), $this->getContentMapperMock() ); diff --git a/eZ/Publish/Core/settings/storage_engines/legacy/search.yml b/eZ/Publish/Core/settings/storage_engines/legacy/search.yml index 769524bb6f0..c0f308f567c 100644 --- a/eZ/Publish/Core/settings/storage_engines/legacy/search.yml +++ b/eZ/Publish/Core/settings/storage_engines/legacy/search.yml @@ -13,9 +13,6 @@ services: - @ezpublish.api.storage_engine.legacy.dbhandler - @ezpublish.persistence.legacy.search.gateway.criteria_converter.content - @ezpublish.persistence.legacy.search.gateway.sort_clause_converter.content - - @ezpublish.persistence.legacy.content.query_builder - - @ezpublish.spi.persistence.legacy.language.handler - - @ezpublish.persistence.legacy.language.mask_generator ezpublish.persistence.legacy.search.gateway.content.exception_conversion: class: %ezpublish.persistence.legacy.search.gateway.content.exception_conversion.class% From a5c9166715db60f3b1aeeeb7a978ca65f9e23473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 26 Nov 2014 15:02:17 +0100 Subject: [PATCH 09/16] EZP-23129: move field map to the ContentType gateway --- .../Search/Gateway/DoctrineDatabase.php | 66 ++++--------------- .../Location/Gateway/DoctrineDatabase.php | 66 ++++--------------- .../Legacy/Content/Type/Gateway.php | 10 +++ .../Content/Type/Gateway/DoctrineDatabase.php | 51 ++++++++++++++ .../Type/Gateway/ExceptionConversion.php | 24 +++++++ .../Content/LocationSearchHandlerSortTest.php | 5 ++ .../Content/LocationSearchHandlerTest.php | 5 ++ .../Tests/Content/SearchHandlerSortTest.php | 5 ++ .../Tests/Content/SearchHandlerTest.php | 5 ++ .../storage_engines/legacy/search.yml | 2 + 10 files changed, 129 insertions(+), 110 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php index c6ef5b5826c..f18e793a792 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php @@ -9,6 +9,7 @@ namespace eZ\Publish\Core\Persistence\Legacy\Content\Search\Gateway; +use eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway as ContentTypeGateway; use eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\CriteriaConverter; use eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\SortClauseConverter; use eZ\Publish\Core\Persistence\Legacy\Content\Search\Gateway; @@ -50,22 +51,30 @@ class DoctrineDatabase extends Gateway */ protected $sortClauseConverter; + /** + * @var \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway + */ + protected $contentTypeGateway; + /** * Construct from handler handler * * @param \eZ\Publish\Core\Persistence\Database\DatabaseHandler $handler * @param \eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\CriteriaConverter $criteriaConverter * @param \eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\SortClauseConverter $sortClauseConverter + * @param \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway $contentTypeGateway */ public function __construct( DatabaseHandler $handler, CriteriaConverter $criteriaConverter, - SortClauseConverter $sortClauseConverter + SortClauseConverter $sortClauseConverter, + ContentTypeGateway $contentTypeGateway ) { $this->handler = $handler; $this->criteriaConverter = $criteriaConverter; $this->sortClauseConverter = $sortClauseConverter; + $this->contentTypeGateway = $contentTypeGateway; } /** @@ -85,7 +94,7 @@ public function find( Criterion $filter, $offset = 0, $limit = null, array $sort { $limit = $limit !== null ? $limit : self::MAX_LIMIT; - $fieldMap = $this->getFieldMap(); + $fieldMap = $this->contentTypeGateway->getFieldMap(); $count = $this->getResultCount( $filter, $sort, $translations, $fieldMap ); if ( $limit === 0 || $count <= $offset ) { @@ -258,58 +267,5 @@ protected function getContentInfoList( Criterion $filter, $sort, $offset, $limit return $statement->fetchAll( \PDO::FETCH_ASSOC ); } - - /** - * Returns field mapping data - * - * Returns an associative array with ContentType and FieldDefinition identifiers as - * first and second level keys respectively, and FieldDefinition ID as value. - * - * @todo Implement this in ContentType Handler using stash - * - * @return array - */ - protected function getFieldMap() - { - $query = $this->handler->createSelectQuery(); - $query - ->select( - $this->handler->alias( - $this->handler->quoteColumn( "id", "ezcontentclass_attribute" ), - $this->handler->quoteIdentifier( "field_id" ) - ), - $this->handler->alias( - $this->handler->quoteColumn( "identifier", "ezcontentclass_attribute" ), - $this->handler->quoteIdentifier( "field_identifier" ) - ), - $this->handler->alias( - $this->handler->quoteColumn( "identifier", "ezcontentclass" ), - $this->handler->quoteIdentifier( "type_identifier" ) - ) - ) - ->from( - $this->handler->quoteTable( "ezcontentclass_attribute" ) - ) - ->innerJoin( - $this->handler->quoteTable( "ezcontentclass" ), - $query->expr->eq( - $this->handler->quoteColumn( "contentclass_id", "ezcontentclass_attribute" ), - $this->handler->quoteColumn( "id", "ezcontentclass" ) - ) - ); - - $statement = $query->prepare( $query ); - $statement->execute(); - - $map = array(); - $rows= $statement->fetchAll( \PDO::FETCH_ASSOC ); - - foreach ( $rows as $row ) - { - $map[$row["type_identifier"]][$row["field_identifier"]] = $row["field_id"]; - } - - return $map; - } } diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Location/Gateway/DoctrineDatabase.php b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Location/Gateway/DoctrineDatabase.php index b514101e084..20ee671c041 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Location/Gateway/DoctrineDatabase.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Location/Gateway/DoctrineDatabase.php @@ -9,6 +9,7 @@ namespace eZ\Publish\Core\Persistence\Legacy\Content\Search\Location\Gateway; +use eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway as ContentTypeGateway; use eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\CriteriaConverter; use eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\SortClauseConverter; use eZ\Publish\Core\Persistence\Legacy\Content\Search\Location\Gateway; @@ -45,22 +46,30 @@ class DoctrineDatabase extends Gateway */ private $sortClauseConverter; + /** + * @var \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway + */ + protected $contentTypeGateway; + /** * Construct from database handler * * @param \eZ\Publish\Core\Persistence\Database\DatabaseHandler $handler * @param \eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\CriteriaConverter $criteriaConverter * @param \eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\SortClauseConverter $sortClauseConverter + * @param \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway $contentTypeGateway */ public function __construct( DatabaseHandler $handler, CriteriaConverter $criteriaConverter, - SortClauseConverter $sortClauseConverter + SortClauseConverter $sortClauseConverter, + ContentTypeGateway $contentTypeGateway ) { $this->handler = $handler; $this->criteriaConverter = $criteriaConverter; $this->sortClauseConverter = $sortClauseConverter; + $this->contentTypeGateway = $contentTypeGateway; } /** @@ -75,7 +84,7 @@ public function __construct( */ public function find( Criterion $criterion, $offset = 0, $limit = null, array $sortClauses = null ) { - $fieldMap = $this->getFieldMap(); + $fieldMap = $this->contentTypeGateway->getFieldMap(); $count = $this->getTotalCount( $criterion, $sortClauses, $fieldMap ); if ( $limit === 0 ) { @@ -200,57 +209,4 @@ protected function getTotalCount( Criterion $criterion, $sortClauses, array $fie $res = $statement->fetchAll( PDO::FETCH_ASSOC ); return (int)$res[0]['count']; } - - /** - * Returns field mapping data - * - * Returns an associative array with ContentType and FieldDefinition identifiers as - * first and second level keys respectively, and FieldDefinition ID as value. - * - * @todo Implement this in ContentType Handler using stash - * - * @return array - */ - protected function getFieldMap() - { - $query = $this->handler->createSelectQuery(); - $query - ->select( - $this->handler->alias( - $this->handler->quoteColumn( "id", "ezcontentclass_attribute" ), - $this->handler->quoteIdentifier( "field_id" ) - ), - $this->handler->alias( - $this->handler->quoteColumn( "identifier", "ezcontentclass_attribute" ), - $this->handler->quoteIdentifier( "field_identifier" ) - ), - $this->handler->alias( - $this->handler->quoteColumn( "identifier", "ezcontentclass" ), - $this->handler->quoteIdentifier( "type_identifier" ) - ) - ) - ->from( - $this->handler->quoteTable( "ezcontentclass_attribute" ) - ) - ->innerJoin( - $this->handler->quoteTable( "ezcontentclass" ), - $query->expr->eq( - $this->handler->quoteColumn( "contentclass_id", "ezcontentclass_attribute" ), - $this->handler->quoteColumn( "id", "ezcontentclass" ) - ) - ); - - $statement = $query->prepare( $query ); - $statement->execute(); - - $map = array(); - $rows= $statement->fetchAll( \PDO::FETCH_ASSOC ); - - foreach ( $rows as $row ) - { - $map[$row["type_identifier"]][$row["field_identifier"]] = $row["field_id"]; - } - - return $map; - } } diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Type/Gateway.php b/eZ/Publish/Core/Persistence/Legacy/Content/Type/Gateway.php index 844aee7a7e7..31b742642a2 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Type/Gateway.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Type/Gateway.php @@ -290,4 +290,14 @@ abstract public function deleteGroupAssignmentsForType( $typeId, $status ); * @return void */ abstract public function publishTypeAndFields( $typeId, $sourceStatus, $targetStatus ); + + /** + * Returns field mapping data + * + * Returns an associative array with ContentType and FieldDefinition identifiers as + * first and second level keys respectively, and FieldDefinition ID as value. + * + * @return array + */ + abstract public function getFieldMap(); } diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php b/eZ/Publish/Core/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php index 0407d067fca..d0af837bd76 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php @@ -1317,4 +1317,55 @@ protected function selectColumns( SelectQuery $q, $tableName ) ); } } + + /** + * Returns field mapping data + * + * Returns an associative array with ContentType and FieldDefinition identifiers as + * first and second level keys respectively, and FieldDefinition ID as value. + * + * @return array + */ + public function getFieldMap() + { + $query = $this->dbHandler->createSelectQuery(); + $query + ->select( + $this->dbHandler->alias( + $this->dbHandler->quoteColumn( "id", "ezcontentclass_attribute" ), + $this->dbHandler->quoteIdentifier( "field_id" ) + ), + $this->dbHandler->alias( + $this->dbHandler->quoteColumn( "identifier", "ezcontentclass_attribute" ), + $this->dbHandler->quoteIdentifier( "field_identifier" ) + ), + $this->dbHandler->alias( + $this->dbHandler->quoteColumn( "identifier", "ezcontentclass" ), + $this->dbHandler->quoteIdentifier( "type_identifier" ) + ) + ) + ->from( + $this->dbHandler->quoteTable( "ezcontentclass_attribute" ) + ) + ->innerJoin( + $this->dbHandler->quoteTable( "ezcontentclass" ), + $query->expr->eq( + $this->dbHandler->quoteColumn( "contentclass_id", "ezcontentclass_attribute" ), + $this->dbHandler->quoteColumn( "id", "ezcontentclass" ) + ) + ); + + $statement = $query->prepare( $query ); + $statement->execute(); + + $map = array(); + $rows= $statement->fetchAll( \PDO::FETCH_ASSOC ); + + foreach ( $rows as $row ) + { + $map[$row["type_identifier"]][$row["field_identifier"]] = $row["field_id"]; + } + + return $map; + } } diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Type/Gateway/ExceptionConversion.php b/eZ/Publish/Core/Persistence/Legacy/Content/Type/Gateway/ExceptionConversion.php index 4c2cda79aa1..cee4222d902 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Type/Gateway/ExceptionConversion.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Type/Gateway/ExceptionConversion.php @@ -675,4 +675,28 @@ public function publishTypeAndFields( $typeId, $sourceStatus, $targetStatus ) throw new RuntimeException( 'Database error', 0, $e ); } } + + /** + * Returns field mapping data + * + * Returns an associative array with ContentType and FieldDefinition identifiers as + * first and second level keys respectively, and FieldDefinition ID as value. + * + * @return array + */ + public function getFieldMap() + { + try + { + return $this->innerGateway->getFieldMap(); + } + catch ( DBALException $e ) + { + throw new RuntimeException( 'Database error', 0, $e ); + } + catch ( PDOException $e ) + { + throw new RuntimeException( 'Database error', 0, $e ); + } + } } diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LocationSearchHandlerSortTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LocationSearchHandlerSortTest.php index 17d2df4341f..043c270312f 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LocationSearchHandlerSortTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LocationSearchHandlerSortTest.php @@ -21,6 +21,7 @@ use eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\SortClauseConverter; use eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\SortClauseHandler as CommonSortClauseHandler; use eZ\Publish\Core\Persistence\Legacy\Content\Search\Location\Gateway\SortClauseHandler as LocationSortClauseHandler; +use eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway\DoctrineDatabase as ContentTypeGateway; /** * Test case for LocationSearchHandler @@ -112,6 +113,10 @@ protected function getLocationSearchHandler() new CommonSortClauseHandler\SectionName( $this->getDatabaseHandler() ), new CommonSortClauseHandler\Field( $this->getDatabaseHandler(), $this->getLanguageHandler() ), ) + ), + new ContentTypeGateway( + $this->getDatabaseHandler(), + $this->getLanguageMaskGenerator() ) ), $this->getLocationMapperMock() diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LocationSearchHandlerTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LocationSearchHandlerTest.php index a7635697b55..e021e5a315a 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LocationSearchHandlerTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LocationSearchHandlerTest.php @@ -27,6 +27,7 @@ use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\Integer; use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\TextLine; use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\Url; +use eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway\DoctrineDatabase as ContentTypeGateway; /** * Test case for LocationSearchHandler @@ -187,6 +188,10 @@ protected function getLocationSearchHandler( array $fullTextSearchConfiguration new LocationSortClauseHandler\Location\Id( $this->getDatabaseHandler() ), new CommonSortClauseHandler\ContentId( $this->getDatabaseHandler() ), ) + ), + new ContentTypeGateway( + $this->getDatabaseHandler(), + $this->getLanguageMaskGenerator() ) ), $this->getLocationMapperMock() diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerSortTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerSortTest.php index 436a54577e8..caf768c9d82 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerSortTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerSortTest.php @@ -16,6 +16,7 @@ use eZ\Publish\SPI\Persistence\Content\VersionInfo; use eZ\Publish\SPI\Persistence\Content\ContentInfo; use eZ\Publish\API\Repository\Values\Content\Query; +use eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway\DoctrineDatabase as ContentTypeGateway; /** * Test case for ContentSearchHandler @@ -90,6 +91,10 @@ protected function getContentSearchHandler( array $fullTextSearchConfiguration = new Content\Search\Common\Gateway\SortClauseHandler\ContentName( $db ), new Content\Search\Common\Gateway\SortClauseHandler\Field( $db, $this->getLanguageHandler() ), ) + ), + new ContentTypeGateway( + $this->getDatabaseHandler(), + $this->getLanguageMaskGenerator() ) ), $this->getContentMapperMock() diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerTest.php index 42d2151d5ed..a64324766bd 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/SearchHandlerTest.php @@ -22,6 +22,7 @@ use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\Integer; use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\TextLine; use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\Url; +use eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway\DoctrineDatabase as ContentTypeGateway; /** * Test case for ContentSearchHandler @@ -229,6 +230,10 @@ protected function getContentSearchHandler( array $fullTextSearchConfiguration = array( new Content\Search\Common\Gateway\SortClauseHandler\ContentId( $this->getDatabaseHandler() ), ) + ), + new ContentTypeGateway( + $this->getDatabaseHandler(), + $this->getLanguageMaskGenerator() ) ), $this->getContentMapperMock() diff --git a/eZ/Publish/Core/settings/storage_engines/legacy/search.yml b/eZ/Publish/Core/settings/storage_engines/legacy/search.yml index c0f308f567c..553ab672bf1 100644 --- a/eZ/Publish/Core/settings/storage_engines/legacy/search.yml +++ b/eZ/Publish/Core/settings/storage_engines/legacy/search.yml @@ -13,6 +13,7 @@ services: - @ezpublish.api.storage_engine.legacy.dbhandler - @ezpublish.persistence.legacy.search.gateway.criteria_converter.content - @ezpublish.persistence.legacy.search.gateway.sort_clause_converter.content + - @ezpublish.persistence.legacy.content_type.gateway ezpublish.persistence.legacy.search.gateway.content.exception_conversion: class: %ezpublish.persistence.legacy.search.gateway.content.exception_conversion.class% @@ -29,6 +30,7 @@ services: - @ezpublish.api.storage_engine.legacy.dbhandler - @ezpublish.persistence.legacy.search.gateway.criteria_converter.location - @ezpublish.persistence.legacy.search.gateway.sort_clause_converter.location + - @ezpublish.persistence.legacy.content_type.gateway ezpublish.persistence.legacy.search.gateway.location.exception_conversion: class: %ezpublish.persistence.legacy.search.gateway.location.exception_conversion.class% From 2c2fb84b08289122f609ac68e1bfe8897be32eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 26 Nov 2014 16:18:55 +0100 Subject: [PATCH 10/16] EZP-23129: fixed: use selectDistinct(), remove duplicate column --- .../Legacy/Content/Search/Gateway/DoctrineDatabase.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php index f18e793a792..65ba52e751d 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php @@ -212,8 +212,7 @@ protected function getResultCount( Criterion $filter, $sort, $translations, arra protected function getContentInfoList( Criterion $filter, $sort, $offset, $limit, $translations, array $fieldMap ) { $query = $this->handler->createSelectQuery(); - $query->select( - 'DISTINCT ezcontentobject.id', + $query->selectDistinct( 'ezcontentobject.*', $this->handler->aliasedColumn( $query, 'main_node_id', 'main_tree' ) ); From 03d55660eb2124c7bb9741365412c49cad015453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 26 Nov 2014 16:20:55 +0100 Subject: [PATCH 11/16] EZP-23129: changed: always sort null last --- .../Legacy/SortFieldMultipleTypes.php | 48 +++++++++---------- .../Legacy/SortFieldMultipleTypesSlice.php | 20 ++++---- .../Common/Gateway/SortClauseConverter.php | 12 ++++- 3 files changed, 45 insertions(+), 35 deletions(-) diff --git a/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypes.php b/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypes.php index f445a4f766b..174c784cdfd 100644 --- a/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypes.php +++ b/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypes.php @@ -10,8 +10,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 4, - 'title' => 'Users', + 'id' => 56, + 'title' => 'Design', ), 'score' => NULL, 'index' => NULL, @@ -21,8 +21,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 11, - 'title' => 'Members', + 'id' => 50, + 'title' => 'Files', ), 'score' => NULL, 'index' => NULL, @@ -32,8 +32,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 12, - 'title' => 'Administrator users', + 'id' => 49, + 'title' => 'Images', ), 'score' => NULL, 'index' => NULL, @@ -43,8 +43,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 13, - 'title' => 'Editors', + 'id' => 41, + 'title' => 'Media', ), 'score' => NULL, 'index' => NULL, @@ -54,8 +54,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 42, - 'title' => 'Anonymous Users', + 'id' => 51, + 'title' => 'Multimedia', ), 'score' => NULL, 'index' => NULL, @@ -65,8 +65,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 59, - 'title' => 'Partners', + 'id' => 45, + 'title' => 'Setup', ), 'score' => NULL, 'index' => NULL, @@ -76,8 +76,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 56, - 'title' => 'Design', + 'id' => 4, + 'title' => 'Users', ), 'score' => NULL, 'index' => NULL, @@ -87,8 +87,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 50, - 'title' => 'Files', + 'id' => 11, + 'title' => 'Members', ), 'score' => NULL, 'index' => NULL, @@ -98,8 +98,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 49, - 'title' => 'Images', + 'id' => 12, + 'title' => 'Administrator users', ), 'score' => NULL, 'index' => NULL, @@ -109,8 +109,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 41, - 'title' => 'Media', + 'id' => 13, + 'title' => 'Editors', ), 'score' => NULL, 'index' => NULL, @@ -120,8 +120,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 51, - 'title' => 'Multimedia', + 'id' => 42, + 'title' => 'Anonymous Users', ), 'score' => NULL, 'index' => NULL, @@ -131,8 +131,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 45, - 'title' => 'Setup', + 'id' => 59, + 'title' => 'Partners', ), 'score' => NULL, 'index' => NULL, diff --git a/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypesSlice.php b/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypesSlice.php index 414c52165a6..8fc8268e07c 100644 --- a/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypesSlice.php +++ b/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypesSlice.php @@ -10,8 +10,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 13, - 'title' => 'Editors', + 'id' => 41, + 'title' => 'Media', ), 'score' => NULL, 'index' => NULL, @@ -21,8 +21,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 42, - 'title' => 'Anonymous Users', + 'id' => 51, + 'title' => 'Multimedia', ), 'score' => NULL, 'index' => NULL, @@ -32,8 +32,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 59, - 'title' => 'Partners', + 'id' => 45, + 'title' => 'Setup', ), 'score' => NULL, 'index' => NULL, @@ -43,8 +43,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 56, - 'title' => 'Design', + 'id' => 4, + 'title' => 'Users', ), 'score' => NULL, 'index' => NULL, @@ -54,8 +54,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 50, - 'title' => 'Files', + 'id' => 11, + 'title' => 'Members', ), 'score' => NULL, 'index' => NULL, diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseConverter.php b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseConverter.php index deb0ca06922..f0386a41291 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseConverter.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Common/Gateway/SortClauseConverter.php @@ -71,7 +71,17 @@ public function applySelect( SelectQuery $query, array $sortClauses ) { foreach ( (array)$handler->applySelect( $query, $sortClause, $nr ) as $column ) { - $this->sortColumns[$column] = $sortClause->direction; + if ( strrpos( $column, "_null", -6 ) === false ) + { + $direction = $sortClause->direction; + } + else + { + // Always sort null last + $direction = SelectQuery::ASC; + } + + $this->sortColumns[$column] = $direction; } continue 2; } From d1999242dbc2bbaf771808771b56af987bced551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 26 Nov 2014 16:21:17 +0100 Subject: [PATCH 12/16] EZP-23129: fixed: use sortable field --- eZ/Publish/API/Repository/Tests/SearchServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eZ/Publish/API/Repository/Tests/SearchServiceTest.php b/eZ/Publish/API/Repository/Tests/SearchServiceTest.php index ec951819eed..de1636ac9e9 100644 --- a/eZ/Publish/API/Repository/Tests/SearchServiceTest.php +++ b/eZ/Publish/API/Repository/Tests/SearchServiceTest.php @@ -1152,7 +1152,7 @@ function ( $a, $b ) 'limit' => 5, 'sortClauses' => array( new SortClause\Field( "folder", "name", Query::SORT_ASC, "eng-US" ), - new SortClause\Field( "template_look", "title", Query::SORT_ASC ), + new SortClause\Field( "user", "first_name", Query::SORT_ASC, "eng-US" ), new SortClause\ContentId(), ) ), From 2394f21e7b223c13c980cb7d822aa70eb6e87e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 26 Nov 2014 16:22:08 +0100 Subject: [PATCH 13/16] EZP-23129: add reverse sort tests --- .../Repository/Tests/SearchServiceTest.php | 25 +++ .../Legacy/SortFieldMultipleTypesReverse.php | 148 ++++++++++++++++++ .../SortFieldMultipleTypesSliceReverse.php | 71 +++++++++ 3 files changed, 244 insertions(+) create mode 100644 eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypesReverse.php create mode 100644 eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypesSliceReverse.php diff --git a/eZ/Publish/API/Repository/Tests/SearchServiceTest.php b/eZ/Publish/API/Repository/Tests/SearchServiceTest.php index de1636ac9e9..b3c190cec7c 100644 --- a/eZ/Publish/API/Repository/Tests/SearchServiceTest.php +++ b/eZ/Publish/API/Repository/Tests/SearchServiceTest.php @@ -1145,6 +1145,18 @@ function ( $a, $b ) ), $fixtureDir . 'SortFieldMultipleTypes.php', ), + array( + array( + 'filter' => new Criterion\ContentTypeId( array( 1, 3 ) ), + 'offset' => 0, + 'limit' => null, + 'sortClauses' => array( + new SortClause\Field( "folder", "name", Query::SORT_DESC, "eng-US" ), + new SortClause\ContentId(), + ) + ), + $fixtureDir . 'SortFieldMultipleTypesReverse.php', + ), array( array( 'filter' => new Criterion\ContentTypeId( array( 1, 3 ) ), @@ -1158,6 +1170,19 @@ function ( $a, $b ) ), $fixtureDir . 'SortFieldMultipleTypesSlice.php', ), + array( + array( + 'filter' => new Criterion\ContentTypeId( array( 1, 3 ) ), + 'offset' => 3, + 'limit' => 5, + 'sortClauses' => array( + new SortClause\Field( "folder", "name", Query::SORT_DESC, "eng-US" ), + new SortClause\Field( "user", "first_name", Query::SORT_ASC, "eng-US" ), + new SortClause\ContentId(), + ) + ), + $fixtureDir . 'SortFieldMultipleTypesSliceReverse.php', + ), ); } diff --git a/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypesReverse.php b/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypesReverse.php new file mode 100644 index 00000000000..9a75f28b6f4 --- /dev/null +++ b/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypesReverse.php @@ -0,0 +1,148 @@ + + array ( + ), + 'searchHits' => + array ( + 0 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 45, + 'title' => 'Setup', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 1 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 51, + 'title' => 'Multimedia', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 2 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 41, + 'title' => 'Media', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 3 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 49, + 'title' => 'Images', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 4 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 50, + 'title' => 'Files', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 5 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 56, + 'title' => 'Design', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 6 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 4, + 'title' => 'Users', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 7 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 11, + 'title' => 'Members', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 8 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 12, + 'title' => 'Administrator users', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 9 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 13, + 'title' => 'Editors', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 10 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 42, + 'title' => 'Anonymous Users', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 11 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 59, + 'title' => 'Partners', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + + ), + 'spellSuggestion' => NULL, + 'time' => 1, + 'timedOut' => NULL, + 'maxScore' => NULL, + 'totalCount' => 12, +)); diff --git a/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypesSliceReverse.php b/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypesSliceReverse.php new file mode 100644 index 00000000000..84b07738776 --- /dev/null +++ b/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortFieldMultipleTypesSliceReverse.php @@ -0,0 +1,71 @@ + + array ( + ), + 'searchHits' => + array ( + 0 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 49, + 'title' => 'Images', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 1 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 50, + 'title' => 'Files', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 2 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 56, + 'title' => 'Design', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 3 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 4, + 'title' => 'Users', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + 4 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 11, + 'title' => 'Members', + ), + 'score' => NULL, + 'index' => NULL, + 'highlight' => NULL, + )), + + ), + 'spellSuggestion' => NULL, + 'time' => 1, + 'timedOut' => NULL, + 'maxScore' => NULL, + 'totalCount' => 12, +)); From 9bba35a8197aa1a4668f45eabe2113c23dd894ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 26 Nov 2014 16:22:34 +0100 Subject: [PATCH 14/16] EZP-23129: add missing Elasticsearch fixtures --- .../Elasticsearch/SortFieldMultipleTypes.php | 148 ++++++++++++++++++ .../SortFieldMultipleTypesReverse.php | 148 ++++++++++++++++++ .../SortFieldMultipleTypesSlice.php | 70 +++++++++ .../SortFieldMultipleTypesSliceReverse.php | 71 +++++++++ 4 files changed, 437 insertions(+) create mode 100644 eZ/Publish/API/Repository/Tests/_fixtures/Elasticsearch/SortFieldMultipleTypes.php create mode 100644 eZ/Publish/API/Repository/Tests/_fixtures/Elasticsearch/SortFieldMultipleTypesReverse.php create mode 100644 eZ/Publish/API/Repository/Tests/_fixtures/Elasticsearch/SortFieldMultipleTypesSlice.php create mode 100644 eZ/Publish/API/Repository/Tests/_fixtures/Elasticsearch/SortFieldMultipleTypesSliceReverse.php diff --git a/eZ/Publish/API/Repository/Tests/_fixtures/Elasticsearch/SortFieldMultipleTypes.php b/eZ/Publish/API/Repository/Tests/_fixtures/Elasticsearch/SortFieldMultipleTypes.php new file mode 100644 index 00000000000..e7b1b6e22d7 --- /dev/null +++ b/eZ/Publish/API/Repository/Tests/_fixtures/Elasticsearch/SortFieldMultipleTypes.php @@ -0,0 +1,148 @@ + + array ( + ), + 'searchHits' => + array ( + 0 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 56, + 'title' => 'Design', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 1 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 50, + 'title' => 'Files', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 2 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 49, + 'title' => 'Images', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 3 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 41, + 'title' => 'Media', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 4 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 51, + 'title' => 'Multimedia', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 5 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 45, + 'title' => 'Setup', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 6 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 4, + 'title' => 'Users', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 7 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 11, + 'title' => 'Members', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 8 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 12, + 'title' => 'Administrator users', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 9 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 13, + 'title' => 'Editors', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 10 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 42, + 'title' => 'Anonymous Users', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 11 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 59, + 'title' => 'Partners', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + + ), + 'spellSuggestion' => NULL, + 'time' => 1, + 'timedOut' => NULL, + 'maxScore' => 1.0, + 'totalCount' => 12, +)); diff --git a/eZ/Publish/API/Repository/Tests/_fixtures/Elasticsearch/SortFieldMultipleTypesReverse.php b/eZ/Publish/API/Repository/Tests/_fixtures/Elasticsearch/SortFieldMultipleTypesReverse.php new file mode 100644 index 00000000000..fd27bdc3ffe --- /dev/null +++ b/eZ/Publish/API/Repository/Tests/_fixtures/Elasticsearch/SortFieldMultipleTypesReverse.php @@ -0,0 +1,148 @@ + + array ( + ), + 'searchHits' => + array ( + 0 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 45, + 'title' => 'Setup', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 1 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 51, + 'title' => 'Multimedia', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 2 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 41, + 'title' => 'Media', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 3 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 49, + 'title' => 'Images', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 4 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 50, + 'title' => 'Files', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 5 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 56, + 'title' => 'Design', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 6 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 4, + 'title' => 'Users', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 7 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 11, + 'title' => 'Members', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 8 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 12, + 'title' => 'Administrator users', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 9 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 13, + 'title' => 'Editors', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 10 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 42, + 'title' => 'Anonymous Users', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 11 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 59, + 'title' => 'Partners', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + + ), + 'spellSuggestion' => NULL, + 'time' => 1, + 'timedOut' => NULL, + 'maxScore' => 1.0, + 'totalCount' => 12, +)); diff --git a/eZ/Publish/API/Repository/Tests/_fixtures/Elasticsearch/SortFieldMultipleTypesSlice.php b/eZ/Publish/API/Repository/Tests/_fixtures/Elasticsearch/SortFieldMultipleTypesSlice.php new file mode 100644 index 00000000000..6cb340e8cac --- /dev/null +++ b/eZ/Publish/API/Repository/Tests/_fixtures/Elasticsearch/SortFieldMultipleTypesSlice.php @@ -0,0 +1,70 @@ + + array ( + ), + 'searchHits' => + array ( + 0 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 41, + 'title' => 'Media', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 1 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 51, + 'title' => 'Multimedia', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 2 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 45, + 'title' => 'Setup', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 3 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 4, + 'title' => 'Users', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 4 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 11, + 'title' => 'Members', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + ), + 'spellSuggestion' => NULL, + 'time' => 1, + 'timedOut' => NULL, + 'maxScore' => 1.0, + 'totalCount' => 12, +)); diff --git a/eZ/Publish/API/Repository/Tests/_fixtures/Elasticsearch/SortFieldMultipleTypesSliceReverse.php b/eZ/Publish/API/Repository/Tests/_fixtures/Elasticsearch/SortFieldMultipleTypesSliceReverse.php new file mode 100644 index 00000000000..17b1b4505a2 --- /dev/null +++ b/eZ/Publish/API/Repository/Tests/_fixtures/Elasticsearch/SortFieldMultipleTypesSliceReverse.php @@ -0,0 +1,71 @@ + + array ( + ), + 'searchHits' => + array ( + 0 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 49, + 'title' => 'Images', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 1 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 50, + 'title' => 'Files', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 2 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 56, + 'title' => 'Design', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 3 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 4, + 'title' => 'Users', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + 4 => + eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( + 'valueObject' => + array ( + 'id' => 11, + 'title' => 'Members', + ), + 'score' => 1.0, + 'index' => NULL, + 'highlight' => NULL, + )), + + ), + 'spellSuggestion' => NULL, + 'time' => 1, + 'timedOut' => NULL, + 'maxScore' => 1.0, + 'totalCount' => 12, +)); From 5616e22c0d2751b315cfc7f2101576bbac83fb8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 26 Nov 2014 16:45:10 +0100 Subject: [PATCH 15/16] EZP-23129: updated fixtures: null always sorted last --- .../Tests/_fixtures/Legacy/SortTemplateTitle.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortTemplateTitle.php b/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortTemplateTitle.php index e0965f12341..da1e6a9d91a 100644 --- a/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortTemplateTitle.php +++ b/eZ/Publish/API/Repository/Tests/_fixtures/Legacy/SortTemplateTitle.php @@ -10,8 +10,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 56, - 'title' => 'Design', + 'id' => 54, + 'title' => 'eZ Publish Demo Design (without demo content)', ), 'score' => NULL, 'index' => NULL, @@ -21,8 +21,8 @@ eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array( 'valueObject' => array ( - 'id' => 54, - 'title' => 'eZ Publish Demo Design (without demo content)', + 'id' => 56, + 'title' => 'Design', ), 'score' => NULL, 'index' => NULL, From fd4ca2dff0bfe9166701581d1fd4e99464d3c11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Thu, 27 Nov 2014 14:22:33 +0100 Subject: [PATCH 16/16] EZP-23129: optimize: load field map only if needed --- .../Search/Gateway/DoctrineDatabase.php | 26 ++++++++++++++++++- .../Location/Gateway/DoctrineDatabase.php | 26 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php index 65ba52e751d..536808e0b74 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Gateway/DoctrineDatabase.php @@ -16,6 +16,8 @@ use eZ\Publish\Core\Persistence\Database\DatabaseHandler; use eZ\Publish\SPI\Persistence\Content\ContentInfo; use eZ\Publish\API\Repository\Values\Content\Query\Criterion; +use eZ\Publish\API\Repository\Values\Content\Query\SortClause\Field; +use eZ\Publish\API\Repository\Values\Content\Query\SortClause\MapLocationDistance; use eZ\Publish\API\Repository\Values\Content\VersionInfo; use eZ\Publish\Core\Persistence\Database\SelectQuery; @@ -94,7 +96,7 @@ public function find( Criterion $filter, $offset = 0, $limit = null, array $sort { $limit = $limit !== null ? $limit : self::MAX_LIMIT; - $fieldMap = $this->contentTypeGateway->getFieldMap(); + $fieldMap = $this->getFieldMap( $sort ); $count = $this->getResultCount( $filter, $sort, $translations, $fieldMap ); if ( $limit === 0 || $count <= $offset ) { @@ -266,5 +268,27 @@ protected function getContentInfoList( Criterion $filter, $sort, $offset, $limit return $statement->fetchAll( \PDO::FETCH_ASSOC ); } + + /** + * Returns the field map if given $sortClauses contain a Field sort clause. + * + * Otherwise an empty array is returned. + * + * @param null|\eZ\Publish\API\Repository\Values\Content\Query\SortClause[] $sortClauses + * + * @return array + */ + protected function getFieldMap( $sortClauses ) + { + foreach ( (array)$sortClauses as $sortClause ) + { + if ( $sortClause instanceof Field || $sortClause instanceof MapLocationDistance ) + { + return $this->contentTypeGateway->getFieldMap(); + } + } + + return array(); + } } diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Location/Gateway/DoctrineDatabase.php b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Location/Gateway/DoctrineDatabase.php index 20ee671c041..1f6eae6ce1d 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Search/Location/Gateway/DoctrineDatabase.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Search/Location/Gateway/DoctrineDatabase.php @@ -16,6 +16,8 @@ use eZ\Publish\Core\Persistence\Database\DatabaseHandler; use eZ\Publish\API\Repository\Values\Content\Query; use eZ\Publish\API\Repository\Values\Content\Query\Criterion; +use eZ\Publish\API\Repository\Values\Content\Query\SortClause\Field; +use eZ\Publish\API\Repository\Values\Content\Query\SortClause\MapLocationDistance; use PDO; /** @@ -84,7 +86,7 @@ public function __construct( */ public function find( Criterion $criterion, $offset = 0, $limit = null, array $sortClauses = null ) { - $fieldMap = $this->contentTypeGateway->getFieldMap(); + $fieldMap = $this->getFieldMap( $sortClauses ); $count = $this->getTotalCount( $criterion, $sortClauses, $fieldMap ); if ( $limit === 0 ) { @@ -209,4 +211,26 @@ protected function getTotalCount( Criterion $criterion, $sortClauses, array $fie $res = $statement->fetchAll( PDO::FETCH_ASSOC ); return (int)$res[0]['count']; } + + /** + * Returns the field map if given $sortClauses contain a Field sort clause. + * + * Otherwise an empty array is returned. + * + * @param null|\eZ\Publish\API\Repository\Values\Content\Query\SortClause[] $sortClauses + * + * @return array + */ + protected function getFieldMap( $sortClauses ) + { + foreach ( (array)$sortClauses as $sortClause ) + { + if ( $sortClause instanceof Field || $sortClause instanceof MapLocationDistance ) + { + return $this->contentTypeGateway->getFieldMap(); + } + } + + return array(); + } }