eZ\Publish\Core\Persistence\Legacy\Content\ObjectState\Gateway\DoctrineDatabase::insertObjectState PHP Method

insertObjectState() public method

Inserts a new object state into database.
public insertObjectState ( eZ\Publish\SPI\Persistence\Content\ObjectState $objectState, integer $groupId )
$objectState eZ\Publish\SPI\Persistence\Content\ObjectState
$groupId integer
    public function insertObjectState(ObjectState $objectState, $groupId)
    {
        $query = $this->dbHandler->createSelectQuery();
        $query->select($query->expr->max($this->dbHandler->quoteColumn('priority')))->from($this->dbHandler->quoteTable('ezcobj_state'))->where($query->expr->eq($this->dbHandler->quoteColumn('group_id'), $query->bindValue($groupId, null, \PDO::PARAM_INT)));
        $statement = $query->prepare();
        $statement->execute();
        $maxPriority = $statement->fetchColumn();
        $objectState->priority = $maxPriority === null ? 0 : (int) $maxPriority + 1;
        $objectState->groupId = (int) $groupId;
        $query = $this->dbHandler->createInsertQuery();
        $query->insertInto($this->dbHandler->quoteTable('ezcobj_state'))->set($this->dbHandler->quoteColumn('id'), $this->dbHandler->getAutoIncrementValue('ezcobj_state', 'id'))->set($this->dbHandler->quoteColumn('group_id'), $query->bindValue($objectState->groupId, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('default_language_id'), $query->bindValue($this->maskGenerator->generateLanguageIndicator($objectState->defaultLanguage, false), null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('identifier'), $query->bindValue($objectState->identifier))->set($this->dbHandler->quoteColumn('language_mask'), $query->bindValue($this->generateLanguageMask($objectState->languageCodes), null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('priority'), $query->bindValue($objectState->priority, null, \PDO::PARAM_INT));
        $query->prepare()->execute();
        $objectState->id = (int) $this->dbHandler->lastInsertId($this->dbHandler->getSequenceName('ezcobj_state', 'id'));
        $this->insertObjectStateTranslations($objectState);
        // If this is a first state in group, assign it to all content objects
        if ($maxPriority === null) {
            // @todo Hm... How do we perform this with query object?
            $this->dbHandler->prepare("INSERT INTO ezcobj_state_link (contentobject_id, contentobject_state_id)\n                SELECT id, {$objectState->id} FROM ezcontentobject")->execute();
        }
    }