/** * After WorkflowItem loaded, de-serialize WorkflowItem * * @param LifecycleEventArgs $args */ public function postLoad(LifecycleEventArgs $args) { $entity = $args->getEntity(); if ($this->isSupported($args->getEntity($entity))) { $this->deserialize($entity); } }
/** * 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); } }
public function preRemove(LifecycleEventArgs $args) { if ($args->getEntity() instanceof Appearance) { $appearance = $args->getEntity(); $appearance->setPlayer(null); $appearance->setGame(null); } }
public function postLoad(LifecycleEventArgs $event) { if ($event->getEntity() instanceof Repository) { $event->getEntity()->init($this->container); } if ($event->getEntity() instanceof StoredFile) { $event->getEntity()->init($this->container); } }
public function postLoad(LifecycleEventArgs $event) { if ($event->getEntity() instanceof PartAttachment) { /** * @var $entity PartAttachment */ $entity = $event->getEntity(); $entity->setImage($this->imageService->canHandleMimetype($entity->getMimeType())); } }
/** * @param LifecycleEventArgs $eventArgs * @return void */ public function postRemove(LifecycleEventArgs $eventArgs) { $entity = $eventArgs->getEntity(); if ($entity instanceof ImageInterface) { /** @var PersistentResource $resource */ $resource = $eventArgs->getEntity()->getResource(); if ($resource !== null) { $this->cacheManager->getCache('TYPO3_Media_ImageSize')->remove($resource->getCacheEntryIdentifier()); } } }
protected function flush(LifecycleEventArgs $args) { $identifier = $this->collectionIdentifiers->getIdentifier($args->getEntity()); if ($identifier === false) { return; } $parameters = array(get_class($args->getEntity()) => $identifier); foreach ($this->caches as $cache) { $cache->flush($parameters); } }
/** * When element answers are deleted they need to notify thier jazzee elements * * @param \Doctrine\ORM\Event\OnFlushEventArgs $eventArgs */ public function preRemove(\Doctrine\ORM\Event\LifecycleEventArgs $eventArgs) { switch (get_class($eventArgs->getEntity())) { case 'Jazzee\\Entity\\Answer': $answer = $eventArgs->getEntity(); foreach ($answer->getElementAnswers() as $elementAnswer) { $elementAnswer->preRemove(); } if ($attachment = $answer->getAttachment()) { $attachment->preRemove(); } break; } }
/** * @param LifecycleEventArgs $args * @param bool $remove */ protected function update(LifecycleEventArgs $args, $remove) { $alias = $this->builder->getEntityAlias($args->getEntity()); $this->keeper->set($alias, new \DateTime()); if ($this->track_individually_entity) { $ids = $this->builder->getEntityIdentifier($args->getEntity()); if ($ids !== null) { if ($remove) { $this->keeper->remove($alias . $ids); } else { $this->keeper->set($alias . $ids, new \DateTime()); } } } }
public function prePersist(LifecycleEventArgs $args) { $entity = $args->getEntity(); if ($entity instanceof Layout) { $entity->setEngine($this->engineParameter); } }
public function prePersist(LifecycleEventArgs $args) { $entity = $args->getEntity(); if ($entity instanceof User) { $this->handleEvent($entity); } }
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); }
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); }
/** * @param LifecycleEventArgs $event */ public function postLoad(LifecycleEventArgs $event) { $entity = $event->getEntity(); if ($entity instanceof ConfigurationEntry) { $entity->init($this->container); } }
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); } }
/** * @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()); } }
/** * @param LifecycleEventArgs $args */ public function postPersist(LifecycleEventArgs $args) { $entity = $args->getEntity(); if ($entity instanceof Journal) { $this->container->get('core.acl_fixer')->fixAcl($entity); } }
/** * 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 $args) { $entity = $args->getEntity(); if ($entity instanceof Test) { $this->calculateCorrectAnswer($entity); } }
/** * 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); } }
/** * @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; }
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 LifecycleEventArgs $args */ public function prePersist($args) { $object = $args->getEntity(); if ($object instanceof Poll && $object->getCreatedOn() === null) { $object->setCreatedOn(new \DateTime()); } }
/** * @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()) ); } } }
/** * Post load * @param LifecycleEventArgs $args */ public function postLoad(LifecycleEventArgs $args) { $entity = $args->getEntity(); if ($entity instanceof TranslatableInterface) { $entity->setLocale($this->locale); } }
/** * @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); } }
/** * Sets update timestamp upon update. * * @param LifecycleEventArgs $args */ public function preUpdate(LifecycleEventArgs $args) { $entity = $args->getEntity(); if ($entity instanceof TimestampableInterface) { $entity->setDatetimeUpdated(new DateTime()); } }
/** * @param LifecycleEventArgs $args */ public function preRemove(LifecycleEventArgs $args) { $object = $args->getEntity(); if ($object instanceof UploadAwareInterface) { $object->removeUpload(); } }
public function postPersist(LifecycleEventArgs $args) { $entity = $args->getEntity(); if ($entity instanceof Taggable) { $this->getTagManager()->saveTagging($entity); } }
public function postRemove(LifecycleEventArgs $args) { $entity = $args->getEntity(); if ($entity instanceof Expense) { $this->remove($entity); } }