eZ\Publish\Core\Persistence\Legacy\Content\Type\ContentUpdater::determineActions PHP Method

determineActions() public method

Determines the necessary update actions.
public determineActions ( eZ\Publish\SPI\Persistence\Content\Type $fromType, eZ\Publish\SPI\Persistence\Content\Type $toType ) : Action[]
$fromType eZ\Publish\SPI\Persistence\Content\Type
$toType eZ\Publish\SPI\Persistence\Content\Type
return eZ\Publish\Core\Persistence\Legacy\Content\Type\ContentUpdater\Action[]
    public function determineActions(Type $fromType, Type $toType)
    {
        $actions = array();
        foreach ($fromType->fieldDefinitions as $fieldDef) {
            if (!$this->hasFieldDefinition($toType, $fieldDef)) {
                $actions[] = new ContentUpdater\Action\RemoveField($this->contentGateway, $fieldDef, $this->storageHandler, $this->contentMapper);
            }
        }
        foreach ($toType->fieldDefinitions as $fieldDef) {
            if (!$this->hasFieldDefinition($fromType, $fieldDef)) {
                $actions[] = new ContentUpdater\Action\AddField($this->contentGateway, $fieldDef, $this->converterRegistry->getConverter($fieldDef->fieldType), $this->storageHandler, $this->contentMapper);
            }
        }
        return $actions;
    }

Usage Example

 /**
  * Updates existing content objects from $fromType to $toType
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Type $fromType
  * @param \eZ\Publish\SPI\Persistence\Content\Type $toType
  *
  * @return void
  */
 public function updateContentObjects(Type $fromType, Type $toType)
 {
     $this->contentUpdater->applyUpdates($fromType->id, $this->contentUpdater->determineActions($fromType, $toType));
 }