Exemplo n.º 1
0
 /**
  * @param LifecycleEventArgs $event
  */
 public function postLoad(LifecycleEventArgs $event)
 {
     $entity = $event->getEntity();
     if ($entity instanceof ConfigurationEntry) {
         $entity->init($this->container);
     }
 }
 public function prePersist(LifecycleEventArgs $event)
 {
     $object = $event->getObject();
     if ($object instanceof UuidAwareInterface and !$object->getId()) {
         $object->setId((new UuidGenerator())->generate($event->getEntityManager(), $object));
     }
 }
Exemplo n.º 3
0
 /**
  * Handle pre save event
  *
  * @param LifecycleEventArgs $args Event arguments
  */
 protected function preSave(LifecycleEventArgs $args)
 {
     $annotations = $this->container->get('cyber_app.metadata.reader')->getUploadebleFieldsAnnotations($args->getEntity());
     if (0 === count($annotations)) {
         return;
     }
     foreach ($annotations as $field => $annotation) {
         $config = $this->container->getParameter('oneup_uploader.config.' . $annotation->endpoint);
         if (!(isset($config['use_orphanage']) && $config['use_orphanage'])) {
             continue;
         }
         $value = (array) PropertyAccess::createPropertyAccessor()->getValue($args->getEntity(), $field);
         $value = array_filter($value, 'strlen');
         $value = array_map(function ($file) {
             return pathinfo($file, PATHINFO_BASENAME);
         }, $value);
         if (empty($value)) {
             continue;
         }
         $orphanageStorage = $this->container->get('oneup_uploader.orphanage.' . $annotation->endpoint);
         $files = [];
         foreach ($orphanageStorage->getFiles() as $file) {
             if (in_array($file->getBasename(), $value, true)) {
                 $files[] = $file;
             }
         }
         $orphanageStorage->uploadFiles($files);
     }
 }
Exemplo n.º 4
0
 /**
  * After entity with reminders was loaded, load reminders
  *
  * @param LifecycleEventArgs $args
  */
 public function postLoad(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof RemindableInterface) {
         $this->getReminderManager()->loadReminders($entity);
     }
 }
 /**
  * Post load
  * @param LifecycleEventArgs $args
  */
 public function postLoad(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof TranslatableInterface) {
         $entity->setLocale($this->locale);
     }
 }
 /**
  * @param LifecycleEventArgs $event
  */
 public function postLoad(LifecycleEventArgs $event)
 {
     $settings = $event->getObject();
     if ($settings instanceof SettingsInterface) {
         $this->reverseTransform($settings);
     }
 }
Exemplo n.º 7
0
 /**
  * @ORM\PostLoad
  *
  * @param \Venne\Security\User $user
  * @param \Doctrine\ORM\Event\LifecycleEventArgs $event
  */
 public function postLoadHandler(User $user, LifecycleEventArgs $event)
 {
     $em = $event->getEntityManager();
     $user->setExtendedUserCallback(function () use($em, $user) {
         return $em->getRepository($user->getClass())->findOneBy(array('user' => $user->id));
     });
 }
