public function testMetadata()
 {
     $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\SoftDeleteable');
     $config = $this->softDeleteable->getConfiguration($this->em, $meta->name);
     $this->assertArrayHasKey('softDeleteable', $config);
     $this->assertTrue($config['softDeleteable']);
     $this->assertArrayHasKey('fieldName', $config);
     $this->assertEquals('deletedAt', $config['fieldName']);
 }
 public function testTreeMetadata()
 {
     $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\ClosureTree');
     $config = $this->tree->getConfiguration($this->em, $meta->name);
     $this->assertArrayHasKey('strategy', $config);
     $this->assertEquals('closure', $config['strategy']);
     $this->assertArrayHasKey('closure', $config);
     $this->assertEquals('Mapping\\Fixture\\ClosureTreeClosure', $config['closure']);
     $this->assertArrayHasKey('parent', $config);
     $this->assertEquals('parent', $config['parent']);
 }
 public function testSluggableMetadata()
 {
     $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\Sortable');
     $config = $this->sortable->getConfiguration($this->em, $meta->name);
     $this->assertArrayHasKey('position', $config);
     $this->assertEquals('position', $config['position']);
     $this->assertArrayHasKey('groups', $config);
     $this->assertCount(3, $config['groups']);
     $this->assertEquals('grouping', $config['groups'][0]);
     $this->assertEquals('sortable_group', $config['groups'][1]);
     $this->assertEquals('sortable_groups', $config['groups'][2]);
 }
 public function testLoggableMetadata()
 {
     $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\Loggable');
     $config = $this->loggable->getConfiguration($this->em, $meta->name);
     $this->assertArrayHasKey('logEntryClass', $config);
     $this->assertEquals('Gedmo\\Loggable\\Entity\\LogEntry', $config['logEntryClass']);
     $this->assertArrayHasKey('loggable', $config);
     $this->assertEquals(true, $config['loggable']);
     $this->assertArrayHasKey('versioned', $config);
     $this->assertEquals(2, count($config['versioned']));
     $this->assertTrue(in_array('title', $config['versioned']));
     $this->assertTrue(in_array('status', $config['versioned']));
 }
 public function testTranslatableMetadata()
 {
     $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\Translatable');
     $config = $this->translatable->getConfiguration($this->em, $meta->name);
     $this->assertArrayHasKey('translationClass', $config);
     $this->assertEquals('Gedmo\\Translatable\\Entity\\Translation', $config['translationClass']);
     $this->assertArrayHasKey('locale', $config);
     $this->assertEquals('locale', $config['locale']);
     $this->assertArrayHasKey('fields', $config);
     $this->assertCount(2, $config['fields']);
     $this->assertTrue(in_array('title', $config['fields']));
     $this->assertTrue(in_array('content', $config['fields']));
 }
 public function testTimestampableMetadata()
 {
     $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\Timestampable');
     $config = $this->timestampable->getConfiguration($this->em, $meta->name);
     $this->assertArrayHasKey('create', $config);
     $this->assertEquals('created', $config['create'][0]);
     $this->assertArrayHasKey('update', $config);
     $this->assertEquals('updated', $config['update'][0]);
     $this->assertArrayHasKey('change', $config);
     $onChange = $config['change'][0];
     $this->assertEquals('published', $onChange['field']);
     $this->assertEquals('status.title', $onChange['trackedField']);
     $this->assertEquals('Published', $onChange['value']);
 }
 /**
  * @param ClassMetadata $class
  * @param array         $entityData
  * @param string        $revType
  */
 private function saveRevisionEntityData($class, $entityData, $revType)
 {
     $params = array($this->getRevisionId(), $revType);
     $types = array(\PDO::PARAM_INT, \PDO::PARAM_STR);
     foreach ($class->fieldNames as $field) {
         $params[] = $entityData[$field];
         $types[] = $class->fieldMappings[$field]['type'];
     }
     foreach ($class->associationMappings as $field => $assoc) {
         if (($assoc['type'] & ClassMetadata::TO_ONE) > 0 && $assoc['isOwningSide']) {
             $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
             if ($entityData[$field] !== null) {
                 $relatedId = $this->uow->getEntityIdentifier($entityData[$field]);
             }
             $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
             foreach ($assoc['sourceToTargetKeyColumns'] as $sourceColumn => $targetColumn) {
                 if ($entityData[$field] === null) {
                     $params[] = null;
                     $types[] = \PDO::PARAM_STR;
                 } else {
                     $params[] = $relatedId[$targetClass->fieldNames[$targetColumn]];
                     $types[] = $targetClass->getTypeOfColumn($targetColumn);
                 }
             }
         }
     }
     $this->conn->executeUpdate($this->getInsertRevisionSQL($class), $params, $types);
 }
 public function testTreeMetadata()
 {
     $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\NestedTree');
     $config = $this->tree->getConfiguration($this->em, $meta->name);
     $this->assertArrayHasKey('strategy', $config);
     $this->assertEquals('nested', $config['strategy']);
     $this->assertArrayHasKey('left', $config);
     $this->assertEquals('left', $config['left']);
     $this->assertArrayHasKey('right', $config);
     $this->assertEquals('right', $config['right']);
     $this->assertArrayHasKey('level', $config);
     $this->assertEquals('level', $config['level']);
     $this->assertArrayHasKey('root', $config);
     $this->assertEquals('root', $config['root']);
     $this->assertArrayHasKey('parent', $config);
     $this->assertEquals('parent', $config['parent']);
 }
 /**
  * Marks this collection as changed/dirty.
  */
 private function changed()
 {
     if (!$this->isDirty) {
         $this->isDirty = true;
         if ($this->association !== null && $this->association['isOwningSide'] && $this->association['type'] == ClassMetadata::MANY_TO_MANY && $this->em->getClassMetadata(get_class($this->owner))->isChangeTrackingNotify()) {
             $this->em->getUnitOfWork()->scheduleForDirtyCheck($this->owner);
         }
     }
 }
