/** * Inserts a new relation database record * * @param \eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct $createStruct * * @return int ID the inserted ID */ public function insertRelation(RelationCreateStruct $createStruct) { $q = $this->dbHandler->createInsertQuery(); $q->insertInto($this->dbHandler->quoteTable('ezcontentobject_link'))->set($this->dbHandler->quoteColumn('id'), $this->dbHandler->getAutoIncrementValue('ezcontentobject_link', 'id'))->set($this->dbHandler->quoteColumn('contentclassattribute_id'), $q->bindValue((int) $createStruct->sourceFieldDefinitionId, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('from_contentobject_id'), $q->bindValue($createStruct->sourceContentId, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('from_contentobject_version'), $q->bindValue($createStruct->sourceContentVersionNo, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('relation_type'), $q->bindValue($createStruct->type, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('to_contentobject_id'), $q->bindValue($createStruct->destinationContentId, null, \PDO::PARAM_INT)); $q->prepare()->execute(); return $this->dbHandler->lastInsertId($this->dbHandler->getSequenceName('ezcontentobject_link', 'id')); }
/** * Creates a new location in given $parentNode * * @param \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct $createStruct * @param array $parentNode * * @return \eZ\Publish\SPI\Persistence\Content\Location */ public function create(CreateStruct $createStruct, array $parentNode) { $location = new Location(); /** @var $query \ezcQueryInsert */ $query = $this->handler->createInsertQuery(); $query->insertInto($this->handler->quoteTable('ezcontentobject_tree'))->set($this->handler->quoteColumn('contentobject_id'), $query->bindValue($location->contentId = $createStruct->contentId, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('contentobject_is_published'), $query->bindValue(1, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('contentobject_version'), $query->bindValue($createStruct->contentVersion, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('depth'), $query->bindValue($location->depth = $parentNode['depth'] + 1, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('is_hidden'), $query->bindValue($location->hidden = $createStruct->hidden, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('is_invisible'), $query->bindValue($location->invisible = $createStruct->invisible, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('modified_subnode'), $query->bindValue(time(), null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('node_id'), $this->handler->getAutoIncrementValue('ezcontentobject_tree', 'node_id'))->set($this->handler->quoteColumn('parent_node_id'), $query->bindValue($location->parentId = $parentNode['node_id'], null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('path_identification_string'), $query->bindValue($location->pathIdentificationString = $createStruct->pathIdentificationString, null, \PDO::PARAM_STR))->set($this->handler->quoteColumn('path_string'), $query->bindValue('dummy'))->set($this->handler->quoteColumn('priority'), $query->bindValue($location->priority = $createStruct->priority, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('remote_id'), $query->bindValue($location->remoteId = $createStruct->remoteId, null, \PDO::PARAM_STR))->set($this->handler->quoteColumn('sort_field'), $query->bindValue($location->sortField = $createStruct->sortField, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('sort_order'), $query->bindValue($location->sortOrder = $createStruct->sortOrder, null, \PDO::PARAM_INT)); $query->prepare()->execute(); $location->id = $this->handler->lastInsertId($this->handler->getSequenceName('ezcontentobject_tree', 'node_id')); $mainLocationId = $createStruct->mainLocationId === true ? $location->id : $createStruct->mainLocationId; $location->pathString = $parentNode['path_string'] . $location->id . '/'; /** @var $query \ezcQueryUpdate */ $query = $this->handler->createUpdateQuery(); $query->update($this->handler->quoteTable('ezcontentobject_tree'))->set($this->handler->quoteColumn('path_string'), $query->bindValue($location->pathString))->set($this->handler->quoteColumn('main_node_id'), $query->bindValue($mainLocationId, null, \PDO::PARAM_INT))->where($query->expr->eq($this->handler->quoteColumn('node_id'), $query->bindValue($location->id, null, \PDO::PARAM_INT))); $query->prepare()->execute(); return $location; }