/** * 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 } } }
/** * Changes main location of content identified by given $contentId to location identified by given $locationId * * Updates ezcontentobject_tree table for the given $contentId and eznode_assignment table for the given * $contentId, $parentLocationId and $versionNo * * @param mixed $contentId * @param mixed $locationId * @param mixed $versionNo version number, needed to update eznode_assignment table * @param mixed $parentLocationId parent location of location identified by $locationId, needed to update * eznode_assignment table * * @return void */ public function changeMainLocation($contentId, $locationId, $versionNo, $parentLocationId) { // Update ezcontentobject_tree table $q = $this->handler->createUpdateQuery(); $q->update($this->handler->quoteTable("ezcontentobject_tree"))->set($this->handler->quoteColumn("main_node_id"), $q->bindValue($locationId, null, \PDO::PARAM_INT))->where($q->expr->eq($this->handler->quoteColumn("contentobject_id"), $q->bindValue($contentId, null, \PDO::PARAM_INT))); $q->prepare()->execute(); // Erase is_main in eznode_assignment table $q = $this->handler->createUpdateQuery(); $q->update($this->handler->quoteTable("eznode_assignment"))->set($this->handler->quoteColumn("is_main"), $q->bindValue(0, null, \PDO::PARAM_INT))->where($q->expr->lAnd($q->expr->eq($this->handler->quoteColumn("contentobject_id"), $q->bindValue($contentId, null, \PDO::PARAM_INT)), $q->expr->eq($this->handler->quoteColumn("contentobject_version"), $q->bindValue($versionNo, null, \PDO::PARAM_INT)), $q->expr->neq($this->handler->quoteColumn("parent_node"), $q->bindValue($parentLocationId, null, \PDO::PARAM_INT)))); $q->prepare()->execute(); // Set new is_main in eznode_assignment table $q = $this->handler->createUpdateQuery(); $q->update($this->handler->quoteTable("eznode_assignment"))->set($this->handler->quoteColumn("is_main"), $q->bindValue(1, null, \PDO::PARAM_INT))->where($q->expr->lAnd($q->expr->eq($this->handler->quoteColumn("contentobject_id"), $q->bindValue($contentId, null, \PDO::PARAM_INT)), $q->expr->eq($this->handler->quoteColumn("contentobject_version"), $q->bindValue($versionNo, null, \PDO::PARAM_INT)), $q->expr->eq($this->handler->quoteColumn("parent_node"), $q->bindValue($parentLocationId, null, \PDO::PARAM_INT)))); $q->prepare()->execute(); }