Esempio n. 1
0
 /**
  * Hydrates the given node
  * @param LifecycleEventArgs $eventArgs
  */
 public function postLoad(LifecycleEventArgs $eventArgs)
 {
     if ($eventArgs->getDocument() instanceof Node) {
         /*
          * Loading users and group inside the current Node
          * Using an event suscriber to allow these objects to come from many places
          */
         $node = $eventArgs->getDocument();
         $groupId = $node->getGroupId();
         /*
          * If netBS
          *
         if(!is_null($groupId))
             $node->setGroup($this->em->getRepository('AppBundle:Groupe')->find($groupId));
         
         
         foreach($node->getUsersId() as $id)
             $node->addUser($this->em->getRepository('InterneSecurityBundle:User')->find($id));
         */
         /*
          * If colibri
          */
         foreach ($node->getUsersId() as $id) {
             $user = $eventArgs->getDocumentManager()->getRepository('ColibriUserBundle:User')->find($id);
             $node->addUser($user);
         }
     }
 }
Esempio n. 2
0
 public function postLoad(\Doctrine\ODM\MongoDB\Event\LifecycleEventArgs $eventArgs)
 {
     if (!$eventArgs->getDocument() instanceof \Bpi\ApiBundle\Domain\Entity\Author) {
         return;
     }
     $author = $eventArgs->getDocument();
     $author->loadAgency($eventArgs->getDocumentManager()->getRepository('BpiApiBundle:Aggregate\\Agency'));
 }
 public function postRemove(LifecycleEventArgs $eventArgs)
 {
     if ($eventArgs->getDocument() instanceof Image) {
         /* @var Image $image */
         $image = $eventArgs->getDocument();
         try {
             $this->imageManager->delete($image, 'uploads');
         } catch (FileException $e) {
             $this->logger->error('PostRemoveListener: Error while deleting image ' . $image->getFileName() . ' Error: ' . $e->getMessage());
         }
     }
 }
 public function postUpdate(LifecycleEventArgs $arg)
 {
     if (!$this->container->isScopeActive('request')) {
         return;
     }
     if (!$this->container->get('security.context')->getToken()->isAuthenticated()) {
         return;
     }
     if ($arg->getDocument() instanceof Document\Article) {
         if ($arg->getDocument()->wereTranslationsModified()) {
             $this->notifyModification($arg->getDocument(), $arg->getDocumentManager());
         }
     }
 }
Esempio n. 5
0
 public function postRemove(LifecycleEventArgs $eventArgs)
 {
     $document = $eventArgs->getDocument();
     if ($document instanceof $this->objectClass) {
         $this->removeIfScheduled($document);
     }
 }