Exemplo n.º 8
0
 public function postLoad(LifecycleEventArgs $args)
 {
     $entity = $args->getObject();
     if ($entity instanceof ServiceAwareEntityInterface) {
         $entity->setServiceLocator($this->serviceManager);
     }
 }
 /**
  * @param LifecycleEventArgs $args
  * @return bool
  * @throws \Exception
  */
 public function checkBadWords(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if (!$entity instanceof BadWordDetectorInterface) {
         return true;
     }
     $badWords = $args->getEntityManager()->getRepository('RenowazeBundle:BadWord')->findAll();
     /** @var BadWordDetector $annotationParams */
     $annotationParams = $this->reader->getClassAnnotation(new \ReflectionClass($entity), 'RenowazeBundle\\Annotation\\BadWordDetector');
     foreach ($annotationParams->fields as $field) {
         $methodName = 'get' . ucfirst($field);
         if (!method_exists($entity, $methodName)) {
             throw new \Exception(sprintf('Field "%s" not found in entity "%s"', $methodName, get_class($entity)));
         }
         /** @var BadWord $badWord */
         foreach ($badWords as $badWord) {
             if (strpos($entity->{$methodName}(), $badWord->getWord()) !== false) {
                 $entity->setHasBadWords(true);
                 return true;
             }
         }
     }
     $entity->setHasBadWords(false);
     return true;
 }
 /**
  * @param LifecycleEventArgs $args
  */
 public function prePersist($args)
 {
     $object = $args->getEntity();
     if ($object instanceof Poll && $object->getCreatedOn() === null) {
         $object->setCreatedOn(new \DateTime());
     }
 }
 public function postPersist(LifecycleEventArgs $event)
 {
     /** @var OroEntityManager $em */
     $em = $event->getEntityManager();
     $entity = $event->getEntity();
     $configProvider = $em->getExtendManager()->getConfigProvider();
     $className = get_class($entity);
     if ($configProvider->hasConfig($className)) {
         $config = $configProvider->getConfig($className);
         $schema = $config->get('schema');
         if (isset($schema['relation'])) {
             foreach ($schema['relation'] as $fieldName) {
                 /** @var Config $fieldConfig */
                 $fieldConfig = $configProvider->getConfig($className, $fieldName);
                 if ($fieldConfig->getId()->getFieldType() == 'optionSet' && ($setData = $entity->{Inflector::camelize('get_' . $fieldName)}())) {
                     $model = $configProvider->getConfigManager()->getConfigFieldModel($fieldConfig->getId()->getClassName(), $fieldConfig->getId()->getFieldName());
                     /**
                      * in case of single select field type, should wrap value in array
                      */
                     if ($setData && !is_array($setData)) {
                         $setData = [$setData];
                     }
                     foreach ($setData as $option) {
                         $optionSetRelation = new OptionSetRelation();
                         $optionSetRelation->setData(null, $entity->getId(), $model, $em->getRepository(OptionSet::ENTITY_NAME)->find($option));
                         $em->persist($optionSetRelation);
                         $this->needFlush = true;
                     }
                 }
             }
         }
     }
 }
    /**
     * @param \Doctrine\ORM\Event\LifecycleEventArgs $eventArgs
     */
    public function postLoad(LifecycleEventArgs $eventArgs)
    {
        $action = $eventArgs->getEntity();
        $className = get_class($action);
        $em = $eventArgs->getEntityManager();
        $metadata = $em->getClassMetadata($className);

        if ($metadata->reflClass->implementsInterface('Redpanda\Bundle\ActivityStreamBundle\Model\ActionInterface')) {

            if ($this->streamableResolver->supports($eventArgs, $action->getActorType())) {
                $actorReflProp = $metadata->reflClass->getProperty('actor');
                $actorReflProp->setAccessible(true);
                $actorReflProp->setValue(
                    $action, $this->streamableResolver->resolve($eventArgs, $action->getActorType(), $action->getActorId())
                );
            }

            if ($this->streamableResolver->supports($eventArgs, $action->getTargetType())) {
                $targetReflProp = $metadata->reflClass->getProperty('target');
                $targetReflProp->setAccessible(true);
                $targetReflProp->setValue(
                    $action, $this->streamableResolver->resolve($eventArgs, $action->getTargetType(), $action->getTargetId())
                );
            }

            if (null !== $action->getActionObjectType() && $this->streamableResolver->supports($eventArgs, $action->getActionObjectType())) {
                $actionObjReflProp = $metadata->reflClass->getProperty('actionObject');
                $actionObjReflProp->setAccessible(true);
                $actionObjReflProp->setValue(
                    $action, $this->streamableResolver->resolve($eventArgs, $action->getActionObjectType(), $action->getActionObjectId())
                );
            }
        }
    }
Exemplo n.º 13
0
 public function postLoad(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof Test) {
         $this->calculateCorrectAnswer($entity);
     }
 }
 /**
  * @param LifecycleEventArgs $args
  */
 public function preRemove(LifecycleEventArgs $args)
 {
     $file = $args->getEntity();
     if ($file instanceof File && $file->getName() !== null && file_exists($file->getPath())) {
         $this->cacheManager->remove($file->getPath());
     }
 }
Exemplo n.º 15
0
 /** @ORM\PostLoad */
 public function postLoadHandler(RouteEntity $route, LifecycleEventArgs $event)
 {
     $em = $event->getEntityManager();
     $route->setExtendedRouteCallback(function () use($em, $route) {
         return $em->getRepository($route->getClass())->findOneBy(array('route' => $route->id));
     });
 }
