/**
  * @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));
     }
 }
 /**
  * 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);
     }
 }
Esempio 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);
     }
 }
Esempio 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));
     });
 }
Esempio 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())
                );
            }
        }
    }
Esempio 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());
     }
 }
Esempio 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));
     });
 }
Esempio 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);
     }
 }
Esempio 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);
 }
 /**
  * @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);
     }
 }
 public function postRemove(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof Expense) {
         $this->remove($entity);
     }
 }
 public function prePersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof Layout) {
         $entity->setEngine($this->engineParameter);
     }
 }
Esempio n. 22
0
 public function prePersist(LifecycleEventArgs $args)
 {
     $object = $args->getObject();
     if ($object instanceof UserInterface) {
         $this->updatePassword($object);
     }
 }
Esempio 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);
 }
Esempio 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);
     }
 }
Esempio 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);
 }
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof Taggable) {
         $this->getTagManager()->saveTagging($entity);
     }
 }
Esempio n. 30
0
 private function collectEventsFromEntity(LifecycleEventArgs $event)
 {
     $entity = $event->getEntity();
     if ($entity instanceof EventContainerInterface) {
         $this->event_manager->registerEventContainer($entity);
     }
 }