Esempio n. 6
0
 public function preUpdate(LifecycleEventArgs $args)
 {
     $document = $args->getDocument();
     // perhaps you only want to act on some "Product" document
     if ($document instanceof Project) {
         $dm = $args->getDocumentManager();
         $document->setDateUpdated(new \DateTime("now"));
         $class = $dm->getClassMetadata("Zeega\\DataBundle\\Document\\Project");
         if ($args->hasChangedField("tags")) {
             $update = true;
             $oldTags = $args->getOldValue('tags');
             foreach ($oldTags as $tag) {
                 $name = $tag->getName();
                 $id = $tag->getId();
                 if ($name == 'homepage' && $id !== null) {
                     $update = false;
                     break;
                 }
             }
             if ($update === true) {
                 $document->setDateTagsUpdated(new \DateTime("now"));
             }
         }
         $dm->getUnitOfWork()->recomputeSingleDocumentChangeSet($class, $document);
     }
 }
 /**
  * @param LifecycleEventArgs $event
  */
 public function prePersist(LifecycleEventArgs $event)
 {
     $document = $event->getDocument();
     $className = get_class($document);
     $generateAnnotations = $this->annotationReader->getClassAnnotation(new \ReflectionClass($className), 'OpenOrchestra\\Mapping\\Annotations\\Document');
     if (!is_null($generateAnnotations)) {
         $repository = $this->container->get($generateAnnotations->getServiceName());
         $getSource = $generateAnnotations->getSource($document);
         $getGenerated = $generateAnnotations->getGenerated($document);
         $setGenerated = $generateAnnotations->setGenerated($document);
         $testMethod = $generateAnnotations->getTestMethod();
         if ($testMethod === null && $repository instanceof FieldAutoGenerableRepositoryInterface) {
             $testMethod = 'testUniquenessInContext';
         }
         if (is_null($document->{$getGenerated}())) {
             $source = $document->{$getSource}();
             $source = Inflector::tableize($source);
             $sourceField = $this->suppressSpecialCharacterHelper->transform($source);
             $generatedField = $sourceField;
             $count = 1;
             while ($repository->{$testMethod}($generatedField)) {
                 $generatedField = $sourceField . '-' . $count;
                 $count++;
             }
             $document->{$setGenerated}($generatedField);
         }
     }
 }
 /**
  * @param LifecycleEventArgs $event
  */
 public function preUpdate(LifecycleEventArgs $event)
 {
     if (!($object = $event->getDocument()) instanceof ContentInterface || in_array($object->getContentId(), $this->contentManaged)) {
         return;
     }
     $this->contentManaged[] = $object->getContentId();
     $contents = $this->getContentRepository()->findByContentId($object->getContentId());
     $contentType = $this->getContentTypeRepository()->findOneByContentTypeIdInLastVersion($object->getContentType());
     /** @var ContentInterface $content */
     foreach ($contents as $content) {
         if ($content != $object) {
             foreach ($this->immutableData as $immutableData) {
                 $getter = $this->generateGetter($immutableData, $object);
                 $setter = 'set' . ucfirst($immutableData);
                 $content->{$setter}($object->{$getter}());
             }
             /** @var FieldTypeInterface $field */
             foreach ($contentType->getFields() as $field) {
                 if (!$field->isTranslatable()) {
                     $contentAttribute = $this->getContentAttribute($content, $field->getFieldId());
                     $contentAttribute->setValue($object->getAttributeByName($field->getFieldId())->getValue());
                 }
             }
         }
         $event->getDocumentManager()->flush($content);
     }
 }
 public function preRemove(LifecycleEventArgs $args)
 {
     $dm = $args->getDocumentManager();
     $currentDocument = $args->getDocument();
     $currentDocumentClass = get_class($currentDocument);
     $isRefExists = FALSE;
     $documentClassNames = $dm->getConfiguration()->getMetadataDriverImpl()->getAllClassNames();
     foreach ($documentClassNames as $documentClassName) {
         try {
             $cm = $dm->getClassMetadata($documentClassName);
             foreach ($cm->getAssociationNames() as $associationName) {
                 if ($currentDocumentClass == $cm->getAssociationTargetClass($associationName) || is_subclass_of($currentDocumentClass, $cm->getAssociationTargetClass($associationName))) {
                     $searchObj = $dm->getRepository($documentClassName)->findOneBy(array($associationName . '.$id' => new \MongoId($currentDocument->getId())));
                     if ($searchObj) {
                         $isRefExists = TRUE;
                     }
                 }
             }
         } catch (\Exception $e) {
         }
     }
     if ($isRefExists) {
         throw new \Exception('ref_erro');
     }
 }
 /**
  * @param LifecycleEventArgs $eventArgs
  * @since 0.28
  */
 public function postLoad(LifecycleEventArgs $eventArgs)
 {
     $entity = $eventArgs->getDocument();
     if ($entity instanceof AttachableEntityInterface) {
         $this->injectAttachableEntityManager($entity);
     }
 }
Esempio n. 11
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function prePersist($args)
 {
     $object = $args->getDocument();
     if ($object instanceof UserInterface) {
         $this->updateUserFields($object);
     }
 }
 public function preUpdate(LifecycleEventArgs $eventArgs)
 {
     $document = $eventArgs->getDocument();
     if (!$document instanceof SearchableEntityInterface) {
         return;
     }
     $dm = $eventArgs->getDocumentManager();
     $uow = $dm->getUnitOfWork();
     $changeset = $uow->getDocumentChangeset($document);
     $filter = $this->getKeywordsFilter();
     $keywords = array();
     $mustUpdate = false;
     foreach ($document->getSearchableProperties() as $name) {
         if (isset($changeset[$name])) {
             $mustUpdate = true;
             break;
         }
     }
     if (!$mustUpdate) {
         return;
     }
     $keywords = $filter->filter($document);
     $document->setKeywords($keywords);
     $uow->recomputeSingleDocumentChangeSet($dm->getClassMetadata(get_class($document)), $document);
 }
 /**
  * @param LifecycleEventArgs $eventArgs
  */
 public function setPath(LifecycleEventArgs $eventArgs)
 {
     $document = $eventArgs->getDocument();
     if ($document instanceof NodeInterface && false === $document->isDeleted()) {
         $nodeRepository = $this->container->get('open_orchestra_model.repository.node');
         $nodeId = $document->getNodeId();
         $siteId = $document->getSiteId();
         $language = $document->getLanguage();
         $path = '';
         $parentNode = $nodeRepository->findInLastVersion($document->getParentId(), $document->getLanguage(), $siteId);
         if ($parentNode instanceof NodeInterface) {
             $path = $parentNode->getPath() . '/';
         }
         $path .= $nodeId;
         if ($path != $document->getPath()) {
             $document->setPath($path);
             $this->nodes[] = $document;
             $childNodes = $nodeRepository->findSubTreeByPath($document->getPath(), $siteId, $language);
             foreach ($childNodes as $childNode) {
                 $this->nodes[] = $childNode;
                 $childNode->setPath(preg_replace('/' . preg_quote($document->getPath(), '/') . '(.*)/', $path . '$1', $childNode->getPath()));
             }
         }
     }
 }