Пример #10
0
 public function updateEntitySchema($entity)
 {
     $meta = $this->em->getClassMetadata($this->getEntityName($entity));
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $sql = $schemaTool->getUpdateSchemaSql(array($meta));
     $schemaTool->updateSchema(array($meta), true);
     return $sql;
     return $this;
 }
 public function testMetadata()
 {
     $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\Uploadable');
     $config = $this->listener->getConfiguration($this->em, $meta->name);
     $this->assertTrue($config['uploadable']);
     $this->assertTrue($config['allowOverwrite']);
     $this->assertTrue($config['appendNumber']);
     $this->assertEquals('/my/path', $config['path']);
     $this->assertEquals('getPath', $config['pathMethod']);
     $this->assertEquals('mimeType', $config['fileMimeTypeField']);
     $this->assertEquals('path', $config['filePathField']);
     $this->assertEquals('size', $config['fileSizeField']);
     $this->assertEquals('callbackMethod', $config['callback']);
     $this->assertEquals('SHA1', $config['filenameGenerator']);
     $this->assertEquals(1500, $config['maxSize']);
     $this->assertContains('text/plain', $config['allowedTypes']);
     $this->assertContains('text/css', $config['allowedTypes']);
     $this->assertContains('video/jpeg', $config['disallowedTypes']);
     $this->assertContains('text/html', $config['disallowedTypes']);
 }
Пример #12
0
 /**
  * Create schema for article rendition
  *
  * @param Exception $e
  * @return void
  */
 private function createSchemaIfMissing(\Exception $e)
 {
     if ($e->getCode() === '42S02') {
         try {
             $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->orm);
             $schemaTool->createSchema(array($this->orm->getClassMetadata('Newscoop\\Image\\ArticleRendition')));
         } catch (\Exception $e) {
             // ignore possible errors - foreign key to Images table
         }
     }
 }
 public function testTreeMetadata()
 {
     $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\MaterializedPathTree');
     $config = $this->tree->getConfiguration($this->em, $meta->name);
     $this->assertArrayHasKey('strategy', $config);
     $this->assertEquals('materializedPath', $config['strategy']);
     $this->assertArrayHasKey('activate_locking', $config);
     $this->assertTrue($config['activate_locking']);
     $this->assertArrayHasKey('locking_timeout', $config);
     $this->assertEquals(10, $config['locking_timeout']);
     $this->assertArrayHasKey('level', $config);
     $this->assertEquals('level', $config['level']);
     $this->assertArrayHasKey('parent', $config);
     $this->assertEquals('parent', $config['parent']);
     $this->assertArrayHasKey('path_source', $config);
     $this->assertEquals('title', $config['path_source']);
     $this->assertArrayHasKey('path', $config);
     $this->assertEquals('path', $config['path']);
     $this->assertArrayHasKey('lock_time', $config);
     $this->assertEquals('lockTime', $config['lock_time']);
 }
