Create Select Query object.
public createSelectQuery ( ) : eZ\Publish\Core\Persistence\Database\SelectQuery | ||
return | eZ\Publish\Core\Persistence\Database\SelectQuery |
public function init() { $selectQuery = $this->dbHandler->createSelectQuery(); $selectQuery->select('filepath')->from($this->dbHandler->quoteTable('ezimagefile')); $this->statement = $selectQuery->prepare(); $this->statement->execute(); }
/** * Creates a select query for content version objects * * Creates a select query with all necessary joins to fetch a complete * content object. Does not apply any WHERE conditions. * * @return \eZ\Publish\Core\Persistence\Database\SelectQuery */ public function createVersionInfoFindQuery() { /** @var $query \eZ\Publish\Core\Persistence\Database\SelectQuery */ $query = $this->dbHandler->createSelectQuery(); $query->select($this->dbHandler->aliasedColumn($query, 'id', 'ezcontentobject_version'), $this->dbHandler->aliasedColumn($query, 'version', 'ezcontentobject_version'), $this->dbHandler->aliasedColumn($query, 'modified', 'ezcontentobject_version'), $this->dbHandler->aliasedColumn($query, 'creator_id', 'ezcontentobject_version'), $this->dbHandler->aliasedColumn($query, 'created', 'ezcontentobject_version'), $this->dbHandler->aliasedColumn($query, 'status', 'ezcontentobject_version'), $this->dbHandler->aliasedColumn($query, 'contentobject_id', 'ezcontentobject_version'), $this->dbHandler->aliasedColumn($query, 'initial_language_id', 'ezcontentobject_version'), $this->dbHandler->aliasedColumn($query, 'language_mask', 'ezcontentobject_version'), $this->dbHandler->aliasedColumn($query, 'main_node_id', 'ezcontentobject_tree'), $this->dbHandler->aliasedColumn($query, 'id', 'ezcontentobject'), $this->dbHandler->aliasedColumn($query, 'contentclass_id', 'ezcontentobject'), $this->dbHandler->aliasedColumn($query, 'section_id', 'ezcontentobject'), $this->dbHandler->aliasedColumn($query, 'owner_id', 'ezcontentobject'), $this->dbHandler->aliasedColumn($query, 'remote_id', 'ezcontentobject'), $this->dbHandler->aliasedColumn($query, 'current_version', 'ezcontentobject'), $this->dbHandler->aliasedColumn($query, 'initial_language_id', 'ezcontentobject'), $this->dbHandler->aliasedColumn($query, 'modified', 'ezcontentobject'), $this->dbHandler->aliasedColumn($query, 'published', 'ezcontentobject'), $this->dbHandler->aliasedColumn($query, 'status', 'ezcontentobject'), $this->dbHandler->aliasedColumn($query, 'name', 'ezcontentobject'), $this->dbHandler->aliasedColumn($query, 'language_mask', 'ezcontentobject'), $this->dbHandler->aliasedColumn($query, 'name', 'ezcontentobject_name'), $this->dbHandler->aliasedColumn($query, 'content_translation', 'ezcontentobject_name'))->from($this->dbHandler->quoteTable('ezcontentobject_version'))->leftJoin($this->dbHandler->quoteTable('ezcontentobject'), $query->expr->eq($this->dbHandler->quoteColumn('id', 'ezcontentobject'), $this->dbHandler->quoteColumn('contentobject_id', 'ezcontentobject_version')))->leftJoin($this->dbHandler->quoteTable('ezcontentobject_tree'), $query->expr->lAnd($query->expr->eq($this->dbHandler->quoteColumn('contentobject_id', 'ezcontentobject_tree'), $this->dbHandler->quoteColumn('contentobject_id', 'ezcontentobject_version')), $query->expr->eq($this->dbHandler->quoteColumn('main_node_id', 'ezcontentobject_tree'), $this->dbHandler->quoteColumn('node_id', 'ezcontentobject_tree'))))->leftJoin($this->dbHandler->quoteTable('ezcontentobject_name'), $query->expr->lAnd($query->expr->eq($this->dbHandler->quoteColumn('contentobject_id', 'ezcontentobject_name'), $this->dbHandler->quoteColumn('contentobject_id', 'ezcontentobject_version')), $query->expr->eq($this->dbHandler->quoteColumn('content_version', 'ezcontentobject_name'), $this->dbHandler->quoteColumn('version', 'ezcontentobject_version')))); return $query; }
/** * Fetch location Ids for the given content object. * * @param int $contentObjectId * @return array Location nodes Ids */ protected function getContentLocationIds($contentObjectId) { $query = $this->databaseHandler->createSelectQuery(); $query->select('node_id')->from($this->databaseHandler->quoteTable(self::CONTENTOBJECT_TREE_TABLE))->where($query->expr->eq('contentobject_id', $contentObjectId)); $stmt = $query->prepare(); $stmt->execute(); $nodeIds = $stmt->fetchAll(PDO::FETCH_COLUMN); return is_array($nodeIds) ? array_map('intval', $nodeIds) : []; }
/** * Checks if there are searchable fields for the Criterion * * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If no searchable fields are found for the given $fieldIdentifier. * * @caching * @param string $fieldIdentifier * * @return void */ protected function checkSearchableFields($fieldIdentifier) { $query = $this->dbHandler->createSelectQuery(); $query->select($this->dbHandler->quoteColumn('id', 'ezcontentclass_attribute'))->from($this->dbHandler->quoteTable('ezcontentclass_attribute'))->where($query->expr->lAnd($query->expr->eq($this->dbHandler->quoteColumn('is_searchable', 'ezcontentclass_attribute'), $query->bindValue(1, null, \PDO::PARAM_INT)), $query->expr->eq($this->dbHandler->quoteColumn('data_type_string', 'ezcontentclass_attribute'), $query->bindValue("ezgmaplocation")), $query->expr->eq($this->dbHandler->quoteColumn('identifier', 'ezcontentclass_attribute'), $query->bindValue($fieldIdentifier)))); $statement = $query->prepare(); $statement->execute(); $fieldDefinitionIds = $statement->fetchAll(\PDO::FETCH_COLUMN); if (empty($fieldDefinitionIds)) { throw new InvalidArgumentException("\$criterion->target", "No searchable fields found for the given criterion target '{$fieldIdentifier}'."); } }
/** * @param string $migrationName * @return Migration|null */ public function loadMigration($migrationName) { /** @var \eZ\Publish\Core\Persistence\Database\SelectQuery $q */ $q = $this->dbHandler->createSelectQuery(); $q->select('migration, md5, path, execution_date, status, execution_error')->from($this->migrationsTableName)->where($q->expr->eq('migration', $q->bindValue($migrationName))); $stmt = $q->prepare(); $stmt->execute(); $result = $stmt->fetch(\PDO::FETCH_ASSOC); if (is_array($result) && !empty($result)) { return $this->arrayToMigration($result); } return null; }
/** * Remove all limitations for a policy. * * @param mixed $policyId */ 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 user with user email. * * @param string $email * * @return array */ public function loadByEmail( $email ) { $query = $this->handler->createSelectQuery(); $query->select( $this->handler->quoteColumn( 'contentobject_id', 'ezuser' ), $this->handler->quoteColumn( 'login', 'ezuser' ), $this->handler->quoteColumn( 'email', 'ezuser' ), $this->handler->quoteColumn( 'password_hash', 'ezuser' ), $this->handler->quoteColumn( 'password_hash_type', 'ezuser' ), $this->handler->quoteColumn( 'is_enabled', 'ezuser_setting' ), $this->handler->quoteColumn( 'max_login', 'ezuser_setting' ) )->from( $this->handler->quoteTable( 'ezuser' ) ); $query = $this->addContentObjectJoin( $query ); $query->leftJoin( $this->handler->quoteTable( 'ezuser_setting' ), $query->expr->eq( $this->handler->quoteColumn( 'user_id', 'ezuser_setting' ), $this->handler->quoteColumn( 'contentobject_id', 'ezuser' ) ) )->where( $query->expr->eq( $this->handler->quoteColumn( 'email', 'ezuser' ), $query->bindValue( $email, null, \PDO::PARAM_STR ) ) ); $statement = $query->prepare(); $statement->execute(); return $statement->fetchAll( \PDO::FETCH_ASSOC ); }
/** * Deletes the relation with the given $relationId. * * @param int $relationId * @param int $type {@see \eZ\Publish\API\Repository\Values\Content\Relation::COMMON, * \eZ\Publish\API\Repository\Values\Content\Relation::EMBED, * \eZ\Publish\API\Repository\Values\Content\Relation::LINK, * \eZ\Publish\API\Repository\Values\Content\Relation::FIELD} * * @return void */ public function deleteRelation($relationId, $type) { // Legacy Storage stores COMMON, LINK and EMBED types using bitmask, therefore first load // existing relation type by given $relationId for comparison /** @var $query \eZ\Publish\Core\Persistence\Database\SelectQuery */ $query = $this->dbHandler->createSelectQuery(); $query->select($this->dbHandler->quoteColumn("relation_type"))->from($this->dbHandler->quoteTable("ezcontentobject_link"))->where($query->expr->eq($this->dbHandler->quoteColumn("id"), $query->bindValue($relationId, null, \PDO::PARAM_INT))); $statement = $query->prepare(); $statement->execute(); $loadedRelationType = $statement->fetchColumn(); if (!$loadedRelationType) { return; } // If relation type matches then delete if ($loadedRelationType == $type) { /** @var $query \eZ\Publish\Core\Persistence\Database\DeleteQuery */ $query = $this->dbHandler->createDeleteQuery(); $query->deleteFrom("ezcontentobject_link")->where($query->expr->eq($this->dbHandler->quoteColumn("id"), $query->bindValue($relationId, null, \PDO::PARAM_INT))); $query->prepare()->execute(); } else { if ($loadedRelationType & $type) { /** @var $query \eZ\Publish\Core\Persistence\Database\UpdateQuery */ $query = $this->dbHandler->createUpdateQuery(); $query->update($this->dbHandler->quoteTable("ezcontentobject_link"))->set($this->dbHandler->quoteColumn("relation_type"), $query->expr->bitAnd($this->dbHandler->quoteColumn("relation_type"), $query->bindValue(~$type, null, \PDO::PARAM_INT)))->where($query->expr->eq($this->dbHandler->quoteColumn("id"), $query->bindValue($relationId, null, \PDO::PARAM_INT))); $query->prepare()->execute(); } else { // No match, do nothing } } }
function convertFields(OutputInterface $output) { $query = $this->db->createSelectQuery(); $query->select($query->expr->count('*')); $query->from('ezcontentobject_attribute'); $query->where($query->expr->eq($this->db->quoteIdentifier('data_type_string'), $query->bindValue('ezxmltext', null, PDO::PARAM_STR))); $statement = $query->prepare(); $statement->execute(); $count = $statement->fetchColumn(); $output->writeln("Found {$count} field rows to convert."); $query = $this->db->createSelectQuery(); $query->select('*'); $query->from('ezcontentobject_attribute'); $query->where($query->expr->eq($this->db->quoteIdentifier('data_type_string'), $query->bindValue('ezxmltext', null, PDO::PARAM_STR))); $statement = $query->prepare(); $statement->execute(); while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { if (empty($row['data_text'])) { $inputValue = Value::EMPTY_VALUE; } else { $inputValue = $row['data_text']; } $converted = $this->convert($inputValue); $updateQuery = $this->db->createUpdateQuery(); $updateQuery->update($this->db->quoteIdentifier('ezcontentobject_attribute')); $updateQuery->set($this->db->quoteIdentifier('data_type_string'), $updateQuery->bindValue('ezrichtext', null, PDO::PARAM_STR)); $updateQuery->set($this->db->quoteIdentifier('data_text'), $updateQuery->bindValue($converted, null, PDO::PARAM_STR)); $updateQuery->where($updateQuery->expr->lAnd($updateQuery->expr->eq($this->db->quoteIdentifier('id'), $updateQuery->bindValue($row['id'], null, PDO::PARAM_INT)), $updateQuery->expr->eq($this->db->quoteIdentifier('version'), $updateQuery->bindValue($row['version'], null, PDO::PARAM_INT)))); $updateQuery->prepare()->execute(); $this->logger->info("Converted ezxmltext field #{$row['id']} to richtext", ['original' => $inputValue, 'converted' => $converted]); } $output->writeln("Converted {$count} ezxmltext fields to richtext"); }
/** * Counts the number of instances that exists of the identified type. * * @param int $typeId * * @return int */ public function countInstancesOfType($typeId) { $q = $this->dbHandler->createSelectQuery(); $q->select($q->alias($q->expr->count($this->dbHandler->quoteColumn('id')), 'count'))->from($this->dbHandler->quoteTable('ezcontentobject'))->where($q->expr->eq($this->dbHandler->quoteColumn('contentclass_id'), $q->bindValue($typeId, null, \PDO::PARAM_INT))); $stmt = $q->prepare(); $stmt->execute(); return (int) $stmt->fetchColumn(); }
/** * Returns all Content IDs for a given $contentTypeId. * * @param int $contentTypeId * * @return int[] */ public function getContentIdsByContentTypeId($contentTypeId) { $query = $this->dbHandler->createSelectQuery(); $query->select($this->dbHandler->quoteColumn('id'))->from($this->dbHandler->quoteTable('ezcontentobject'))->where($query->expr->eq($this->dbHandler->quoteColumn('contentclass_id'), $query->bindValue($contentTypeId, null, PDO::PARAM_INT))); $statement = $query->prepare(); $statement->execute(); return $statement->fetchAll(PDO::FETCH_COLUMN); }
/** * Returns searchable field mapping data * * @return array */ public function getSearchableFieldMapData() { $query = $this->dbHandler->createSelectQuery(); $query->select($this->dbHandler->alias($this->dbHandler->quoteColumn("identifier", "ezcontentclass_attribute"), $this->dbHandler->quoteIdentifier("field_definition_identifier")), $this->dbHandler->alias($this->dbHandler->quoteColumn("identifier", "ezcontentclass"), $this->dbHandler->quoteIdentifier("content_type_identifier")), $this->dbHandler->alias($this->dbHandler->quoteColumn("id", "ezcontentclass_attribute"), $this->dbHandler->quoteIdentifier("field_definition_id")), $this->dbHandler->alias($this->dbHandler->quoteColumn("data_type_string", "ezcontentclass_attribute"), $this->dbHandler->quoteIdentifier("field_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")))->where($query->expr->eq($this->dbHandler->quoteColumn("is_searchable", "ezcontentclass_attribute"), $query->bindValue(1, null, PDO::PARAM_INT))); $statement = $query->prepare($query); $statement->execute(); return $statement->fetchAll(\PDO::FETCH_ASSOC); }
/** * Returns how many locations given content object identified by $contentId has. * * @param int $contentId * * @return int */ public function countLocationsByContentId($contentId) { $q = $this->handler->createSelectQuery(); $q->select($q->alias($q->expr->count('*'), 'count'))->from($this->handler->quoteTable('ezcontentobject_tree'))->where($q->expr->eq($this->handler->quoteColumn('contentobject_id'), $q->bindValue($contentId, null, \PDO::PARAM_INT))); $stmt = $q->prepare(); $stmt->execute(); $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); return (int) $res[0]['count']; }
/** * Get sorted arrays of content IDs, which should be returned * * @param Criterion $filter * @param array $sort * @param mixed $offset * @param mixed $limit * @param mixed $translations * * @return int[] */ protected function getContentInfoList( Criterion $filter, $sort, $offset, $limit, $translations ) { $query = $this->handler->createSelectQuery(); $query->selectDistinct( 'ezcontentobject.*', $this->handler->aliasedColumn( $query, 'main_node_id', 'main_tree' ) ); if ( $sort !== null ) { $this->sortClauseConverter->applySelect( $query, $sort ); } $query->from( $this->handler->quoteTable( 'ezcontentobject' ) )->innerJoin( 'ezcontentobject_version', 'ezcontentobject.id', 'ezcontentobject_version.contentobject_id' )->leftJoin( $this->handler->alias( $this->handler->quoteTable( 'ezcontentobject_tree' ), $this->handler->quoteIdentifier( 'main_tree' ) ), $query->expr->lAnd( $query->expr->eq( $this->handler->quoteColumn( "contentobject_id", "main_tree" ), $this->handler->quoteColumn( "id", "ezcontentobject" ) ), $query->expr->eq( $this->handler->quoteColumn( "main_node_id", "main_tree" ), $this->handler->quoteColumn( "node_id", "main_tree" ) ) ) ); if ( $sort !== null ) { $this->sortClauseConverter->applyJoin( $query, $sort ); } $query->where( $this->getQueryCondition( $filter, $query, $translations ) ); if ( $sort !== null ) { $this->sortClauseConverter->applyOrderBy( $query ); } $query->limit( $limit, $offset ); $statement = $query->prepare(); $statement->execute(); return $statement->fetchAll( \PDO::FETCH_ASSOC ); }
/** * 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 \eZ\Publish\Core\Persistence\Database\SelectQuery */ $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); }
/** * Returns total results count for $criterion and $sortClauses. * * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * * @return array */ protected function getTotalCount(Criterion $criterion) { $query = $this->handler->createSelectQuery(); $query->select($query->alias($query->expr->count('*'), 'count'))->from($this->handler->quoteTable('ezcontentobject_tree'))->innerJoin('ezcontentobject', 'ezcontentobject_tree.contentobject_id', 'ezcontentobject.id')->innerJoin('ezcontentobject_version', 'ezcontentobject.id', 'ezcontentobject_version.contentobject_id'); $query->where($this->criteriaConverter->convertCriteria($query, $criterion), $query->expr->eq('ezcontentobject.status', $query->bindValue(1, null, PDO::PARAM_INT)), $query->expr->eq('ezcontentobject_version.status', $query->bindValue(1, null, PDO::PARAM_INT)), $query->expr->neq($this->handler->quoteColumn('depth', 'ezcontentobject_tree'), $query->bindValue(0, null, PDO::PARAM_INT))); $statement = $query->prepare(); $statement->execute(); $res = $statement->fetchAll(PDO::FETCH_ASSOC); return (int) $res[0]['count']; }
/** * @param mixed[] $destinationContentIds * * @throws \Exception * * @return array */ protected function getRelationXmlHashFromDB(array $destinationContentIds) { if (empty($destinationContentIds)) { return array(); } $q = $this->db->createSelectQuery(); $q->select($this->db->aliasedColumn($q, 'id', 'ezcontentobject'), $this->db->aliasedColumn($q, 'remote_id', 'ezcontentobject'), $this->db->aliasedColumn($q, 'current_version', 'ezcontentobject'), $this->db->aliasedColumn($q, 'contentclass_id', 'ezcontentobject'), $this->db->aliasedColumn($q, 'node_id', 'ezcontentobject_tree'), $this->db->aliasedColumn($q, 'parent_node_id', 'ezcontentobject_tree'), $this->db->aliasedColumn($q, 'identifier', 'ezcontentclass'))->from($this->db->quoteTable('ezcontentobject'))->leftJoin($this->db->quoteTable('ezcontentobject_tree'), $q->expr->lAnd($q->expr->eq($this->db->quoteColumn('contentobject_id', 'ezcontentobject_tree'), $this->db->quoteColumn('id', 'ezcontentobject')), $q->expr->eq($this->db->quoteColumn('node_id', 'ezcontentobject_tree'), $this->db->quoteColumn('main_node_id', 'ezcontentobject_tree'))))->leftJoin($this->db->quoteTable('ezcontentclass'), $q->expr->lAnd($q->expr->eq($this->db->quoteColumn('id', 'ezcontentclass'), $this->db->quoteColumn('contentclass_id', 'ezcontentobject')), $q->expr->eq($this->db->quoteColumn('version', 'ezcontentclass'), $q->bindValue(ContentType::STATUS_DEFINED, null, PDO::PARAM_INT))))->where($q->expr->in($this->db->quoteColumn('id', 'ezcontentobject'), $destinationContentIds)); $stmt = $q->prepare(); $stmt->execute(); return $stmt->fetchAll(PDO::FETCH_ASSOC | PDO::FETCH_GROUP); }
/** * Loads all autogenerated entries with given $parentId with optionally included history entries. * * @param mixed $parentId * @param boolean $includeHistory * * @return array */ public function loadAutogeneratedEntries($parentId, $includeHistory = false) { /** @var $query \eZ\Publish\Core\Persistence\Database\SelectQuery */ $query = $this->dbHandler->createSelectQuery(); $query->select("*")->from($this->dbHandler->quoteTable("ezurlalias_ml"))->where($query->expr->lAnd($query->expr->eq($this->dbHandler->quoteColumn("parent"), $query->bindValue($parentId, null, \PDO::PARAM_INT)), $query->expr->eq($this->dbHandler->quoteColumn("action_type"), $query->bindValue("eznode", null, \PDO::PARAM_STR)), $query->expr->eq($this->dbHandler->quoteColumn("is_alias"), $query->bindValue(0, null, \PDO::PARAM_INT)))); if (!$includeHistory) { $query->where($query->expr->eq($this->dbHandler->quoteColumn("is_original"), $query->bindValue(1, null, \PDO::PARAM_INT))); } $statement = $query->prepare(); $statement->execute(); return $statement->fetchAll(\PDO::FETCH_ASSOC); }
/** * Get all words related to the content object (legacy db table: ezsearch_object_word_link). * * @param $contentId * * @return array */ public function getContentObjectWords($contentId) { $query = $this->dbHandler->createSelectQuery(); $this->setContentObjectWordsSelectQuery($query); $stmt = $query->prepare(); $stmt->execute(['contentId' => $contentId]); $wordIDList = []; while (false !== ($row = $stmt->fetch(PDO::FETCH_NUM))) { $wordIDList[] = $row[0]; } return $wordIDList; }
/** * 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; }
/** * Returns total results count for $criterion and $sortClauses. * * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion * @param array $languageFilter * * @return array */ protected function getTotalCount(Criterion $criterion, array $languageFilter) { $query = $this->handler->createSelectQuery(); $query->select($query->alias($query->expr->count('*'), 'count'))->from($this->handler->quoteTable('ezcontentobject_tree'))->innerJoin('ezcontentobject', 'ezcontentobject_tree.contentobject_id', 'ezcontentobject.id')->innerJoin('ezcontentobject_version', 'ezcontentobject.id', 'ezcontentobject_version.contentobject_id'); $query->where($this->criteriaConverter->convertCriteria($query, $criterion, $languageFilter), $query->expr->eq('ezcontentobject.status', $query->bindValue(1, null, PDO::PARAM_INT)), $query->expr->eq('ezcontentobject_version.status', $query->bindValue(1, null, PDO::PARAM_INT)), $query->expr->neq($this->handler->quoteColumn('depth', 'ezcontentobject_tree'), $query->bindValue(0, null, PDO::PARAM_INT))); // If not main-languages query if (!empty($languageFilter['languages'])) { $query->where($query->expr->gt($query->expr->bitAnd($this->handler->quoteColumn('language_mask', 'ezcontentobject'), $query->bindValue($this->getLanguageMask($languageFilter), null, PDO::PARAM_INT)), $query->bindValue(0, null, PDO::PARAM_INT))); } $statement = $query->prepare(); $statement->execute(); return (int) $statement->fetchColumn(); }
/** * Creates a select count query for tag objects. * * Creates a select query with all necessary joins to fetch a complete * tag. Does not apply any WHERE conditions. * * @param string[] $translations * @param bool $useAlwaysAvailable * * @return \eZ\Publish\Core\Persistence\Database\SelectQuery */ protected function createTagCountQuery(array $translations = null, $useAlwaysAvailable = true) { /** @var $query \eZ\Publish\Core\Persistence\Database\SelectQuery */ $query = $this->handler->createSelectQuery(); $query->select($query->alias($query->expr->count('DISTINCT eztags.id'), 'count'))->from($this->handler->quoteTable('eztags'))->leftJoin($this->handler->quoteTable('eztags_keyword'), $query->expr->lAnd($query->expr->eq($this->handler->quoteColumn('keyword_id', 'eztags_keyword'), $this->handler->quoteColumn('id', 'eztags')), $query->expr->eq($this->handler->quoteColumn('status', 'eztags_keyword'), $query->bindValue(1, null, PDO::PARAM_INT)))); if (!empty($translations)) { if ($useAlwaysAvailable) { $query->where($query->expr->lOr($query->expr->in($this->handler->quoteColumn('locale', 'eztags_keyword'), $translations), $query->expr->eq($this->handler->quoteColumn('main_language_id', 'eztags'), $query->expr->bitAnd($this->handler->quoteColumn('language_id', 'eztags_keyword'), -2)))); } else { $query->where($query->expr->in($this->handler->quoteColumn('locale', 'eztags_keyword'), $translations)); } } return $query; }
/** * @param mixed[] $destinationContentIds * * @throws \Exception * * @return array */ protected function getRelationXmlHashFromDB(array $destinationContentIds) { if (empty($destinationContentIds)) { return array(); } $q = $this->db->createSelectQuery(); $q->select($this->db->aliasedColumn($q, 'id', 'ezcontentobject'), $this->db->aliasedColumn($q, 'remote_id', 'ezcontentobject'), $this->db->aliasedColumn($q, 'current_version', 'ezcontentobject'), $this->db->aliasedColumn($q, 'contentclass_id', 'ezcontentobject'), $this->db->aliasedColumn($q, 'node_id', 'ezcontentobject_tree'), $this->db->aliasedColumn($q, 'parent_node_id', 'ezcontentobject_tree'), $this->db->aliasedColumn($q, 'identifier', 'ezcontentclass'))->from($this->db->quoteTable('ezcontentobject'))->leftJoin($this->db->quoteTable('ezcontentobject_tree'), $q->expr->lAnd($q->expr->eq($this->db->quoteColumn('contentobject_id', 'ezcontentobject_tree'), $this->db->quoteColumn('id', 'ezcontentobject')), $q->expr->eq($this->db->quoteColumn('node_id', 'ezcontentobject_tree'), $this->db->quoteColumn('main_node_id', 'ezcontentobject_tree'))))->leftJoin($this->db->quoteTable('ezcontentclass'), $q->expr->lAnd($q->expr->eq($this->db->quoteColumn('id', 'ezcontentclass'), $this->db->quoteColumn('contentclass_id', 'ezcontentobject')), $q->expr->eq($this->db->quoteColumn('version', 'ezcontentclass'), $q->bindValue(ContentType::STATUS_DEFINED, null, PDO::PARAM_INT))))->where($q->expr->in($this->db->quoteColumn('id', 'ezcontentobject'), $destinationContentIds)); $stmt = $q->prepare(); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC | PDO::FETCH_GROUP); if (empty($rows)) { throw new \Exception("Could find Content with id's" . var_export($destinationContentIds, true)); } elseif (count($rows) !== count($destinationContentIds)) { throw new \Exception('Miss match of rows & id count:' . var_export($destinationContentIds, true)); } return $rows; }
/** * Get sorted arrays of content IDs, which should be returned * * @param Criterion $filter * @param array $sort * @param mixed $offset * @param mixed $limit * @param mixed $translations * * @return int[] */ protected function getContentIds(Criterion $filter, $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($filter, $query, $translations)); if ($sort !== null) { $this->sortClauseConverter->applyOrderBy($query); } $query->limit($limit, $offset); $statement = $query->prepare(); $statement->execute(); return $statement->fetchAll(\PDO::FETCH_COLUMN); }
/** * Returns relevant field information for the specified field * * The returned information is returned as an array of the attribute * identifier and the sort column, which should be used. * * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If no searchable fields are found for the given $fieldIdentifier. * @throws \RuntimeException if no converter is found * * @caching * @param string $fieldIdentifier * * @return array */ protected function getFieldsInformation($fieldIdentifier) { $query = $this->dbHandler->createSelectQuery(); $query->select($this->dbHandler->quoteColumn('id', 'ezcontentclass_attribute'), $this->dbHandler->quoteColumn('data_type_string', 'ezcontentclass_attribute'))->from($this->dbHandler->quoteTable('ezcontentclass_attribute'))->where($query->expr->lAnd($query->expr->eq($this->dbHandler->quoteColumn('identifier', 'ezcontentclass_attribute'), $query->bindValue($fieldIdentifier)), $query->expr->eq($this->dbHandler->quoteColumn('is_searchable', 'ezcontentclass_attribute'), $query->bindValue(1, null, \PDO::PARAM_INT)))); $statement = $query->prepare(); $statement->execute(); if (!($rows = $statement->fetchAll(\PDO::FETCH_ASSOC))) { throw new InvalidArgumentException("\$criterion->target", "No searchable fields found for the given criterion target '{$fieldIdentifier}'."); } $fieldMapArray = array(); foreach ($rows as $row) { if (!isset($fieldMapArray[$row['data_type_string']])) { $converter = $this->fieldConverterRegistry->getConverter($row['data_type_string']); if (!$converter instanceof Converter) { throw new RuntimeException("getConverter({$row['data_type_string']}) did not return a converter, got: " . gettype($converter)); } $fieldMapArray[$row['data_type_string']] = array('ids' => array(), 'column' => $converter->getIndexColumn()); } $fieldMapArray[$row['data_type_string']]['ids'][] = $row['id']; } return $fieldMapArray; }
/** * @param $commentId * @param DatabaseHandler $connection * @return bool */ public function commentExists($commentId, DatabaseHandler $connection) { $selectQuery = $connection->createSelectQuery(); $selectQuery->select('*')->from($connection->quoteTable('ezcomment'))->where($selectQuery->expr->eq($connection->quoteColumn('id'), $selectQuery->bindValue($commentId, null, \PDO::PARAM_INT))); $statement = $selectQuery->prepare(); $statement->execute(); return $statement->rowCount() > 0 ? true : false; }
/** * Get content objects total count. * * @param \eZ\Publish\Core\Persistence\Database\DatabaseHandler $databaseHandler * @param int $contentObjectStatus ContentInfo constant * * @return int */ private function getContentObjectsTotalCount(DatabaseHandler $databaseHandler, $contentObjectStatus) { $query = $databaseHandler->createSelectQuery(); $query->select('count(id)')->from('ezcontentobject')->where($query->expr->eq('status', $contentObjectStatus)); $stmt = $query->prepare(); $stmt->execute(); $totalCount = $stmt->fetchColumn(); return $totalCount; }
/** * Creates a generalized query for fetching object state group(s) * * @return \eZ\Publish\Core\Persistence\Database\SelectQuery */ protected function createObjectStateGroupFindQuery() { $query = $this->dbHandler->createSelectQuery(); $query->select($this->dbHandler->aliasedColumn($query, 'default_language_id', 'ezcobj_state_group'), $this->dbHandler->aliasedColumn($query, 'id', 'ezcobj_state_group'), $this->dbHandler->aliasedColumn($query, 'identifier', 'ezcobj_state_group'), $this->dbHandler->aliasedColumn($query, 'language_mask', 'ezcobj_state_group'), $this->dbHandler->aliasedColumn($query, 'description', 'ezcobj_state_group_language'), $this->dbHandler->aliasedColumn($query, 'language_id', 'ezcobj_state_group_language'), $this->dbHandler->aliasedColumn($query, 'real_language_id', 'ezcobj_state_group_language'), $this->dbHandler->aliasedColumn($query, 'name', 'ezcobj_state_group_language'))->from($this->dbHandler->quoteTable('ezcobj_state_group'))->innerJoin($this->dbHandler->quoteTable('ezcobj_state_group_language'), $query->expr->eq($this->dbHandler->quoteColumn('id', 'ezcobj_state_group'), $this->dbHandler->quoteColumn('contentobject_state_group_id', 'ezcobj_state_group_language'))); return $query; }