Esempio n. 14
0
 public function postUpdate(LifecycleEventArgs $eventArgs)
 {
     $document = $eventArgs->getDocument();
     if ($document instanceof MODM67EmbeddedObject) {
         $document->postUpdate = true;
     }
 }
 /**
  * Set object creator & updater
  *
  * @param LifecycleEventArgs $args The event arguments
  */
 public function prePersist(LifecycleEventArgs $args)
 {
     $obj = $args->getDocument();
     $blameable = $this->driver->getBlameableAnnotation($obj);
     if (null !== $blameable) {
         $this->updateEntity($obj, $blameable, true);
     }
 }
 /**
  *
  * @param \Doctrine\ODM\MongoDB\Event\LifecycleEventArgs $eventArgs
  */
 protected function recomputeChangeset(LifecycleEventArgs $eventArgs)
 {
     $documentManager = $eventArgs->getDocumentManager();
     $document = $eventArgs->getDocument();
     $unitOfWork = $documentManager->getUnitOfWork();
     $metadata = $documentManager->getClassMetadata(get_class($document));
     $unitOfWork->recomputeSingleDocumentChangeSet($metadata, $document);
 }
 /**
  * @param LifecycleEventArgs $event
  */
 public function postUpdate(LifecycleEventArgs $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof ChannelableInterface) {
         return;
     }
     $this->process($document, 'add');
 }
Esempio n. 18
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getDocument();
     try {
         $this->solrFacade->addDocument($entity);
     } catch (\RuntimeException $e) {
     }
 }
Esempio n. 19
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function postUpdate(LifecycleEventArgs $args)
 {
     $entity = $args->getDocument();
     try {
         $this->solr->updateDocument($entity);
     } catch (\RuntimeException $e) {
     }
 }
