作者:dryme
项目:fcs-backen
public function preUpdate(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof User) {
$this->updatePassword($entity);
}
}
作者:dstansb
项目:camdra
public function postRemove(LifecycleEventArgs $event)
{
$object = $event->getObject();
$reflection = new \ReflectionClass($object);
$message = sprintf('%s deleted', $reflection->getShortName());
$this->logger->notice($message, $this->getContext($object));
}
作者:profca
项目:ilio
public function prePersist(LifecycleEventArgs $args)
{
$object = $args->getObject();
if ($object instanceof FileInterface) {
$object->upload();
}
}
作者:kokmo
项目:SKCMS-Admi
public function PostUpdate(LifecycleEventArgs $args)
{
$entity = $args->getObject();
$em = $args->getObjectManager();
$classMetaData = $em->getClassMetadata(get_class($entity));
foreach ($classMetaData->associationMappings as $associationMappingKey => $associationMappingDatas) {
if ($associationMappingDatas['type'] == \Doctrine\ORM\Mapping\ClassMetadataInfo::ONE_TO_MANY) {
$repo = $em->getRepository($associationMappingDatas['targetEntity']);
$associated = $repo->findBy([$associationMappingDatas['mappedBy'] => $entity]);
$newAssociated = call_user_func([$entity, 'get' . ucfirst($associationMappingKey)]);
$changed = false;
foreach ($associated as $associatedEntity) {
if (!$newAssociated->contains($associatedEntity)) {
$changed = true;
$em->remove($associatedEntity);
}
}
if ($changed) {
$em->flush();
}
//
}
}
// dump($classMetaData);
// die();
}
作者:foreverglor
项目:menu-bundl
protected function updateRoute(LifecycleEventArgs $args)
{
$object = $args->getObject();
if ($object instanceof MenuInterface) {
$object->setRouter($this->router);
}
}
作者:ugra9
项目:knowledgem
/**
* @param EventArgs|LifecycleEventArgs $args
*/
public function postPersist(LifecycleEventArgs $args)
{
$entity = $args->getObject();
$em = $args->getObjectManager();
if ($entity instanceof Comment) {
if ($entity->getArticleId() != null) {
if ($entity->getUserId()->getId() != $entity->getArticleId()->getUserId()->getId()) {
$n = new Notification();
$n->setUser($entity->getUserId())->setArticle($entity->getArticleId());
$em->persist($n);
$em->flush();
}
} else {
if ($entity->getVideoId() != null) {
if ($entity->getUserId()->getId() != $entity->getVideoId()->getUserId()->getId()) {
$n = new Notification();
$n->setUser($entity->getUserId())->setVideo($entity->getVideoId());
$em->persist($n);
$em->flush();
}
} else {
if ($entity->getLinkId() != null) {
if ($entity->getUserId()->getId() != $entity->getLinkId()->getUserId()->getId()) {
$n = new Notification();
$n->setUser($entity->getUserId())->setLink($entity->getLinkId());
$em->persist($n);
$em->flush();
}
}
}
}
}
}
作者:javiersanto
项目:pim-community-de
/**
* Pre update
* PreUpdate event needs to recompute change set
*
* @param LifecycleEventArgs $args
*/
public function preUpdate(LifecycleEventArgs $args)
{
$object = $args->getObject();
if ($object instanceof AbstractMetric && $object->getUnit()) {
$this->createMetricBaseValues($object);
}
}
作者:abdeldaye
项目:pim-community-de
function it_applies_during_pre_update_on_timestampable_object(LifecycleEventArgs $args, TimestampableInterface $object)
{
$args->getObject()->willReturn($object);
$object->setCreated()->shouldNotBeCalled();
$object->setUpdated(Argument::type('\\DateTime'))->shouldBeCalled();
$this->preUpdate($args);
}
作者:hiroyasu5
项目:ec-cub
public function preUpdate(LifecycleEventArgs $args)
{
$entity = $args->getObject();
if (method_exists($entity, 'setUpdateDate')) {
$entity->setUpdateDate(new \DateTime());
}
}
作者:fullpip
项目:image-bundl
/**
* Removes image file
* @param LifecycleEventArgs $event
*/
public function preRemove(LifecycleEventArgs $event)
{
$entity = $event->getEntity();
if ($entity instanceof ImageInterface) {
$this->uploader->remove($entity);
}
}
作者:kumf
项目:Syliu
/**
* @param LifecycleEventArgs $eventArgs
*/
public function preUpdate(LifecycleEventArgs $eventArgs)
{
$object = $eventArgs->getObject();
if ($this->isSluggable($object)) {
$this->updateSlug($object);
}
}
作者:DavidG0
项目:ErichardDmsBundl
/**
* Control object dms
*
* @param LifecycleEventArgs $args
*/
public function postUpdate(LifecycleEventArgs $args)
{
$entity = $args->getObject();
if ($entity instanceof GedableInterface) {
$this->manageNodeTree($entity->getGedTree());
}
}
作者:Dren-
项目:mobitne
/**
* Pre update listener based on doctrine commons, overwrite to update
* the changeset in the UoW and to handle non-common event argument
* class.
*
* @param LifecycleEventArgs $args weak typed to allow overwriting
*/
public function preUpdate($args)
{
$object = $args->getObject();
if ($object instanceof UserInterface) {
$this->updateUserFields($object);
}
}
作者:abdeldaye
项目:pim-community-de
function it_marks_indexed_product_values_outdated_after_loading_a_value(LifecycleEventArgs $args, ProductValueInterface $value, ProductInterface $entity)
{
$args->getObject()->willReturn($value);
$value->getEntity()->willReturn($entity);
$entity->markIndexedValuesOutdated()->shouldBeCalled();
$this->postLoad($args);
}
作者:JhnMh
项目:SimpleProjec
private function fixOrders(LifecycleEventArgs $event)
{
$entity = $event->getEntity();
if (!$entity instanceof \UR\DB\NewBundle\Entity\BasePerson) {
return;
}
$personId = $entity->getId();
$this->LOGGER->debug("Fixing orders for ID: " . $personId);
$em = $event->getEntityManager();
$education = $em->getRepository('NewBundle:Education')->findBy(array('person' => $personId), array('educationOrder' => 'ASC'));
$this->fixArray($em, $education, PersonInformation::EDUCATION);
$honour = $em->getRepository('NewBundle:Honour')->findBy(array('person' => $personId), array('honourOrder' => 'ASC'));
$this->fixArray($em, $honour, PersonInformation::HONOUR);
$property = $em->getRepository('NewBundle:Property')->findBy(array('person' => $personId), array('propertyOrder' => 'ASC'));
$this->fixArray($em, $property, PersonInformation::PROPERTY);
$rank = $em->getRepository('NewBundle:Rank')->findBy(array('person' => $personId), array('rankOrder' => 'ASC'));
$this->fixArray($em, $rank, PersonInformation::RANK);
$religion = $em->getRepository('NewBundle:Religion')->findBy(array('person' => $personId), array('religionOrder' => 'ASC'));
$this->fixArray($em, $religion, PersonInformation::RELIGION);
$roadOfLife = $em->getRepository('NewBundle:RoadOfLife')->findBy(array('person' => $personId), array('roadOfLifeOrder' => 'ASC'));
$this->fixArray($em, $roadOfLife, PersonInformation::ROAD_OF_LIFE);
$status = $em->getRepository('NewBundle:Status')->findBy(array('person' => $personId), array('statusOrder' => 'ASC'));
$this->fixArray($em, $status, PersonInformation::STATUS);
$works = $em->getRepository('NewBundle:Works')->findBy(array('person' => $personId), array('worksOrder' => 'ASC'));
$this->fixArray($em, $works, PersonInformation::WORK);
if ($entity instanceof \UR\DB\NewBundle\Entity\Person) {
$source = $em->getRepository('NewBundle:Source')->findBy(array('person' => $personId), array('sourceOrder' => 'ASC'));
$this->fixArray($em, $source, PersonInformation::SOURCE);
}
$em->flush();
}
作者:knplab
项目:rad-use
function let(Generator $generator, HasInitialPassword $user, LifecycleEventArgs $event)
{
$generator->generate()->willReturn('password');
$event->getObject()->willReturn($user);
$user->getPlainPassword()->willReturn(null);
$this->beConstructedWith($generator);
}
作者:joschi12
项目:DoctrineOrmOdmAdapte
public function preRemove(LifecycleEventArgs $event)
{
$object = $event->getObject();
if ($this->isReferenceable($object)) {
$this->objectAdapterManager->removeReference($object);
}
}
作者:wellcommerc
项目:wellcommerc
public function onPaymentBeforeSave(LifecycleEventArgs $args)
{
$entity = $args->getObject();
if ($entity instanceof PaymentInterface) {
$this->getPaymentStateHistoryManager()->createPaymentStateHistory($entity);
}
}
作者:unpetitl
项目:stor
/**
* Cette methode sera appelé depuis mon services.yml
* ET reçoie en argument mon evenement Doctrine 2
* @param LifecycleEventArgs $args
*/
public function postUpdate(LifecycleEventArgs $args)
{
// Je récupère mon objet après modification (update)
$entity = $args->getEntity();
$em = $args->getEntityManager();
// récupérer l'Entité Manager
// Si mon objet est un objet de mon entité Product
if ($entity instanceof Product) {
// récupéré le titre de mion produit
$title = $entity->getTitle();
# 2 tableaux avec accents
$a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'Ð', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', '?', '?', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', '?', '?', 'L', 'l', 'N', 'n', 'N', 'n', 'N', 'n', '?', 'O', 'o', 'O', 'o', 'O', 'o', 'Œ', 'œ', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'Š', 'š', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Ÿ', 'Z', 'z', 'Z', 'z', 'Ž', 'ž', '?', 'ƒ', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', '?', '?', '?', '?', '?', '?');
$b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');
// slugifier mon titre stocké dans une variable slug
$slug = strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), str_replace($a, $b, $title)));
// setSlug me permet de modifier le slug de mon product
$entity->setSlug($slug);
$em->persist($entity);
//j'enregistre en base de données
$em->flush();
// quand la quantité sera égal à 1
if ($entity->getQuantity() == 1) {
$this->notification->notify($entity->getId(), 'Attention, votre produit ' . $entity->getTitle() . ' a une seule quantité', 'product', 'danger');
} else {
if ($entity->getQuantity() < 5) {
// je notifie la quantité de ce produit
// avec la methode notify()
$this->notification->notify($entity->getId(), 'Attention, votre produit ' . $entity->getTitle() . ' a un stocke bientôt épuisé', 'product', 'warning');
}
}
}
}
作者:knplab
项目:rad-use
function let(Generator $generator, HasSalt $user, LifecycleEventArgs $event)
{
$generator->generate()->willReturn('salt');
$event->getObject()->willReturn($user);
$user->getSalt()->willReturn(null);
$this->beConstructedWith($generator);
}