createInsertQuery() public method

Create Insert Query object.
public createInsertQuery ( ) : eZ\Publish\Core\Persistence\Database\InsertQuery
return eZ\Publish\Core\Persistence\Database\InsertQuery
 /**
  * Inserts the given UrlWildcard.
  *
  * @param \eZ\Publish\SPI\Persistence\Content\UrlWildcard $urlWildcard
  *
  * @return mixed
  */
 public function insertUrlWildcard(UrlWildcard $urlWildcard)
 {
     /** @var $query \eZ\Publish\Core\Persistence\Database\InsertQuery */
     $query = $this->dbHandler->createInsertQuery();
     $query->insertInto($this->dbHandler->quoteTable('ezurlwildcard'))->set($this->dbHandler->quoteColumn('destination_url'), $query->bindValue(trim($urlWildcard->destinationUrl, '/ '), null, \PDO::PARAM_STR))->set($this->dbHandler->quoteColumn('id'), $this->dbHandler->getAutoIncrementValue('ezurlwildcard', 'id'))->set($this->dbHandler->quoteColumn('source_url'), $query->bindValue(trim($urlWildcard->sourceUrl, '/ '), null, \PDO::PARAM_STR))->set($this->dbHandler->quoteColumn('type'), $query->bindValue($urlWildcard->forward ? 1 : 2, null, \PDO::PARAM_INT));
     $query->prepare()->execute();
     return $this->dbHandler->lastInsertId($this->dbHandler->getSequenceName('ezurlwildcard', 'id'));
 }
 /**
  * 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'));
 }
 /**
  * Assigns role to user with given limitation
  *
  * @param mixed $contentId
  * @param mixed $roleId
  * @param array $limitation
  */
 public function assignRole( $contentId, $roleId, array $limitation )
 {
     foreach ( $limitation as $identifier => $values )
     {
         foreach ( $values as $value )
         {
             $query = $this->handler->createInsertQuery();
             $query
                 ->insertInto( $this->handler->quoteTable( 'ezuser_role' ) )
                 ->set(
                     $this->handler->quoteColumn( 'contentobject_id' ),
                     $query->bindValue( $contentId, null, \PDO::PARAM_INT )
                 )->set(
                     $this->handler->quoteColumn( 'role_id' ),
                     $query->bindValue( $roleId, null, \PDO::PARAM_INT )
                 )->set(
                     $this->handler->quoteColumn( 'limit_identifier' ),
                     $query->bindValue( $identifier )
                 )->set(
                     $this->handler->quoteColumn( 'limit_value' ),
                     $query->bindValue( $value )
                 );
             $query->prepare()->execute();
         }
     }
 }