Esempio n. 20
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     $document = $args->getDocument();
     if ($document instanceof ArticleSubmissionProgress) {
         $aclManager = $this->container->get('problematic.acl_manager');
         $aclManager->on($document)->permit(MaskBuilder::MASK_OWNER)->save();
     }
 }
 /**
  * @param LifecycleEventArgs $args
  */
 public function preRemove(LifecycleEventArgs $args)
 {
     $entity = $args->getDocument();
     try {
         $this->solrFacade->removeDocument($entity);
     } catch (\RuntimeException $e) {
     }
 }
 /**
  * Populates identities for stored references
  *
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     $object = $args->getDocument();
     if (($name = $this->referenceRepository->getReferenceName($object)) !== false) {
         $identity = $args->getDocumentManager()->getUnitOfWork()->getDocumentIdentifier($object);
         $this->referenceRepository->setReferenceIdentity($name, $identity);
     }
 }
 public function postPersist(LifecycleEventArgs $eventArgs)
 {
     $document = $eventArgs->getDocument();
     $uow = $eventArgs->getDocumentManager()->getUnitOfWork();
     $idmap = $uow->getIdentityMap();
     if ($document instanceof User\Document\User) {
         var_dump($idmap);
     }
 }
Esempio n. 24
0
 /**
  * @param LifecycleEventArgs $eventArgs
  */
 public function postLoad(LifecycleEventArgs $eventArgs)
 {
     $document = $eventArgs->getDocument();
     if ($document instanceof Translation) {
         $this->cache = array('id' => $document->getId(), 'bundle' => $document->getBundle(), 'catalog' => $document->getCatalog());
         return;
     }
     // if document ...
 }
 /**
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getDocument();
     try {
         $this->solr->addDocument($entity);
     } catch (\RuntimeException $e) {
         $this->logger->debug($e->getMessage());
     }
 }
 function it_throws_exception_when_entity_collection_field_has_no_target_entity(LifecycleEventArgs $args, ValueStub $document, DocumentManager $dm, ClassMetadata $documentMetadata)
 {
     $args->getDocument()->willReturn($document);
     $args->getDocumentManager()->willReturn($dm);
     $dm->getClassMetadata(Argument::any())->willReturn($documentMetadata);
     $documentMetadata->fieldMappings = ['foo' => ['type' => 'text'], 'bar' => ['type' => 'entity']];
     $documentMetadata->name = 'Acme/Document';
     $this->shouldThrow(new \RuntimeException('Please provide the "targetEntity" of the Acme/Document::$bar field mapping'))->duringPostLoad($args);
 }
 /**
  * Dans le cas d'un document nouvellement enregistré, je vais renommer le nom du fichier uploadé si besoin
  * @param  LifecycleEventArgs $eventArgs [description]
  * @return [type]                        [description]
  */
 public function postPersist(LifecycleEventArgs $eventArgs)
 {
     $document = $eventArgs->getDocument();
     $dm = $eventArgs->getDocumentManager();
     $is_uploadable = $this->metadata_reader->isUploadable(ClassUtils::getClass($document));
     if ($is_uploadable) {
         // Récupération des champs uploadable
         $fields = $this->metadata_reader->getUploadableFields(ClassUtils::getClass($document));
         // Pour chacun de ces champs, je récupère le mapping associé pour vérifier le namer et le nom du champ
         foreach ($fields as $field) {
             $mapping = $this->mapping_factory->fromField($document, $field['propertyName']);
             if ($mapping->getNamer() instanceof \Redking\Bundle\UploadBundle\Naming\ObjectNamer) {
                 $filename = $mapping->getFileName($document);
                 $file = $mapping->getFile($document);
                 // Si il y a bien un fichier, je vérifie son nom
                 if (!is_null($filename) && $file instanceof File) {
                     $filename_normalized = $mapping->getNamer()->getNormalizedName($document, $filename);
                     // Si les deux noms ne correspondent pas, je renomme et réassigne
                     if (strcmp($filename, $filename_normalized) !== 0) {
                         $base_directory = $mapping->hasDirectoryNamer() ? $mapping->getDirectoryNamer()->directoryName($document, $mapping) . '/' : '';
                         $adapter = $this->filesystem_map->get($mapping->getUploadDestination())->getAdapter();
                         $adapter->rename($base_directory . $filename, $base_directory . $filename_normalized);
                         if ($adapter->exists($base_directory . $filename)) {
                             $adapter->delete($base_directory . $filename);
                         }
                         // On vérifie si il y a des fichiers resized à renommer
                         foreach ($this->resizes as $suffix => $resize_conf) {
                             $resize_filename = $base_directory . ResizedNamer::getName($filename, $suffix);
                             $resize_filename_normalized = $base_directory . ResizedNamer::getName($filename_normalized, $suffix);
                             if ($adapter->exists($resize_filename)) {
                                 $adapter->rename($resize_filename, $resize_filename_normalized);
                                 if ($adapter->exists($resize_filename)) {
                                     $adapter->delete($resize_filename);
                                 }
                             }
                         }
                         $mapping->setFileName($document, $filename_normalized);
                         // Ré-enregistrement
                         $class = $dm->getClassMetadata(get_class($document));
                         $dm->getUnitOfWork()->recomputeSingleDocumentChangeSet($class, $document);
                     }
                 }
             }
             // Traitement du répertoire basé sur l'id pour voir si le fichier est bien dedans
             $directory_namer = $mapping->getDirectoryNamer();
             if (!is_null($directory_namer) && $directory_namer instanceof BaseDirectoryIdNamer) {
                 $adapter = $this->filesystem_map->get($mapping->getUploadDestination())->getAdapter();
                 $filename = $mapping->getFileName($document);
                 $good_path = ltrim($directory_namer->directoryName($document, $mapping) . '/' . $filename, '/');
                 $bad_path = ltrim($directory_namer->directoryNameError($document, $mapping) . '/' . $filename, '/');
                 if (!$adapter->exists($good_path) && $adapter->exists($bad_path)) {
                     $success = $adapter->rename($bad_path, $good_path);
                 }
             }
         }
     }
 }
 public function postLoad(LifecycleEventArgs $args)
 {
     $document = $args->getDocument();
     if (!$document instanceof UserInterface) {
         return;
     }
     $resolver = $this->services->get('Settings/EntityResolver');
     $document->setSettingsEntityResolver($resolver);
 }
Esempio n. 29
0
 public function postLoad(LifecycleEventArgs $args)
 {
     $dm = $args->getDocumentManager();
     $document = $args->getDocument();
     if (!$document instanceof GH1152Child) {
         return;
     }
     $document->parentAssociation = $dm->getUnitOfWork()->getParentAssociation($document);
 }
 /**
  * Creates and injects the organization reference to an user entity.
  *
  * @param LifecycleEventArgs $args
  */
 public function postLoad(LifecycleEventArgs $args)
 {
     $document = $args->getDocument();
     if ($document instanceof UserInterface) {
         $repository = $args->getDocumentManager()->getRepository('Organizations\\Entity\\Organization');
         $userId = $document->getId();
         $reference = new OrganizationReference($userId, $repository);
         $document->setOrganization($reference);
     }
 }