/** * Generate query expression for a Criterion this handler accepts. * * accept() must be called before calling this method. * * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * @param array $fieldFilters * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion, array $fieldFilters = null) { /** @var \Netgen\TagsBundle\API\Repository\Values\Content\Query\Criterion\Value\TagKeywordValue $valueData */ $valueData = $criterion->valueData; $subSelect = $query->subSelect(); $subSelect->select($this->dbHandler->quoteColumn('id', 'ezcontentobject'))->from($this->dbHandler->quoteTable('ezcontentobject'))->innerJoin($this->dbHandler->quoteTable('eztags_attribute_link'), $subSelect->expr->lAnd(array($subSelect->expr->eq($this->dbHandler->quoteColumn('objectattribute_version', 'eztags_attribute_link'), $this->dbHandler->quoteColumn('current_version', 'ezcontentobject')), $subSelect->expr->eq($this->dbHandler->quoteColumn('object_id', 'eztags_attribute_link'), $this->dbHandler->quoteColumn('id', 'ezcontentobject')))))->innerJoin($this->dbHandler->quoteTable('eztags'), $subSelect->expr->eq($this->dbHandler->quoteColumn('keyword_id', 'eztags_attribute_link'), $this->dbHandler->quoteColumn('id', 'eztags')))->leftJoin($this->dbHandler->quoteTable('eztags_keyword'), $subSelect->expr->lAnd($subSelect->expr->eq($this->dbHandler->quoteColumn('id', 'eztags'), $this->dbHandler->quoteColumn('keyword_id', 'eztags_keyword')), $subSelect->expr->eq($this->dbHandler->quoteColumn('status', 'eztags_keyword'), $subSelect->bindValue(1, null, \PDO::PARAM_INT)))); if ($valueData !== null && !empty($valueData->languages)) { if ($valueData->useAlwaysAvailable) { $subSelect->where($subSelect->expr->lOr($subSelect->expr->in($this->dbHandler->quoteColumn('locale', 'eztags_keyword'), $valueData->languages), $subSelect->expr->eq($this->dbHandler->quoteColumn('main_language_id', 'eztags'), $subSelect->expr->bitAnd($this->dbHandler->quoteColumn('language_id', 'eztags_keyword'), -2)))); } else { $subSelect->where($subSelect->expr->in($this->dbHandler->quoteColumn('locale', 'eztags_keyword'), $valueData->languages)); } } if ($criterion->operator == Criterion\Operator::LIKE) { $subSelect->where($subSelect->expr->like($this->dbHandler->quoteColumn('keyword', 'eztags_keyword'), $subSelect->bindValue($criterion->value[0]))); } else { $subSelect->where($subSelect->expr->in($this->dbHandler->quoteColumn('keyword', 'eztags_keyword'), $criterion->value)); } $fieldDefinitionIds = $this->getSearchableFields($criterion->target); if ($fieldDefinitionIds !== null) { $subSelect->innerJoin($this->dbHandler->quoteTable('ezcontentobject_attribute'), $subSelect->expr->lAnd(array($subSelect->expr->eq($this->dbHandler->quoteColumn('id', 'ezcontentobject_attribute'), $this->dbHandler->quoteColumn('objectattribute_id', 'eztags_attribute_link')), $subSelect->expr->eq($this->dbHandler->quoteColumn('version', 'ezcontentobject_attribute'), $this->dbHandler->quoteColumn('objectattribute_version', 'eztags_attribute_link'))))); $subSelect->where($query->expr->in($this->dbHandler->quoteColumn('contentclassattribute_id', 'ezcontentobject_attribute'), $fieldDefinitionIds)); } return $query->expr->in($this->dbHandler->quoteColumn('id', 'ezcontentobject'), $subSelect); }
/** * Generate query expression for a Criterion this handler accepts * * accept() must be called before calling this method. * * @param \eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * * @return \eZ\Publish\Core\Persistence\Database\Expression * @throws RuntimeException */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion) { $column = $this->dbHandler->quoteColumn('to_contentobject_id', 'ezcontentobject_link'); switch ($criterion->operator) { case Criterion\Operator::CONTAINS: if (count($criterion->value) > 1) { $subRequest = array(); foreach ($criterion->value as $value) { $subSelect = $query->subSelect(); $subSelect->select($this->dbHandler->quoteColumn('from_contentobject_id'))->from($this->dbHandler->quoteTable('ezcontentobject_link')); $subSelect->innerJoin('ezcontentclass_attribute', $subSelect->expr->eq('ezcontentclass_attribute.id', 'ezcontentobject_link.contentclassattribute_id')); $subSelect->where($subSelect->expr->lAnd($subSelect->expr->eq($this->dbHandler->quoteColumn('from_contentobject_version', 'ezcontentobject_link'), $this->dbHandler->quoteColumn('current_version', 'ezcontentobject')), $subSelect->expr->eq($this->dbHandler->quoteColumn('contentclass_id', 'ezcontentclass_attribute'), $this->dbHandler->quoteColumn('contentclass_id', 'ezcontentobject')), $subSelect->expr->eq($this->dbHandler->quoteColumn('identifier', 'ezcontentclass_attribute'), $subSelect->bindValue($criterion->target)), $subSelect->expr->eq($column, $value))); $subRequest[] = $subSelect->expr->in($this->dbHandler->quoteColumn('id', 'ezcontentobject'), $subSelect); } return $query->expr->lAnd($subRequest); } case Criterion\Operator::IN: $subSelect = $query->subSelect(); $subSelect->select($this->dbHandler->quoteColumn('from_contentobject_id'))->from($this->dbHandler->quoteTable('ezcontentobject_link')); $subSelect->innerJoin('ezcontentclass_attribute', $subSelect->expr->eq('ezcontentclass_attribute.id', 'ezcontentobject_link.contentclassattribute_id')); return $query->expr->in($this->dbHandler->quoteColumn('id', 'ezcontentobject'), $subSelect->where($subSelect->expr->lAnd($subSelect->expr->eq($this->dbHandler->quoteColumn('from_contentobject_version', 'ezcontentobject_link'), $this->dbHandler->quoteColumn('current_version', 'ezcontentobject')), $subSelect->expr->eq($this->dbHandler->quoteColumn('contentclass_id', 'ezcontentclass_attribute'), $this->dbHandler->quoteColumn('contentclass_id', 'ezcontentobject')), $subSelect->expr->eq($this->dbHandler->quoteColumn('identifier', 'ezcontentclass_attribute'), $subSelect->bindValue($criterion->target)), $subSelect->expr->in($column, $criterion->value)))); default: throw new RuntimeException("Unknown operator '{$criterion->operator}' for RelationList criterion handler."); } }
/** * Generate query expression for a Criterion this handler accepts. * * accept() must be called before calling this method. * * @throws \RuntimeException * * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * @param array $languageSettings * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion, array $languageSettings) { $column = $this->dbHandler->quoteColumn('to_contentobject_id', 'ezcontentobject_link'); $fieldDefinitionIds = $this->getFieldDefinitionsIds($criterion->target); switch ($criterion->operator) { case Criterion\Operator::CONTAINS: if (count($criterion->value) > 1) { $subRequest = array(); foreach ($criterion->value as $value) { $subSelect = $query->subSelect(); $subSelect->select($this->dbHandler->quoteColumn('from_contentobject_id'))->from($this->dbHandler->quoteTable('ezcontentobject_link')); $subSelect->where($subSelect->expr->lAnd($subSelect->expr->eq($this->dbHandler->quoteColumn('from_contentobject_version', 'ezcontentobject_link'), $this->dbHandler->quoteColumn('current_version', 'ezcontentobject')), $subSelect->expr->in($this->dbHandler->quoteColumn('contentclassattribute_id', 'ezcontentobject_link'), $fieldDefinitionIds), $subSelect->expr->eq($column, $value))); $subRequest[] = $subSelect->expr->in($this->dbHandler->quoteColumn('id', 'ezcontentobject'), $subSelect); } return $query->expr->lAnd($subRequest); } // Intentionally omitting break // Intentionally omitting break case Criterion\Operator::IN: $subSelect = $query->subSelect(); $subSelect->select($this->dbHandler->quoteColumn('from_contentobject_id'))->from($this->dbHandler->quoteTable('ezcontentobject_link')); return $query->expr->in($this->dbHandler->quoteColumn('id', 'ezcontentobject'), $subSelect->where($subSelect->expr->lAnd($subSelect->expr->eq($this->dbHandler->quoteColumn('from_contentobject_version', 'ezcontentobject_link'), $this->dbHandler->quoteColumn('current_version', 'ezcontentobject')), $subSelect->expr->in($this->dbHandler->quoteColumn('contentclassattribute_id', 'ezcontentobject_link'), $fieldDefinitionIds), $subSelect->expr->in($column, $criterion->value)))); default: throw new RuntimeException("Unknown operator '{$criterion->operator}' for RelationList criterion handler."); } }
/** * Returns a field language join condition for the given $languageSettings. * * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param array $languageSettings * * @return string */ protected function getFieldCondition(SelectQuery $query, array $languageSettings) { // 1. Use main language(s) by default if (empty($languageSettings['languages'])) { return $query->expr->gt($query->expr->bitAnd($this->dbHandler->quoteColumn('initial_language_id', 'ezcontentobject'), $this->dbHandler->quoteColumn('language_id', 'ezcontentobject_attribute')), $query->bindValue(0, null, PDO::PARAM_INT)); } // 2. Otherwise use prioritized languages $leftSide = $query->expr->bitAnd($query->expr->sub($this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'), $query->expr->bitAnd($this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'), $this->dbHandler->quoteColumn('language_id', 'ezcontentobject_attribute'))), $query->bindValue(1, null, PDO::PARAM_INT)); $rightSide = $query->expr->bitAnd($this->dbHandler->quoteColumn('language_id', 'ezcontentobject_attribute'), $query->bindValue(1, null, PDO::PARAM_INT)); for ($index = count($languageSettings['languages']) - 1, $multiplier = 2; $index >= 0; $index--, $multiplier *= 2) { $languageId = $this->languageHandler->loadByLanguageCode($languageSettings['languages'][$index])->id; $addToLeftSide = $query->expr->bitAnd($query->expr->sub($this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'), $query->expr->bitAnd($this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'), $this->dbHandler->quoteColumn('language_id', 'ezcontentobject_attribute'))), $languageId); $addToRightSide = $query->expr->bitAnd($this->dbHandler->quoteColumn('language_id', 'ezcontentobject_attribute'), $languageId); if ($multiplier > $languageId) { $factor = $multiplier / $languageId; for ($shift = 0; $factor > 1; $factor = $factor / 2, $shift++) { } $factorTerm = ' << ' . $shift; $addToLeftSide .= $factorTerm; $addToRightSide .= $factorTerm; } elseif ($multiplier < $languageId) { $factor = $languageId / $multiplier; for ($shift = 0; $factor > 1; $factor = $factor / 2, $shift++) { } $factorTerm = ' >> ' . $shift; $addToLeftSide .= $factorTerm; $addToRightSide .= $factorTerm; } $leftSide = $query->expr->add($leftSide, "({$addToLeftSide})"); $rightSide = $query->expr->add($rightSide, "({$addToRightSide})"); } return $query->expr->lAnd($query->expr->gt($query->expr->bitAnd($this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'), $this->dbHandler->quoteColumn('language_id', 'ezcontentobject_attribute')), $query->bindValue(0, null, PDO::PARAM_INT)), $query->expr->lt($leftSide, $rightSide)); }
/** * Generates query expression for operator and value of a Field Criterion. * * @throws \RuntimeException If operator is not handled. * * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * @param string $column * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(SelectQuery $query, Criterion $criterion, $column) { $column = $this->dbHandler->quoteColumn($column); switch ($criterion->operator) { case Criterion\Operator::IN: $filter = $query->expr->in($column, array_map(array($this, 'lowercase'), $criterion->value)); break; case Criterion\Operator::BETWEEN: $filter = $query->expr->between($column, $query->bindValue($this->lowercase($criterion->value[0])), $query->bindValue($this->lowercase($criterion->value[1]))); break; case Criterion\Operator::EQ: case Criterion\Operator::GT: case Criterion\Operator::GTE: case Criterion\Operator::LT: case Criterion\Operator::LTE: case Criterion\Operator::LIKE: $operatorFunction = $this->comparatorMap[$criterion->operator]; $filter = $query->expr->{$operatorFunction}($column, $query->bindValue($this->lowercase($criterion->value))); break; case Criterion\Operator::CONTAINS: $filter = $query->expr->like($column, $query->bindValue("%" . $this->lowercase($criterion->value) . "%")); break; default: throw new RuntimeException("Unknown operator '{$criterion->operator}' for Field criterion handler."); } return $filter; }
/** * Generate query expression for a Criterion this handler accepts. * * accept() must be called before calling this method. * * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * @param array $languageSettings * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion, array $languageSettings) { $statements = array(); foreach ($criterion->value as $pattern) { $statements[] = $query->expr->like($this->dbHandler->quoteColumn('path_string', 'ezcontentobject_tree'), $query->bindValue($pattern . '%')); } return $query->expr->lOr($statements); }
/** * Generate query expression for a Criterion this handler accepts * * accept() must be called before calling this method. * * @param \eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion) { $table = $this->getUniqueTableName(); $statements = array(); foreach ($criterion->value as $pattern) { $statements[] = $query->expr->like($this->dbHandler->quoteColumn('path_string', $table), $query->bindValue($pattern . '%')); } $query->leftJoin($query->alias($this->dbHandler->quoteTable('ezcontentobject_tree'), $this->dbHandler->quoteIdentifier($table)), $query->expr->eq($this->dbHandler->quoteColumn('contentobject_id', $table), $this->dbHandler->quoteColumn('id', 'ezcontentobject'))); return $query->expr->lOr($statements); }
/** * Generate query expression for a Criterion this handler accepts. * * accept() must be called before calling this method. * * @todo: Needs optimisation since this subselect can potentially be problematic * due to large number of contentobject_id values returned. One way to fix this * is to use inner joins on ezcontentobject_tree table, but this is not currently * supported in legacy search gateway * * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * @param array $languageSettings * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion, array $languageSettings) { $subSelect = $query->subSelect(); if ($criterion->value[0] === Criterion\Visibility::VISIBLE) { $expression = $query->expr->lAnd($query->expr->eq($this->dbHandler->quoteColumn('is_hidden', 'ezcontentobject_tree'), 0), $query->expr->eq($this->dbHandler->quoteColumn('is_invisible', 'ezcontentobject_tree'), 0)); } else { $expression = $query->expr->lOr($query->expr->eq($this->dbHandler->quoteColumn('is_hidden', 'ezcontentobject_tree'), 1), $query->expr->eq($this->dbHandler->quoteColumn('is_invisible', 'ezcontentobject_tree'), 1)); } $subSelect->select($this->dbHandler->quoteColumn('contentobject_id'))->from($this->dbHandler->quoteTable('ezcontentobject_tree'))->where($expression); return $query->expr->in($this->dbHandler->quoteColumn('id', 'ezcontentobject'), $subSelect); }
/** * Generates query expression for operator and value of a Field Criterion. * * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * @param string $column * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(SelectQuery $query, Criterion $criterion, $column) { switch ($criterion->operator) { case Criterion\Operator::CONTAINS: $filter = $query->expr->eq($this->dbHandler->quoteColumn($column), $query->bindValue($this->lowerCase($criterion->value))); break; default: $filter = parent::handle($query, $criterion, $column); } return $filter; }
/** * Generate query expression for a Criterion this handler accepts. * * accept() must be called before calling this method. * * @param \eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion) { $subSelect = $query->subSelect(); $subSelect->select($this->dbHandler->quoteColumn('id', 'ezcontentobject'))->from($this->dbHandler->quoteTable('ezcontentobject'))->innerJoin($this->dbHandler->quoteTable('eztags_attribute_link'), $subSelect->expr->lAnd(array($subSelect->expr->eq($this->dbHandler->quoteColumn('objectattribute_version', 'eztags_attribute_link'), $this->dbHandler->quoteColumn('current_version', 'ezcontentobject')), $subSelect->expr->eq($this->dbHandler->quoteColumn('object_id', 'eztags_attribute_link'), $this->dbHandler->quoteColumn('id', 'ezcontentobject')))))->where($query->expr->in($this->dbHandler->quoteColumn('keyword_id', 'eztags_attribute_link'), $criterion->value)); $fieldDefinitionIds = $this->getSearchableFields($criterion->target); if ($fieldDefinitionIds !== null) { $subSelect->innerJoin($this->dbHandler->quoteTable('ezcontentobject_attribute'), $subSelect->expr->lAnd(array($subSelect->expr->eq($this->dbHandler->quoteColumn('id', 'ezcontentobject_attribute'), $this->dbHandler->quoteColumn('objectattribute_id', 'eztags_attribute_link')), $subSelect->expr->eq($this->dbHandler->quoteColumn('version', 'ezcontentobject_attribute'), $this->dbHandler->quoteColumn('objectattribute_version', 'eztags_attribute_link'))))); $subSelect->where($query->expr->in($this->dbHandler->quoteColumn('contentclassattribute_id', 'ezcontentobject_attribute'), $fieldDefinitionIds)); } return $query->expr->in($this->dbHandler->quoteColumn('id', 'ezcontentobject'), $subSelect); }
/** * Generate query expression for a Criterion this handler accepts. * * accept() must be called before calling this method. * * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * @param array $languageSettings * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion, array $languageSettings) { $idSet = array(); foreach ($criterion->value as $value) { foreach (explode('/', trim($value, '/')) as $id) { $idSet[$id] = true; } } $subSelect = $query->subSelect(); $subSelect->select($this->dbHandler->quoteColumn('contentobject_id'))->from($this->dbHandler->quoteTable('ezcontentobject_tree'))->where($query->expr->in($this->dbHandler->quoteColumn('node_id'), array_keys($idSet))); return $query->expr->in($this->dbHandler->quoteColumn('id', 'ezcontentobject'), $subSelect); }
/** * Generate query expression for a Criterion this handler accepts * * accept() must be called before calling this method. * * @param \eZ\Publish\Core\Persistence\Legacy\Content\Search\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion$criterion * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion) { $column = $this->dbHandler->quoteColumn('is_invisible', 'ezcontentobject_tree'); switch ($criterion->value[0]) { case Criterion\Visibility::VISIBLE: return $query->expr->eq($column, $query->bindValue(0, null, PDO::PARAM_INT)); case Criterion\Visibility::HIDDEN: return $query->expr->eq($column, $query->bindValue(1, null, PDO::PARAM_INT)); default: throw new RuntimeException("Unknown value '{$criterion->value[0]}' for Visibility criterion handler."); } }
/** * Applies joins to the query, required to fetch sort data. * * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause $sortClause * @param int $number * @param array $languageSettings */ public function applyJoin(SelectQuery $query, SortClause $sortClause, $number, array $languageSettings) { /** @var \eZ\Publish\API\Repository\Values\Content\Query\SortClause\Target\FieldTarget $fieldTarget */ $fieldTarget = $sortClause->targetData; $fieldMap = $this->contentTypeHandler->getSearchableFieldMap(); if (!isset($fieldMap[$fieldTarget->typeIdentifier][$fieldTarget->fieldIdentifier]['field_definition_id'])) { throw new InvalidArgumentException('$sortClause->targetData', 'No searchable fields found for the given sort clause target ' . "'{$fieldTarget->fieldIdentifier}' on '{$fieldTarget->typeIdentifier}'."); } $fieldDefinitionId = $fieldMap[$fieldTarget->typeIdentifier][$fieldTarget->fieldIdentifier]['field_definition_id']; $table = $this->getSortTableName($number); $externalTable = $this->getSortTableName($number, 'ezgmaplocation'); $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')), $this->getFieldCondition($query, $languageSettings, $table)))->leftJoin($query->alias($this->dbHandler->quoteTable('ezgmaplocation'), $this->dbHandler->quoteIdentifier($externalTable)), $query->expr->lAnd($query->expr->eq($this->dbHandler->quoteColumn('contentobject_version', $externalTable), $this->dbHandler->quoteColumn('version', $table)), $query->expr->eq($this->dbHandler->quoteColumn('contentobject_attribute_id', $externalTable), $this->dbHandler->quoteColumn('id', $table)))); }
/** * Applies joins to the query, required to fetch sort data * * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause $sortClause * @param int $number * * @return void */ public function applyJoin(SelectQuery $query, SortClause $sortClause, $number) { /** @var \eZ\Publish\API\Repository\Values\Content\Query\SortClause\Target\FieldTarget $fieldTarget */ $fieldTarget = $sortClause->targetData; $table = $this->getSortTableName($number); if ($fieldTarget->languageCode === null) { $linkTable = $table; $query->innerJoin($query->alias($this->dbHandler->quoteTable("ezcontentobject_attribute"), $this->dbHandler->quoteIdentifier($table)), $query->expr->lAnd($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))); } else { $linkTable = $table . "_main_language"; $query->innerJoin($query->alias($this->dbHandler->quoteTable("ezcontentobject_attribute"), $this->dbHandler->quoteIdentifier($linkTable)), $query->expr->lAnd($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($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))); } $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)))); }
/** * Generate query expression for a Criterion this handler accepts. * * accept() must be called before calling this method. * * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * @param array $languageSettings * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion, array $languageSettings) { switch ($criterion->target) { case Criterion\UserMetadata::MODIFIER: return $query->expr->in($this->dbHandler->quoteColumn('creator_id', 'ezcontentobject_version'), $criterion->value); case Criterion\UserMetadata::GROUP: $subSelect = $query->subSelect(); $subSelect->select($this->dbHandler->quoteColumn('contentobject_id', 't1'))->from($query->alias($this->dbHandler->quoteTable('ezcontentobject_tree'), 't1'))->innerJoin($query->alias($this->dbHandler->quoteTable('ezcontentobject_tree'), 't2'), $query->expr->like('t1.path_string', $query->expr->concat('t2.path_string', $query->bindValue('%'))))->where($query->expr->in($this->dbHandler->quoteColumn('contentobject_id', 't2'), $criterion->value)); return $query->expr->in($this->dbHandler->quoteColumn('owner_id', 'ezcontentobject'), $subSelect); case Criterion\UserMetadata::OWNER: return $query->expr->in($this->dbHandler->quoteColumn('owner_id', 'ezcontentobject'), $criterion->value); } throw new RuntimeException("Invalid target criterion encountered:'" . $criterion->target . "'"); }
/** * Generate query expression for a Criterion this handler accepts * * accept() must be called before calling this method. * * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion) { switch ($criterion->target) { case Criterion\UserMetadata::MODIFIER: return $query->expr->in($this->dbHandler->quoteColumn("creator_id", "ezcontentobject_version"), $criterion->value); case Criterion\UserMetadata::GROUP: $subSelect = $query->subSelect(); $subSelect->select($this->dbHandler->quoteColumn("contentobject_id", "t1"))->from($query->alias($this->dbHandler->quoteTable("ezcontentobject_tree"), "t1"))->innerJoin($query->alias($this->dbHandler->quoteTable("ezcontentobject_tree"), "t2"), $query->expr->like("t1.path_string", $query->expr->concat("t2.path_string", $query->bindValue("%"))))->where($query->expr->in($this->dbHandler->quoteColumn("contentobject_id", "t2"), $criterion->value)); return $query->expr->in($this->dbHandler->quoteColumn("owner_id", "ezcontentobject"), $subSelect); case Criterion\UserMetadata::OWNER: return $query->expr->in($this->dbHandler->quoteColumn("owner_id", "ezcontentobject"), $criterion->value); } throw new RuntimeException("Invalid target criterion encountered:'" . $criterion->target . "'"); }
/** * Generate query expression for a Criterion this handler accepts * * accept() must be called before calling this method. * * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * @param array $fieldFilters * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion, array $fieldFilters) { $subSelect = $query->subSelect(); switch ($criterion->operator) { case Criterion\Operator::BETWEEN: $subSelect->select($this->dbHandler->quoteColumn('contentobject_id'))->from($this->dbHandler->quoteTable('ezcontentobject_tree'))->where($query->expr->between($this->dbHandler->quoteColumn('priority'), $criterion->value[0], $criterion->value[1])); break; case Criterion\Operator::GT: case Criterion\Operator::GTE: case Criterion\Operator::LT: case Criterion\Operator::LTE: $operatorFunction = $this->comparatorMap[$criterion->operator]; $subSelect->select($this->dbHandler->quoteColumn('contentobject_id'))->from($this->dbHandler->quoteTable('ezcontentobject_tree'))->where($query->expr->{$operatorFunction}($this->dbHandler->quoteColumn('priority'), reset($criterion->value))); } return $query->expr->in($this->dbHandler->quoteColumn('id', 'ezcontentobject'), $subSelect); }
/** * Generate query expression for a Criterion this handler accepts * * accept() must be called before calling this method. * * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion$criterion * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion) { $column = $this->dbHandler->quoteColumn('priority'); switch ($criterion->operator) { case Criterion\Operator::BETWEEN: return $query->expr->between($column, $query->bindValue($criterion->value[0]), $query->bindValue($criterion->value[1])); case Criterion\Operator::GT: case Criterion\Operator::GTE: case Criterion\Operator::LT: case Criterion\Operator::LTE: $operatorFunction = $this->comparatorMap[$criterion->operator]; return $query->expr->{$operatorFunction}($column, $query->bindValue(reset($criterion->value))); default: throw new RuntimeException("Unknown operator '{$criterion->operator}' for Priority criterion handler."); } }
/** * Generate query expression for a Criterion this handler accepts. * * accept() must be called before calling this method. * * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * @param array $fieldFilters * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion, array $fieldFilters) { $table = 'permission_subtree'; $statements = array(); foreach ($criterion->value as $pattern) { $statements[] = $query->expr->like($this->dbHandler->quoteColumn('path_string', $table), $query->bindValue($pattern . '%')); } // Check if ezcontentobject_tree was already joined, if it was there is no need to join // with it again - first join will be reused by all other PermissionSubtree criteria /** @var $query \eZ\Publish\Core\Persistence\Doctrine\SelectDoctrineQuery */ if (!$query->permissionSubtreeJoinAdded) { $query->leftJoin($query->alias($this->dbHandler->quoteTable('ezcontentobject_tree'), $this->dbHandler->quoteIdentifier($table)), $query->expr->eq($this->dbHandler->quoteColumn('contentobject_id', $table), $this->dbHandler->quoteColumn('id', 'ezcontentobject'))); // Set joined state to true $query->permissionSubtreeJoinAdded = true; } return $query->expr->lOr($statements); }
/** * Generate query expression for a Criterion this handler accepts. * * accept() must be called before calling this method. * * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * @param array $languageSettings * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion, array $languageSettings) { $column = $this->dbHandler->quoteColumn('depth', 'ezcontentobject_tree'); switch ($criterion->operator) { case Criterion\Operator::IN: return $query->expr->in($column, $criterion->value); case Criterion\Operator::BETWEEN: return $query->expr->between($column, $query->bindValue($criterion->value[0]), $query->bindValue($criterion->value[1])); case Criterion\Operator::EQ: case Criterion\Operator::GT: case Criterion\Operator::GTE: case Criterion\Operator::LT: case Criterion\Operator::LTE: $operatorFunction = $this->comparatorMap[$criterion->operator]; return $query->expr->{$operatorFunction}($column, $query->bindValue(reset($criterion->value))); default: throw new RuntimeException("Unknown operator '{$criterion->operator}' for Depth criterion handler."); } }
/** * Generate query expression for a Criterion this handler accepts. * * accept() must be called before calling this method. * * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion) { $column = $this->dbHandler->quoteColumn($criterion->target === Criterion\DateMetadata::MODIFIED ? 'modified' : 'published', 'ezcontentobject'); switch ($criterion->operator) { case Criterion\Operator::IN: return $query->expr->in($column, $criterion->value); case Criterion\Operator::BETWEEN: return $query->expr->between($column, $query->bindValue($criterion->value[0]), $query->bindValue($criterion->value[1])); case Criterion\Operator::EQ: case Criterion\Operator::GT: case Criterion\Operator::GTE: case Criterion\Operator::LT: case Criterion\Operator::LTE: $operatorFunction = $this->comparatorMap[$criterion->operator]; return $query->expr->{$operatorFunction}($column, $query->bindValue(reset($criterion->value))); default: throw new RuntimeException("Unknown operator '{$criterion->operator}' for DateMetadata criterion handler."); } }
/** * Applies joins to the query, required to fetch sort data * * @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, 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) { $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 { $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)); }
/** * Adds field filters condition to the WHERE clause of the given $query. * * Conditions are combined with existing ones using logical AND operator. * * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param array $fieldFilters */ protected function addFieldFiltersConditions(SelectQuery $query, array $fieldFilters) { $languageMask = $this->getFieldFiltersLanguageMask($fieldFilters); // Only apply if languages are defined in $fieldFilters; // 'useAlwaysAvailable' does not make sense on its own if ($languageMask === null) { return; } // Condition for the language part of $fieldFilters $languageMaskExpression = $query->expr->gt($query->expr->bitAnd($this->dbHandler->quoteColumn("language_id", "ezcontentobject_attribute"), $query->bindValue($languageMask, null, \PDO::PARAM_INT)), $query->bindValue(0, null, \PDO::PARAM_INT)); // If 'useAlwaysAvailable' is set to true, additionally factor in condition for the // Content's main language that is marked as always available if (!isset($fieldFilters["useAlwaysAvailable"]) || $fieldFilters["useAlwaysAvailable"] === true) { $query->where($query->expr->lOr($languageMaskExpression, $query->expr->lAnd($query->expr->gt($query->expr->bitAnd($this->dbHandler->quoteColumn("language_id", "ezcontentobject_attribute"), $this->dbHandler->quoteColumn("initial_language_id", "ezcontentobject")), $query->bindValue(0, null, \PDO::PARAM_INT)), $query->expr->gt($query->expr->bitAnd($this->dbHandler->quoteColumn("language_id", "ezcontentobject_attribute"), $query->bindValue(1, null, \PDO::PARAM_INT)), $query->bindValue(0, null, \PDO::PARAM_INT))))); } else { // Matching on a given list of languages $query->where($languageMaskExpression); } }
/** * Generates query expression for operator and value of a Field Criterion. * * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * @param string $column * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(SelectQuery $query, Criterion $criterion, $column) { switch ($criterion->operator) { case Criterion\Operator::CONTAINS: $quotedColumn = $this->dbHandler->quoteColumn($column); $value = $this->lowerCase($criterion->value); $filter = $query->expr->lOr(array($query->expr->eq($quotedColumn, $query->bindValue($value, null, \PDO::PARAM_STR)), $query->expr->like($quotedColumn, $query->bindValue("%" . $this->separator . $value, null, \PDO::PARAM_STR)), $query->expr->like($quotedColumn, $query->bindValue($value . $this->separator . "%", null, \PDO::PARAM_STR)), $query->expr->like($quotedColumn, $query->bindValue("%" . $this->separator . $value . $this->separator . "%", null, \PDO::PARAM_STR)))); break; default: $filter = parent::handle($query, $criterion, $column); } return $filter; }
/** * Generate query expression for a Criterion this handler accepts * * accept() must be called before calling this method. * * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * @param array $fieldFilters * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion, array $fieldFilters) { $table = $this->getUniqueTableName(); $column = $this->dbHandler->quoteColumn('depth', $table); $query->leftJoin($query->alias($this->dbHandler->quoteTable('ezcontentobject_tree'), $this->dbHandler->quoteIdentifier($table)), $query->expr->eq($this->dbHandler->quoteColumn('contentobject_id', $table), $this->dbHandler->quoteColumn('id', 'ezcontentobject'))); switch ($criterion->operator) { case Criterion\Operator::IN: return $query->expr->in($column, $criterion->value); case Criterion\Operator::BETWEEN: return $query->expr->between($column, $query->bindValue($criterion->value[0]), $query->bindValue($criterion->value[1])); case Criterion\Operator::EQ: case Criterion\Operator::GT: case Criterion\Operator::GTE: case Criterion\Operator::LT: case Criterion\Operator::LTE: $operatorFunction = $this->comparatorMap[$criterion->operator]; return $query->expr->{$operatorFunction}($column, $query->bindValue(reset($criterion->value))); default: throw new RuntimeException("Unknown operator '{$criterion->operator}' for Depth criterion handler."); } }
/** * Apply selects to the query * * Returns the name of the (aliased) column, which information should be * used for sorting. * * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause $sortClause * @param int $number * * @return string */ public function applySelect(SelectQuery $query, SortClause $sortClause, $number) { $query->select($query->alias($this->dbHandler->quoteColumn('node_id', 'ezcontentobject_tree'), $column = $this->getSortColumnName($number))); return $column; }
/** * Generate query expression for a Criterion this handler accepts * * accept() must be called before calling this method. * * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * @param array $fieldFilters * * @return \eZ\Publish\Core\Persistence\Database\Expression */ public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion, array $fieldFilters) { $subSelect = $query->subSelect(); $subSelect->select($this->dbHandler->quoteColumn('contentobject_id'))->from($this->dbHandler->quoteTable('ezcontentobject_tree'))->where($query->expr->in($this->dbHandler->quoteColumn('node_id'), $criterion->value)); return $query->expr->in($this->dbHandler->quoteColumn('id', 'ezcontentobject'), $subSelect); }
/** * Assert query result as correct. * * Builds text representations of the asserted and fetched query result, * based on a eZ\Publish\Core\Persistence\Database\SelectQuery object. Compares them using classic diff for * maximum readability of the differences between expectations and real * results. * * The expectation MUST be passed as a two dimensional array containing * rows of columns. * * @param array $expectation * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param string $message */ public static function assertQueryResult(array $expectation, SelectQuery $query, $message = null) { $statement = $query->prepare(); $statement->execute(); $result = array(); while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) { $result[] = $row; } return self::assertEquals(self::getResultTextRepresentation($expectation), self::getResultTextRepresentation($result), $message); }
/** * Apply selects to the query * * Returns the name of the (aliased) column, which information should be * used for sorting. * * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause $sortClause * @param int $number * * @return string */ public function applySelect(SelectQuery $query, SortClause $sortClause, $number) { $query->select($query->alias($this->dbHandler->quoteColumn("modified", "ezcontentobject"), $column = $this->getSortColumnName($number))); return $column; }
/** * Creates an array of select columns for $tableName. * * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $q * @param string $tableName */ protected function selectColumns(SelectQuery $q, $tableName) { foreach ($this->columns[$tableName] as $col) { $q->select($this->dbHandler->aliasedColumn($q, $col, $tableName)); } }