Example #4
0
 /**
  * Inserts keywords for tag with provided tag ID.
  *
  * @param mixed $tagId
  * @param array $keywords
  * @param string $mainLanguageCode
  * @param bool $alwaysAvailable
  */
 protected function insertTagKeywords($tagId, array $keywords, $mainLanguageCode, $alwaysAvailable)
 {
     foreach ($keywords as $languageCode => $keyword) {
         $query = $this->handler->createInsertQuery();
         $query->insertInto($this->handler->quoteTable('eztags_keyword'))->set($this->handler->quoteColumn('keyword_id'), $query->bindValue($tagId, null, PDO::PARAM_INT))->set($this->handler->quoteColumn('language_id'), $query->bindValue($this->languageHandler->loadByLanguageCode($languageCode)->id + (int) ($languageCode === $mainLanguageCode && $alwaysAvailable), null, PDO::PARAM_INT))->set($this->handler->quoteColumn('keyword'), $query->bindValue($keyword, null, PDO::PARAM_STR))->set($this->handler->quoteColumn('locale'), $query->bindValue($languageCode, null, PDO::PARAM_STR))->set($this->handler->quoteColumn('status'), $query->bindValue(1, null, PDO::PARAM_INT));
         $query->prepare()->execute();
     }
 }
 /**
  * Inserts object state group translations into database
  *
  * @param \eZ\Publish\SPI\Persistence\Content\ObjectState\Group $objectStateGroup
  */
 protected function insertObjectStateGroupTranslations(Group $objectStateGroup)
 {
     foreach ($objectStateGroup->languageCodes as $languageCode) {
         $languageId = $this->maskGenerator->generateLanguageIndicator($languageCode, $languageCode === $objectStateGroup->defaultLanguage);
         $query = $this->dbHandler->createInsertQuery();
         $query->insertInto($this->dbHandler->quoteTable('ezcobj_state_group_language'))->set($this->dbHandler->quoteColumn('contentobject_state_group_id'), $query->bindValue($objectStateGroup->id, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('description'), $query->bindValue($objectStateGroup->description[$languageCode]))->set($this->dbHandler->quoteColumn('name'), $query->bindValue($objectStateGroup->name[$languageCode]))->set($this->dbHandler->quoteColumn('language_id'), $query->bindValue($languageId, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('real_language_id'), $query->bindValue($languageId & ~1, null, \PDO::PARAM_INT));
         $query->prepare()->execute();
     }
 }
 /**
  * Link word with specific content object (legacy db table: ezsearch_object_word_link).
  *
  * @param $wordId
  * @param $contentId
  * @param $frequency
  * @param $placement
  * @param $nextWordId
  * @param $prevWordId
  * @param $contentTypeId
  * @param $fieldTypeId
  * @param $published
  * @param $sectionId
  * @param $identifier
  * @param $integerValue
  */
 public function addObjectWordLink($wordId, $contentId, $frequency, $placement, $nextWordId, $prevWordId, $contentTypeId, $fieldTypeId, $published, $sectionId, $identifier, $integerValue)
 {
     $assoc = ['word_id' => $wordId, 'contentobject_id' => $contentId, 'frequency' => $frequency, 'placement' => $placement, 'next_word_id' => $nextWordId, 'prev_word_id' => $prevWordId, 'contentclass_id' => $contentTypeId, 'contentclass_attribute_id' => $fieldTypeId, 'published' => $published, 'section_id' => $sectionId, 'identifier' => $identifier, 'integer_value' => $integerValue];
     $query = $this->dbHandler->createInsertQuery();
     $query->insertInto('ezsearch_object_word_link');
     foreach ($assoc as $column => $value) {
         $query->set($this->dbHandler->quoteColumn($column), $query->bindValue($value));
     }
     $stmt = $query->prepare();
     $stmt->execute();
 }
 /**
  * Inserts a $fieldDefinition for $typeId.
  *
  * @param mixed $typeId
  * @param int $status
  * @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDefinition
  * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageFieldDef
  *
  * @return mixed Field definition ID
  */
 public function insertFieldDefinition($typeId, $status, FieldDefinition $fieldDefinition, StorageFieldDefinition $storageFieldDef)
 {
     $q = $this->dbHandler->createInsertQuery();
     $q->insertInto($this->dbHandler->quoteTable('ezcontentclass_attribute'));
     $q->set($this->dbHandler->quoteColumn('id'), isset($fieldDefinition->id) ? $q->bindValue($fieldDefinition->id, null, \PDO::PARAM_INT) : $this->dbHandler->getAutoIncrementValue('ezcontentclass_attribute', 'id'))->set($this->dbHandler->quoteColumn('contentclass_id'), $q->bindValue($typeId, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('version'), $q->bindValue($status, null, \PDO::PARAM_INT));
     $this->setCommonFieldColumns($q, $fieldDefinition, $storageFieldDef);
     $q->prepare()->execute();
     if (!isset($fieldDefinition->id)) {
         return $this->dbHandler->lastInsertId($this->dbHandler->getSequenceName('ezcontentclass_attribute', 'id'));
     }
     return $fieldDefinition->id;
 }
 /**
  * Sends a single location identified by given $locationId to the trash.
  *
  * The associated content object is left untouched.
  *
  * @param mixed $locationId
  *
  * @return bool
  */
 public function trashLocation($locationId)
 {
     $locationRow = $this->getBasicNodeData($locationId);
     /** @var $query \eZ\Publish\Core\Persistence\Database\InsertQuery */
     $query = $this->handler->createInsertQuery();
     $query->insertInto($this->handler->quoteTable('ezcontentobject_trash'));
     unset($locationRow['contentobject_is_published']);
     foreach ($locationRow as $key => $value) {
         $query->set($key, $query->bindValue($value));
     }
     $query->prepare()->execute();
     $this->removeLocation($locationRow['node_id']);
     $this->setContentStatus($locationRow['contentobject_id'], ContentInfo::STATUS_ARCHIVED);
 }
 /**
  * Adds limitations to an existing policy.
  *
  * @param int $policyId
  * @param array $limitations
  */
 public function addPolicyLimitations($policyId, array $limitations)
 {
     foreach ($limitations as $identifier => $values) {
         $query = $this->handler->createInsertQuery();
         $query->insertInto($this->handler->quoteTable('ezpolicy_limitation'))->set($this->handler->quoteColumn('id'), $this->handler->getAutoIncrementValue('ezpolicy_limitation', 'id'))->set($this->handler->quoteColumn('identifier'), $query->bindValue($identifier))->set($this->handler->quoteColumn('policy_id'), $query->bindValue($policyId, null, \PDO::PARAM_INT));
         $query->prepare()->execute();
         $limitationId = $this->handler->lastInsertId($this->handler->getSequenceName('ezpolicy_limitation', 'id'));
         foreach ($values as $value) {
             $query = $this->handler->createInsertQuery();
             $query->insertInto($this->handler->quoteTable('ezpolicy_limitation_value'))->set($this->handler->quoteColumn('id'), $this->handler->getAutoIncrementValue('ezpolicy_limitation_value', 'id'))->set($this->handler->quoteColumn('value'), $query->bindValue($value))->set($this->handler->quoteColumn('limitation_id'), $query->bindValue($limitationId, null, \PDO::PARAM_INT));
             $query->prepare()->execute();
         }
     }
 }
 /**
  * Returns next value for "id" column.
  *
  * @return mixed
  */
 public function getNextId()
 {
     $sequence = $this->dbHandler->getSequenceName('ezurlalias_ml_incr', 'id');
     /** @var $query \eZ\Publish\Core\Persistence\Database\InsertQuery */
     $query = $this->dbHandler->createInsertQuery();
     $query->insertInto($this->dbHandler->quoteTable("ezurlalias_ml_incr"));
     // ezcDatabase does not abstract the "auto increment id"
     // INSERT INTO ezurlalias_ml_incr VALUES(DEFAULT) is not an option due
     // to this mysql bug: http://bugs.mysql.com/bug.php?id=42270
     // as a result we are forced to check which database is currently used
     // to generate the correct SQL query
     // see https://jira.ez.no/browse/EZP-20652
     if ($this->dbHandler->useSequences()) {
         $query->set($this->dbHandler->quoteColumn("id"), "nextval('{$sequence}')");
     } else {
         $query->set($this->dbHandler->quoteColumn("id"), $query->bindValue(null, null, \PDO::PARAM_NULL));
     }
     $query->prepare()->execute();
     return $this->dbHandler->lastInsertId($sequence);
 }