/**
  * Applies the action to the given $content.
  *
  * @param int $contentId
  */
 public function apply($contentId)
 {
     $versionNumbers = $this->contentGateway->listVersionNumbers($contentId);
     $fieldIdSet = array();
     $nameRows = $this->contentGateway->loadVersionedNameData(array_map(function ($versionNo) use($contentId) {
         return array('id' => $contentId, 'version' => $versionNo);
     }, $versionNumbers));
     foreach ($versionNumbers as $versionNo) {
         $contentRows = $this->contentGateway->load($contentId, $versionNo);
         $contentList = $this->contentMapper->extractContentFromRows($contentRows, $nameRows);
         $content = $contentList[0];
         $versionFieldIdSet = array();
         foreach ($content->fields as $field) {
             if ($field->fieldDefinitionId == $this->fieldDefinition->id) {
                 $fieldIdSet[$field->id] = true;
                 $versionFieldIdSet[$field->id] = true;
             }
         }
         // Delete from external storage with list of IDs per version
         $this->storageHandler->deleteFieldData($this->fieldDefinition->fieldType, $content->versionInfo, array_keys($versionFieldIdSet));
     }
     // Delete from internal storage -- field is always deleted from _all_ versions
     foreach (array_keys($fieldIdSet) as $fieldId) {
         $this->contentGateway->deleteField($fieldId);
     }
 }
 /**
  * Applies the action to the given $content
  *
  * @param \eZ\Publish\SPI\Persistence\Content $content
  *
  * @return void
  */
 public function apply(Content $content)
 {
     $fieldIdsToRemoveMap = array();
     foreach ($content->fields as $field) {
         if ($field->fieldDefinitionId == $this->fieldDefinition->id) {
             $this->contentGateway->deleteField($field->id);
             $fieldIdsToRemoveMap[$field->type][] = $field->id;
         }
     }
     foreach ($fieldIdsToRemoveMap as $fieldType => $ids) {
         $this->storageHandler->deleteFieldData($fieldType, $content->versionInfo, $ids);
     }
 }
 /**
  * Deletes the fields for $contentId in $versionInfo from the database
  *
  * @param int $contentId
  * @param \eZ\Publish\SPI\Persistence\Content\VersionInfo $versionInfo
  *
  * @return void
  */
 public function deleteFields($contentId, VersionInfo $versionInfo)
 {
     foreach ($this->contentGateway->getFieldIdsByType($contentId, $versionInfo->versionNo) as $fieldType => $ids) {
         $this->storageHandler->deleteFieldData($fieldType, $versionInfo, $ids);
     }
     $this->contentGateway->deleteFields($contentId, $versionInfo->versionNo);
 }
Example #4
0
 /**
  * Applies the action to the given $content
  *
  * @param \eZ\Publish\SPI\Persistence\Content\ContentInfo $contentInfo
  *
  * @return void
  */
 public function apply(ContentInfo $contentInfo)
 {
     $fieldIdsToRemoveMap = array();
     $contentRows = $this->contentGateway->load($contentInfo->id, $contentInfo->currentVersionNo);
     $contentList = $this->contentMapper->extractContentFromRows($contentRows);
     $content = $contentList[0];
     foreach ($content->fields as $field) {
         if ($field->fieldDefinitionId == $this->fieldDefinition->id) {
             $this->contentGateway->deleteField($field->id);
             $fieldIdsToRemoveMap[$field->type][] = $field->id;
         }
     }
     foreach ($fieldIdsToRemoveMap as $fieldType => $ids) {
         $this->storageHandler->deleteFieldData($fieldType, $content->versionInfo, $ids);
     }
 }
Example #5
0
 /**
  * Inserts given $field and appends it to the given $content field collection.
  *
  * @param \eZ\Publish\SPI\Persistence\Content $content
  * @param \eZ\Publish\SPI\Persistence\Content\Field $field
  *
  * @return void
  */
 protected function insertField(Content $content, Field $field)
 {
     $storageValue = new StorageFieldValue();
     $this->fieldValueConverter->toStorageValue($field->value, $storageValue);
     $field->id = $this->contentGateway->insertNewField($content, $field, $storageValue);
     // If the storage handler returns true, it means that $field value has been modified
     // So we need to update it in order to store those modifications
     // Field converter is called once again via the Mapper
     if ($this->storageHandler->storeFieldData($content->versionInfo, $field) === true) {
         $storageValue = new StorageFieldValue();
         $this->fieldValueConverter->toStorageValue($field->value, $storageValue);
         if ($this->fieldDefinition->isTranslatable) {
             $this->contentGateway->updateField($field, $storageValue);
         } else {
             $this->contentGateway->updateNonTranslatableField($field, $storageValue, $content->versionInfo->contentInfo->id);
         }
     }
     $content->fields[] = $field;
 }
Example #6
0
 /**
  * Inserts given $field to the internal and external storage.
  *
  * If $field->id is null, creating new field id will be created.
  * Otherwise it will be inserted for the given $content version, reusing existing Field id.
  *
  * @param \eZ\Publish\SPI\Persistence\Content $content
  * @param \eZ\Publish\SPI\Persistence\Content\Field $field
  *
  * @return int The ID of the field that was inserted
  */
 protected function insertField(Content $content, Field $field)
 {
     $storageValue = new StorageFieldValue();
     $this->fieldValueConverter->toStorageValue($field->value, $storageValue);
     if (isset($field->id)) {
         // Insert with existing Field id and given Content version number
         $this->contentGateway->insertExistingField($content, $field, $storageValue);
     } else {
         // Insert with creating new Field id and given Content version number
         $field->id = $this->contentGateway->insertNewField($content, $field, $storageValue);
     }
     // If the storage handler returns true, it means that $field value has been modified
     // So we need to update it in order to store those modifications
     // Field converter is called once again via the Mapper
     if ($this->storageHandler->storeFieldData($content->versionInfo, $field) === true) {
         $storageValue = new StorageFieldValue();
         $this->fieldValueConverter->toStorageValue($field->value, $storageValue);
         $this->contentGateway->updateField($field, $storageValue);
     }
     return $field->id;
 }