/**
  * Updates a field
  *
  * @param ORM\UnitOfWork $uow
  * @param mixed $object
  * @param ORM\Mapping\ClassMetadata $classMetadata
  * @param string $field
  */
 private function updateField(ORM\UnitOfWork $uow, $object, ORM\Mapping\ClassMetadata $classMetadata, $field)
 {
     $property = $classMetadata->getReflectionProperty($field);
     $oldValue = $property->getValue($object);
     $newValue = $this->getDateValue($classMetadata, $field);
     $property->setValue($object, $newValue);
     $uow->propertyChanged($object, $field, $oldValue, $newValue);
     $uow->scheduleExtraUpdate($object, [$field => [$oldValue, $newValue]]);
 }
Ejemplo n.º 2
0
 /**
  * @param DoctrineClassMetadata $entityMeta
  * @param object                $entity
  *
  * @return array [entityIdentifier => entity, ...]
  */
 protected function calculateManyToOneData(DoctrineClassMetadata $entityMeta, $entity)
 {
     $entities = [];
     foreach ($entityMeta->associationMappings as $assoc) {
         if ($assoc['type'] !== DoctrineClassMetadata::MANY_TO_ONE || empty($assoc['inversedBy'])) {
             continue;
         }
         $owner = $entityMeta->getReflectionProperty($assoc['fieldName'])->getValue($entity);
         if (!$owner) {
             continue;
         }
         $ownerMeta = $this->em->getClassMetadata($assoc['targetEntity']);
         $collection = $ownerMeta->getReflectionProperty($assoc['inversedBy'])->getValue($owner);
         if (!$collection instanceof PersistentCollection) {
             continue;
         }
         $entityIdentifier = $this->getEntityIdentifierString($owner);
         $this->calculateCollectionData($collection, $entityIdentifier);
         $entities[$entityIdentifier] = $owner;
     }
     return $entities;
 }
Ejemplo n.º 3
0
 /**
  * @param DoctrineClassMetadata $entityMeta
  * @param object $entity
  */
 protected function calculateManyToOneData(DoctrineClassMetadata $entityMeta, $entity)
 {
     $requiredProperties = array_flip(['type', 'fieldName', 'targetEntity', 'inversedBy']);
     foreach ($entityMeta->associationMappings as $assoc) {
         if (count($requiredProperties) !== count(array_filter(array_intersect_key($assoc, $requiredProperties)))) {
             continue;
         }
         if ($assoc['type'] !== DoctrineClassMetadata::MANY_TO_ONE) {
             continue;
         }
         $owner = $entityMeta->getReflectionProperty($assoc['fieldName'])->getValue($entity);
         if (!$owner) {
             continue;
         }
         $ownerMeta = $this->em->getClassMetadata($assoc['targetEntity']);
         $collection = $ownerMeta->getReflectionProperty($assoc['inversedBy'])->getValue($owner);
         if (!$collection instanceof PersistentCollection) {
             continue;
         }
         $entityIdentifier = $this->getEntityIdentifierString($owner);
         $this->calculateCollectionData($collection, $entityIdentifier);
         $this->updatedEntities[$entityIdentifier] = $owner;
     }
 }
 /**
  * @param $entity
  * @param string $method
  * @param array $column
  * @param ClassMetadata $meta
  */
 protected function handleField($entity, $method, array $column, $meta)
 {
     $field = $column['field'];
     $oid = spl_object_hash($entity);
     $reflProp = $meta->getReflectionProperty($field);
     $oldValue = $this->getEntityValue($reflProp, $entity);
     $newValue = $this->getNewValue($oid, $field, $column['name'], $method, $oldValue);
     $reflProp->setValue($entity, $newValue);
     if ($method === self::FUNCTION_REVERSE_TRANSFORM) {
         $this->storeOriginalFieldData($oid, $field, $oldValue, $newValue);
     }
 }
 /**
  * Save the tree hierarchy for the specified node.
  *
  * @param EntityManager $entityManager
  * @param object $entity The node to save the tree for.
  * @param ClassMetadata $nodeMetadata
  * @param object|null $parent The parent entity (or null to get it from the entity itself).
  */
 protected function saveNodeTree(EntityManager $entityManager, $entity, ClassMetadata $nodeMetadata, $parent = null)
 {
     $nodeClass = get_class($entity);
     $treeClass = $nodeMetadata->closureTree['treeEntity'];
     // Get metadata
     $treeMetadata = $entityManager->getClassMetadata($treeClass);
     // Get the table name
     $tableName = $treeMetadata->getTableName();
     $idColumn = $nodeMetadata->getSingleIdentifierFieldName();
     $ancestorColumn = $treeMetadata->closureTree['ancestor']['fieldName'];
     $descendantColumn = $treeMetadata->closureTree['descendant']['fieldName'];
     if ($treeMetadata->closureTree['depth']) {
         $depthColumn = $treeMetadata->closureTree['depth']['fieldName'];
     } else {
         $depthColumn = null;
     }
     $nodeId = $nodeMetadata->getReflectionProperty($idColumn)->getValue($entity);
     $parent = $parent ?: $entity->getParent();
     // Check if the entity has a parent
     if ($parent) {
         // Get the parent ID
         $parentId = $parent->getId();
         // Format the query to insert the tree hierarchy
         $query = 'INSERT INTO ' . $tableName . ' (' . $ancestorColumn . ', ' . $descendantColumn;
         if ($depthColumn) {
             $query .= ', ' . $depthColumn;
         }
         $query .= ') SELECT ' . $ancestorColumn . ', ' . $nodeId . ' ';
         if ($depthColumn) {
             $query .= ', (' . $depthColumn . ' + 1) ';
         }
         $query .= 'FROM ' . $tableName . ' ';
         $query .= 'WHERE ' . $descendantColumn . ' = ? ';
         $query .= 'UNION ALL SELECT ' . $nodeId . ', ' . $nodeId;
         if ($depthColumn) {
             $query .= ', 0';
         }
         // Set the query parameters
         $queryParams = array($parentId);
     } else {
         // Format the query to insert the tree hierarchy
         $query = 'INSERT INTO ' . $tableName . ' ';
         $query .= '(' . $ancestorColumn . ', ' . $descendantColumn;
         if ($depthColumn) {
             $query .= ', ' . $depthColumn;
         }
         $query .= ') VALUES (?, ?';
         if ($depthColumn) {
             $query .= ', 0';
         }
         $query .= ')';
         // Set the query parameters
         $queryParams = array($nodeId, $nodeId);
     }
     // Execute the query and close the cursor
     $entityManager->getConnection()->executeQuery($query, $queryParams)->closeCursor();
 }
Ejemplo n.º 6
0
 public function allowPersist(ClassMetadata $cm, $field)
 {
     $groupsAnnotation = $this->reader->getPropertyAnnotation($cm->getReflectionProperty($field), 'Symfony\\Component\\Serializer\\Annotation\\Groups');
     if ($groupsAnnotation !== null) {
         if (in_array("readonly", $groupsAnnotation->getGroups())) {
             return false;
         }
     }
     return true;
 }