/**
* 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}
*/
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();
} elseif ($loadedRelationType & $type) {
// If relation type is composite update bitmask
/** @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
}
}