Exemplo n.º 16
0
 /**
  * @param GetResponseEvent $event
  *
  * method called on kernel request used only to persist locale in session
  */
 public function prePersist(LifecycleEventArgs $event)
 {
     $entity = $event->getEntity();
     if ($entity instanceof View && $entity->getLocale() == null) {
         $entity->setLocale($this->defaultLocale);
     }
 }
Exemplo n.º 17
0
 function it_canonicalize_only_user_or_customer_interface_implementation_on_pre_update($canonicalizer, LifecycleEventArgs $event)
 {
     $item = new \stdClass();
     $event->getEntity()->willReturn($item);
     $canonicalizer->canonicalize(Argument::any())->shouldNotBeCalled();
     $this->preUpdate($event);
 }
Exemplo n.º 18
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function preRemove(LifecycleEventArgs $args)
 {
     $object = $args->getEntity();
     if ($object instanceof UploadAwareInterface) {
         $object->removeUpload();
     }
 }
 public function prePersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof User) {
         $this->handleEvent($entity);
     }
 }
Exemplo n.º 20
0
 public function postRemove(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof Expense) {
         $this->remove($entity);
     }
 }
Exemplo n.º 21
0
 public function prePersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof Layout) {
         $entity->setEngine($this->engineParameter);
     }
 }
Exemplo n.º 22
0
 public function prePersist(LifecycleEventArgs $args)
 {
     $object = $args->getObject();
     if ($object instanceof UserInterface) {
         $this->updatePassword($object);
     }
 }
Exemplo n.º 23
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function postRemove(LifecycleEventArgs $args)
 {
     $entity = $args->getObject();
     $em = $args->getEntityManager();
     $meta = $em->getClassMetadata(get_class($entity));
     $this->logEntityChange('removed', $meta, $entity);
 }
Exemplo n.º 24
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof Journal) {
         $this->container->get('core.acl_fixer')->fixAcl($entity);
     }
 }
Exemplo n.º 25
0
 /**
  * Happens before the deletion of a product
  *
  * @param LifecycleEventArgs $args
  */
 public function preRemove(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($this->ormIndexer->isObjectIndexable($entity)) {
         $this->scheduledForDeletion[] = $entity;
     }
 }
 public function postLoad(LifecycleEventArgs $eventArgs)
 {
     $em = $eventArgs->getEntityManager();
     $uow = $em->getUnitOfWork();
     $entity = $eventArgs->getEntity();
     $classname = get_class($entity);
     if (!array_key_exists($classname, $this->getEntities())) {
         return null;
     }
     /** @var Schema $schema */
     $schema = $em->getRepository('Padam87AttributeBundle:Schema')->findOneBy(array('className' => $classname));
     if ($schema === null) {
         throw new \UnexpectedValueException('Schema not found for ' . $classname);
     }
     $qb = $em->getRepository($classname)->createQueryBuilder('main');
     $qb->distinct()->select('d.id')->join('main.attributes', 'a')->join('a.definition', 'd', null, null, 'd.id')->where('main = :main')->setParameter('main', $entity);
     $definitions = $qb->getQuery()->getScalarResult();
     $ids = array_map('current', $definitions);
     foreach ($schema->getDefinitions() as $definition) {
         if (!in_array($definition->getId(), $ids)) {
             $attribute = new Attribute();
             $attribute->setDefinition($definition);
             $entity->addAttribute($attribute);
         }
     }
     if ($uow->getEntityState($entity) == UnitOfWork::STATE_MANAGED) {
         $em->persist($entity);
         $em->flush($entity);
     }
 }
 /**
  * Sets update timestamp upon update.
  *
  * @param LifecycleEventArgs $args
  */
 public function preUpdate(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof TimestampableInterface) {
         $entity->setDatetimeUpdated(new DateTime());
     }
 }
 function it_updates_password_on_pre_update_doctrine_event_for_user_interface_implementation_only($passwordUpdater, LifecycleEventArgs $event, UserInterface $user)
 {
     $user = '';
     $event->getEntity()->willReturn($user);
     $passwordUpdater->updatePassword($user)->shouldNotBeCalled();
     $this->preUpdate($event);
 }
Exemplo n.º 29
0
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof Taggable) {
         $this->getTagManager()->saveTagging($entity);
     }
 }
Exemplo n.º 30
0
 private function collectEventsFromEntity(LifecycleEventArgs $event)
 {
     $entity = $event->getEntity();
     if ($entity instanceof EventContainerInterface) {
         $this->event_manager->registerEventContainer($entity);
     }
 }