/**
  * 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);
 }
 /**
  * Get sorted arrays of content IDs, which should be returned
  *
  * @param Criterion $criterion
  * @param array $sort
  * @param mixed $offset
  * @param mixed $limit
  * @param mixed $translations
  *
  * @return int[]
  */
 protected function getContentIds(Criterion $criterion, $sort, $offset, $limit, $translations)
 {
     $query = $this->handler->createSelectQuery();
     $query->select($this->handler->quoteColumn('id', 'ezcontentobject'));
     if ($sort !== null) {
         $this->sortClauseConverter->applySelect($query, $sort);
     }
     $query->from($this->handler->quoteTable('ezcontentobject'));
     $query->innerJoin('ezcontentobject_version', 'ezcontentobject.id', 'ezcontentobject_version.contentobject_id');
     if ($sort !== null) {
         $this->sortClauseConverter->applyJoin($query, $sort);
     }
     $query->where($this->getQueryCondition($criterion, $query, $translations));
     if ($sort !== null) {
         $this->sortClauseConverter->applyOrderBy($query, $sort);
     }
     $query->limit($limit, $offset);
     $statement = $query->prepare();
     $statement->execute();
     return $statement->fetchAll(\PDO::FETCH_COLUMN);
 }
 /**
  * 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);
 }
 /**
  * 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;
 }
 /**
  * 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();
 }