/** * Update current node-type using a new one. * * Update diff will update only non-critical fields such as : * * * description * * displayName * * It will only create absent node-type fields won't delete fields * not to lose any data. * * This method does not flush ORM. You'll need to manually call it. * * @param RZ\Roadiz\Core\Entities\NodeType $newNodeType * * @throws \RuntimeException If newNodeType param is null */ public function diff(NodeType $newNodeType) { if (null !== $newNodeType) { /* * options */ if ("" != $newNodeType->getDisplayName()) { $this->nodeType->setDisplayName($newNodeType->getDisplayName()); } if ("" != $newNodeType->getDescription()) { $this->nodeType->setDescription($newNodeType->getDescription()); } /* * make fields diff */ $existingFieldsNames = $this->nodeType->getFieldsNames(); foreach ($newNodeType->getFields() as $newField) { if (false === in_array($newField->getName(), $existingFieldsNames)) { /* * Field does not exist in type, * creating it. */ $newField->setNodeType($this->nodeType); Kernel::getService('em')->persist($newField); } } } else { throw new \RuntimeException("New node-type is null", 1); } }