/** * Remove all limitations for a policy * * @param mixed $policyId * * @return void */ public function removePolicyLimitations($policyId) { $query = $this->handler->createSelectQuery(); $query->select($this->handler->aliasedColumn($query, 'id', 'ezpolicy_limitation'), $this->handler->aliasedColumn($query, 'id', 'ezpolicy_limitation_value'))->from($this->handler->quoteTable('ezpolicy'))->leftJoin($this->handler->quoteTable('ezpolicy_limitation'), $query->expr->eq($this->handler->quoteColumn('policy_id', 'ezpolicy_limitation'), $this->handler->quoteColumn('id', 'ezpolicy')))->leftJoin($this->handler->quoteTable('ezpolicy_limitation_value'), $query->expr->eq($this->handler->quoteColumn('limitation_id', 'ezpolicy_limitation_value'), $this->handler->quoteColumn('id', 'ezpolicy_limitation')))->where($query->expr->eq($this->handler->quoteColumn('id', 'ezpolicy'), $query->bindValue($policyId, null, \PDO::PARAM_INT))); $statement = $query->prepare(); $statement->execute(); $limitationIdsSet = array(); $limitationValuesSet = array(); while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) { if ($row['ezpolicy_limitation_id'] !== null) { $limitationIdsSet[$row['ezpolicy_limitation_id']] = true; } if ($row['ezpolicy_limitation_value_id'] !== null) { $limitationValuesSet[$row['ezpolicy_limitation_value_id']] = true; } } if (!empty($limitationIdsSet)) { $query = $this->handler->createDeleteQuery(); $query->deleteFrom($this->handler->quoteTable('ezpolicy_limitation'))->where($query->expr->in($this->handler->quoteColumn('id'), array_keys($limitationIdsSet))); $query->prepare()->execute(); } if (!empty($limitationValuesSet)) { $query = $this->handler->createDeleteQuery(); $query->deleteFrom($this->handler->quoteTable('ezpolicy_limitation_value'))->where($query->expr->in($this->handler->quoteColumn('id'), array_keys($limitationValuesSet))); $query->prepare()->execute(); } }
/** * Loads an array with data about UrlWildcards (paged) * * @param mixed $offset * @param mixed $limit * * @return array */ public function loadUrlWildcardsData($offset = 0, $limit = -1) { $limit = $limit === -1 ? self::MAX_LIMIT : $limit; /** @var $query \ezcQuerySelect */ $query = $this->dbHandler->createSelectQuery(); $query->select("*")->from($this->dbHandler->quoteTable("ezurlwildcard"))->limit($limit > 0 ? $limit : self::MAX_LIMIT, $offset); $stmt = $query->prepare(); $stmt->execute(); return $stmt->fetchAll(\PDO::FETCH_ASSOC); }
/** * Loads the actual content based on the provided IDs * * @param array $contentIds * @param mixed $translations * * @return mixed[] */ protected function loadContent(array $contentIds, $translations) { $loadQuery = $this->queryBuilder->createFindQuery($translations); $loadQuery->where($loadQuery->expr->eq('ezcontentobject_version.status', VersionInfo::STATUS_PUBLISHED), $loadQuery->expr->in($this->handler->quoteColumn('id', 'ezcontentobject'), $contentIds)); $statement = $loadQuery->prepare(); $statement->execute(); $rows = $statement->fetchAll(\PDO::FETCH_ASSOC); // Sort array, as defined in the $contentIds array $contentIdOrder = array_flip($contentIds); usort($rows, function ($current, $next) use($contentIdOrder) { return $contentIdOrder[$current['ezcontentobject_id']] - $contentIdOrder[$next['ezcontentobject_id']]; }); foreach ($rows as &$row) { $row['ezcontentobject_always_available'] = $this->languageMaskGenerator->isAlwaysAvailable($row['ezcontentobject_language_mask']); $row['ezcontentobject_main_language_code'] = $this->languageHandler->load($row['ezcontentobject_initial_language_id'])->languageCode; $row['ezcontentobject_version_languages'] = $this->languageMaskGenerator->extractLanguageIdsFromMask($row['ezcontentobject_version_language_mask']); $row['ezcontentobject_version_initial_language_code'] = $this->languageHandler->load($row['ezcontentobject_version_initial_language_id'])->languageCode; } return $rows; }
/** * Generate query expression for a Criterion this handler accepts * * accept() must be called before calling this method. * * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If no searchable fields are found for the given criterion target. * * @param \eZ\Publish\Core\Persistence\Legacy\Content\Search\Gateway\CriteriaConverter$converter * @param \ezcQuerySelect $query * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion$criterion * * @return \ezcQueryExpression */ public function handle(CriteriaConverter $converter, ezcQuerySelect $query, Criterion $criterion) { $fieldsInformation = $this->getFieldsInformation($criterion->target); $subSelect = $query->subSelect(); $subSelect->select($this->dbHandler->quoteColumn('contentobject_id'))->from($this->dbHandler->quoteTable('ezcontentobject_attribute')); $whereExpressions = array(); foreach ($fieldsInformation as $fieldTypeIdentifier => $fieldsInfo) { if ($fieldsInfo['column'] === false) { throw new NotImplementedException("A field of type '{$fieldTypeIdentifier}' is not searchable in the legacy search engine."); } $column = $this->dbHandler->quoteColumn($fieldsInfo['column']); switch ($criterion->operator) { case Criterion\Operator::IN: $filter = $subSelect->expr->in($column, $criterion->value); break; case Criterion\Operator::BETWEEN: $filter = $subSelect->expr->between($column, $subSelect->bindValue($criterion->value[0]), $subSelect->bindValue($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 = $subSelect->expr->{$operatorFunction}($column, $subSelect->bindValue($criterion->value)); break; default: throw new RuntimeException('Unknown operator.'); } $whereExpressions[] = $subSelect->expr->lAnd($subSelect->expr->in($this->dbHandler->quoteColumn('contentclassattribute_id'), $fieldsInfo['ids']), $filter); } if (isset($whereExpressions[1])) { $subSelect->where($subSelect->expr->lOr($whereExpressions)); } else { $subSelect->where($whereExpressions[0]); } return $query->expr->in($this->dbHandler->quoteColumn('id', 'ezcontentobject'), $subSelect); }
public function getSequenceName($table, $column) { if ($table === "ezcontentobject_attribute" && $column === "id") { return "{$table}.{$column}"; } if ($table === "ezcontentclass" && $column === "id") { return "{$table}.{$column}"; } if ($table === "ezcontentclass_attribute" && $column === "id") { return "{$table}.{$column}"; } return parent::getSequenceName($table, $column); }
/** * Get ezcontent_language Id * @param \eZ\Publish\Core\Persistence\Legacy\EzcDbHandler $connection * @param $languageCode * @return int */ protected function getLanguageId($connection, $languageCode) { /** @var \ezcQuerySelect $selectQuery */ $selectQuery = $connection->createSelectQuery(); $selectQuery->select($connection->quoteColumn('id'))->from($connection->quoteTable('ezcontent_language'))->where($selectQuery->expr->eq($connection->quoteColumn('locale'), $selectQuery->bindValue($languageCode, null, \PDO::PARAM_STR))); $statement = $selectQuery->prepare(); $statement->execute(); $row = $statement->fetch(); if (isset($row['id'])) { return $row['id']; } return 0; }
/** * Builds the DB handler used by the legacy storage engine. * * @return \eZ\Publish\Core\Persistence\Legacy\EzcDbHandler */ public function buildLegacyDbHandler() { return EzcDbHandler::create($this->configResolver->getParameter('database.params')); }
/** * Deletes all translations of the $groupId state group * * @param mixed $groupId */ protected function deleteObjectStateGroupTranslations($groupId) { $query = $this->dbHandler->createDeleteQuery(); $query->deleteFrom($this->dbHandler->quoteTable('ezcobj_state_group_language'))->where($query->expr->eq($this->dbHandler->quoteColumn('contentobject_state_group_id'), $query->bindValue($groupId, null, \PDO::PARAM_INT))); $query->prepare()->execute(); }
/** * Remove role from user * * @param mixed $contentId * @param mixed $roleId */ public function removeRole($contentId, $roleId) { $query = $this->handler->createDeleteQuery(); $query->deleteFrom($this->handler->quoteTable('ezuser_role'))->where($query->expr->lAnd($query->expr->eq($this->handler->quoteColumn('contentobject_id'), $query->bindValue($contentId, null, \PDO::PARAM_INT)), $query->expr->eq($this->handler->quoteColumn('role_id'), $query->bindValue($roleId, null, \PDO::PARAM_INT)))); $query->prepare()->execute(); }
/** * Returns the quoted sort column name * * @param int $number * * @return string */ protected function getSortColumnName($number) { return $this->dbHandler->quoteIdentifier('sort_column_' . $number); }