Пример #14
0
 /**
  * Get class metadata
  *
  * @param string $path Path to class files
  * @param string $namespace Namespace of classes
  * @return array Class metadata
  */
 private static function getClassMetas($path, $namespace)
 {
     $metadata = array();
     if ($handle = opendir($path)) {
         while (false !== ($file = readdir($handle))) {
             if (preg_match('/\\.php$/', $file)) {
                 list($class) = explode('.', $file);
                 $metadata[] = self::$entityManager->getClassMetadata($namespace . $class);
             }
         }
     }
     self::$metadata = array_merge(self::$metadata, $metadata);
     return $metadata;
 }
Пример #15
0
 /**
  * INTERNAL:
  * Sets the collection owner. Used (only?) during hydration.
  *
  * @param object $entity
  * @param AssociationMapping $assoc
  */
 public function setOwner($entity, AssociationMapping $assoc)
 {
     $this->_owner = $entity;
     $this->_association = $assoc;
     if ($assoc->isInverseSide()) {
         // For sure bi-directional
         $this->_backRefFieldName = $assoc->mappedByFieldName;
     } else {
         $targetClass = $this->_em->getClassMetadata($assoc->targetEntityName);
         if (isset($targetClass->inverseMappings[$assoc->sourceFieldName])) {
             // Bi-directional
             $this->_backRefFieldName = $targetClass->inverseMappings[$assoc->sourceFieldName]->sourceFieldName;
         }
     }
 }
 public function testSluggableMetadata()
 {
     $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\Sluggable');
     $config = $this->sluggable->getConfiguration($this->em, $meta->name);
     $this->assertArrayHasKey('slugFields', $config);
     $this->assertEquals('slug', $config['slugFields']['slug']['slug']);
     $this->assertArrayHasKey('style', $config['slugFields']['slug']);
     $this->assertEquals('camel', $config['slugFields']['slug']['style']);
     $this->assertArrayHasKey('updatable', $config['slugFields']['slug']);
     $this->assertTrue($config['slugFields']['slug']['updatable']);
     $this->assertArrayHasKey('unique', $config['slugFields']['slug']);
     $this->assertTrue($config['slugFields']['slug']['unique']);
     $this->assertArrayHasKey('separator', $config['slugFields']['slug']);
     $this->assertEquals('_', $config['slugFields']['slug']['separator']);
     $this->assertArrayHasKey('fields', $config);
     $this->assertEquals(3, count($config['fields']['slug']));
     $fields = $config['fields'];
     $this->assertEquals('title', $fields['slug'][0]['field']);
     $this->assertEquals(0, $fields['slug'][0]['position']);
     $this->assertEquals('code', $fields['slug'][1]['field']);
     $this->assertEquals(false, $fields['slug'][1]['position']);
     $this->assertEquals('ean', $fields['slug'][2]['field']);
     $this->assertEquals(1, $fields['slug'][2]['position']);
 }
Пример #17
0
 /**
  * Get article entity
  *
  * @param  int                      $articleNumber
  * @return Newscoop\Package\Article
  */
 private function getArticle($articleNumber)
 {
     try {
         $article = $this->orm->getRepository('Newscoop\\Package\\Article')->findOneBy(array('id' => $articleNumber));
     } catch (\Exception $e) {
         if ($e->getCode() === '42S02') {
             $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->orm);
             try {
                 $schemaTool->createSchema(array($this->orm->getClassMetadata('Newscoop\\Package\\Article')));
             } catch (\Exception $e) {
             }
             $article = null;
         } else {
             throw $e;
         }
     }
     if ($article === null) {
         $article = new Article($articleNumber);
         $this->orm->persist($article);
         $this->orm->flush($article);
     }
     return $article;
 }
