/** * 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 \ezcQuerySelect */ public function createVersionInfoFindQuery() { /** @var $query \ezcQuerySelect */ $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('contentobject_version', 'ezcontentobject_tree'), $this->dbHandler->quoteColumn('version', '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; }
/** * 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 \ezcQuerySelect */ $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 \ezcQueryDelete */ $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 \ezcQueryUpdate */ $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 } } }
/** * 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']; }