Пример #18
0
 /**
  * Método para ler o annotations do doctrine
  * @param  string $entidade namespace da classe
  * @return [type]           Objeto de mapeamento da entidade
  */
 public function readEntityDoctrine($entidade)
 {
     return $this->entityManager->getClassMetadata($entidade);
 }
 public function testTranslatableMetadataWithEmbedded()
 {
     $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\TranslatableWithEmbedded');
     $config = $this->translatable->getConfiguration($this->em, $meta->name);
     $this->assertContains('embedded.subtitle', $config['fields']);
 }
Пример #20
0
 /**
  * Notifies this UnitOfWork of a property change in an entity.
  *
  * @param object $entity The entity that owns the property.
  * @param string $propertyName The name of the property that changed.
  * @param mixed $oldValue The old value of the property.
  * @param mixed $newValue The new value of the property.
  */
 public function propertyChanged($entity, $propertyName, $oldValue, $newValue)
 {
     $oid = spl_object_hash($entity);
     $class = $this->em->getClassMetadata(get_class($entity));
     $isAssocField = isset($class->associationMappings[$propertyName]);
     if (!$isAssocField && !isset($class->fieldMappings[$propertyName])) {
         return;
         // ignore non-persistent fields
     }
     // Update changeset and mark entity for synchronization
     $this->entityChangeSets[$oid][$propertyName] = array($oldValue, $newValue);
     if (!isset($this->scheduledForDirtyCheck[$class->rootEntityName][$oid])) {
         $this->scheduleForDirtyCheck($entity);
     }
 }
Пример #21
0
 /**
  * Notifies this UnitOfWork of a property change in an entity.
  *
  * @param object $entity The entity that owns the property.
  * @param string $propertyName The name of the property that changed.
  * @param mixed $oldValue The old value of the property.
  * @param mixed $newValue The new value of the property.
  */
 public function propertyChanged($entity, $propertyName, $oldValue, $newValue)
 {
     $oid = spl_object_hash($entity);
     $class = $this->_em->getClassMetadata(get_class($entity));
     $this->_entityChangeSets[$oid][$propertyName] = array($oldValue, $newValue);
     if (isset($class->associationMappings[$propertyName])) {
         $assoc = $class->associationMappings[$propertyName];
         if ($assoc->isOneToOne() && $assoc->isOwningSide) {
             $this->_entityUpdates[$oid] = $entity;
         } else {
             if ($oldValue instanceof PersistentCollection) {
                 // A PersistentCollection was de-referenced, so delete it.
                 if (!in_array($oldValue, $this->_collectionDeletions, true)) {
                     $this->_collectionDeletions[] = $oldValue;
                 }
             }
         }
     } else {
         $this->_entityUpdates[$oid] = $entity;
     }
 }
Пример #22
0
 /**
  * Notifies this UnitOfWork of a property change in an entity.
  *
  * @param object $entity The entity that owns the property.
  * @param string $propertyName The name of the property that changed.
  * @param mixed $oldValue The old value of the property.
  * @param mixed $newValue The new value of the property.
  * @todo Simply use _scheduledForDirtyCheck, otherwise a lot of behavior is potentially inconsistent.
  */
 public function propertyChanged($entity, $propertyName, $oldValue, $newValue)
 {
     $oid = spl_object_hash($entity);
     $class = $this->em->getClassMetadata(get_class($entity));
     $isAssocField = isset($class->associationMappings[$propertyName]);
     if (!$isAssocField && !isset($class->fieldMappings[$propertyName])) {
         return;
         // ignore non-persistent fields
     }
     //$this->scheduleForDirtyCheck($entity);
     $this->entityChangeSets[$oid][$propertyName] = array($oldValue, $newValue);
     if ($isAssocField) {
         $assoc = $class->associationMappings[$propertyName];
         if ($assoc->isOneToOne() && $assoc->isOwningSide) {
             $this->entityUpdates[$oid] = $entity;
         } else {
             if ($oldValue instanceof PersistentCollection) {
                 // A PersistentCollection was de-referenced, so delete it.
                 if (!in_array($oldValue, $this->collectionDeletions, true)) {
                     $this->collectionDeletions[] = $oldValue;
                 }
             }
         }
     } else {
         $this->entityUpdates[$oid] = $entity;
     }
 }