當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Event\OnFlushEventArgs類代碼示例

本文整理匯總了PHP中Doctrine\ORM\Event\OnFlushEventArgs的典型用法代碼示例。如果您正苦於以下問題:PHP OnFlushEventArgs類的具體用法?PHP OnFlushEventArgs怎麽用?PHP OnFlushEventArgs使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了OnFlushEventArgs類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: onFlush

 public function onFlush(OnFlushEventArgs $args)
 {
     $em = $args->getEntityManager();
     $uow = $em->getUnitOfWork();
     foreach ($uow->getScheduledEntityInsertions() as $entity) {
         /*
          * Check if the class is a child of the Meta class, the latter
          * handling the automatic createDate and modifiedDate methods.
          */
         if (!is_subclass_of($entity, 'CampaignChain\\CoreBundle\\Entity\\Meta')) {
             continue;
         }
         $logMetadata = $em->getClassMetadata(get_class($entity));
         $entity->setCreatedDate(new \DateTime('now', new \DateTimeZone('UTC')));
         $entity->setModifiedDate($entity->getCreatedDate());
         $em->persist($entity);
         $classMetadata = $em->getClassMetadata(get_class($entity));
         $uow->recomputeSingleEntityChangeSet($classMetadata, $entity);
     }
     foreach ($uow->getScheduledEntityUpdates() as $entity) {
         if (!is_subclass_of($entity, 'CampaignChain\\CoreBundle\\Entity\\Meta')) {
             continue;
         }
         $logMetadata = $em->getClassMetadata(get_class($entity));
         $entity->setModifiedDate(new \DateTime('now', new \DateTimeZone('UTC')));
     }
 }
開發者ID:CampaignChain,項目名稱:core,代碼行數:27,代碼來源:DoctrineMetaListener.php

示例2: onFlush

 /**
  * Change cssHash of views when a widget is updated or deleted.
  *
  * @param OnFlushEventArgs $args
  */
 public function onFlush(OnFlushEventArgs $args)
 {
     $this->em = $args->getEntityManager();
     $this->uow = $this->em->getUnitOfWork();
     $this->widgetRepo = $this->em->getRepository('Victoire\\Bundle\\WidgetBundle\\Entity\\Widget');
     $this->viewRepo = $this->em->getRepository('Victoire\\Bundle\\CoreBundle\\Entity\\View');
     $updatedEntities = $this->uow->getScheduledEntityUpdates();
     $deletedEntities = $this->uow->getScheduledEntityDeletions();
     //Update View's CSS and inheritors of updated and deleted widgets
     foreach (array_merge($updatedEntities, $deletedEntities) as $entity) {
         if (!$entity instanceof Widget) {
             continue;
         }
         $view = $entity->getView();
         $this->updateViewCss($view);
         $this->updateTemplateInheritorsCss($view);
     }
     //Remove CSS of deleted View and update its inheritors
     foreach ($deletedEntities as $entity) {
         if (!$entity instanceof View) {
             continue;
         }
         $this->viewCssBuilder->removeCssFile($entity->getCssHash());
         $this->updateTemplateInheritorsCss($entity);
     }
     //Update CSS of updated View and its inheritors
     foreach ($updatedEntities as $entity) {
         if (!$entity instanceof View) {
             continue;
         }
         $this->updateViewCss($entity);
         $this->updateTemplateInheritorsCss($entity);
     }
 }
開發者ID:global01,項目名稱:victoire,代碼行數:39,代碼來源:WidgetSubscriber.php

示例3: onFlush

 public function onFlush(OnFlushEventArgs $args)
 {
     //echo "---preFlush".PHP_EOL;
     $em = $args->getEntityManager();
     $uow = $em->getUnitOfWork();
     foreach ($uow->getScheduledEntityInsertions() as $entity) {
         if ($entity instanceof CmsUser) {
             // Adds a phonenumber to every newly persisted CmsUser ...
             $phone = new CmsPhonenumber();
             $phone->phonenumber = 12345;
             // Update object model
             $entity->addPhonenumber($phone);
             // Invoke regular persist call
             $em->persist($phone);
             // Explicitly calculate the changeset since onFlush is raised
             // after changeset calculation!
             $uow->computeChangeSet($em->getClassMetadata(get_class($phone)), $phone);
             // Take a snapshot because the UoW wont do this for us, because
             // the UoW did not visit this collection.
             // Alternatively we could provide an ->addVisitedCollection() method
             // on the UoW.
             $entity->getPhonenumbers()->takeSnapshot();
         }
         /*foreach ($uow->getEntityChangeSet($entity) as $field => $change) {
                         list ($old, $new) = $change;
         
                         var_dump($old);
                     }*/
     }
 }
開發者ID:andreia,項目名稱:doctrine,代碼行數:30,代碼來源:FlushEventTest.php

示例4: onFlush

 /**
  * @param OnFlushEventArgs $event
  */
 public function onFlush(OnFlushEventArgs $event)
 {
     $em = $event->getEntityManager();
     $uow = $em->getUnitOfWork();
     foreach ($uow->getScheduledEntityInsertions() as $entity) {
         if ($entity instanceof User) {
             $userSettings = new UserSettings();
             $userSettings->setUser($entity);
             $em->persist($userSettings);
             $uow->computeChangeSet($em->getClassMetadata(UserSettings::clazz()), $userSettings);
         }
         if ($entity instanceof Group) {
             $groupSettings = new GroupSettings();
             $groupSettings->setGroup($entity);
             $em->persist($groupSettings);
             $uow->computeChangeSet($em->getClassMetadata(GroupSettings::clazz()), $groupSettings);
         }
     }
     foreach ($uow->getScheduledEntityDeletions() as $entity) {
         if ($entity instanceof User) {
             $query = $em->createQuery(sprintf('DELETE FROM %s us WHERE us.user = ?0', UserSettings::clazz()));
             $query->execute(array($entity));
         }
         if ($entity instanceof Group) {
             $query = $em->createQuery(sprintf('DELETE FROM %s us WHERE us.group = ?0', GroupSettings::clazz()));
             $query->execute(array($entity));
         }
     }
 }
開發者ID:modera,項目名稱:foundation,代碼行數:32,代碼來源:SettingsEntityManagingListener.php

示例5: onFlush

 public function onFlush(OnFlushEventArgs $args)
 {
     $em = $args->getEntityManager();
     $uow = $em->getUnitOfWork();
     $entities = array_merge($uow->getScheduledEntityInsertions(), $uow->getScheduledEntityUpdates());
     foreach ($entities as $entity) {
         if (!$entity instanceof Searchable) {
             continue;
         }
         $this->_updates[] = $entity;
     }
     $entities = array_merge($uow->getScheduledEntityDeletions());
     foreach ($entities as $entity) {
         if (!$entity instanceof Searchable) {
             continue;
         }
         $this->_deletions[] = $entity;
     }
     if (count($this->_deletions)) {
         $indexes = $em->getRepository('Chalk\\Core\\Index')->entities($this->_deletions);
         foreach ($indexes as $index) {
             $em->remove($index);
         }
         $this->_deletions = [];
     }
 }
開發者ID:jacksleight,項目名稱:chalk,代碼行數:26,代碼來源:Listener.php

示例6: onFlush

 /**
  * @param OnFlushEventArgs $args
  */
 public function onFlush(OnFlushEventArgs $args)
 {
     $uow = $args->getEntityManager()->getUnitOfWork();
     foreach ($uow->getScheduledEntityDeletions() as $entity) {
         $this->addPendingUpdates($entity);
     }
 }
開發者ID:qrz-io,項目名稱:pim-community-dev,代碼行數:10,代碼來源:ProductRelatedEntityRemovalSubscriber.php

示例7: onFlush

 public function onFlush(OnFlushEventArgs $args)
 {
     /** @var $om EntityManager */
     $om = $args->getEntityManager();
     $uow = $om->getUnitOfWork();
     $arm = $this->getAutoRouteManager();
     $this->contentResolver->setEntityManager($om);
     $this->insertions = $uow->getScheduledEntityInsertions();
     $scheduledUpdates = $uow->getScheduledEntityUpdates();
     //        $updates = array_merge($scheduledInserts, $scheduledUpdates);
     foreach ($scheduledUpdates as $document) {
         $this->handleInsertOrUpdate($document, $arm, $om, $uow);
     }
     $removes = $uow->getScheduledCollectionDeletions();
     foreach ($removes as $document) {
         if ($this->isAutoRouteable($document)) {
             $referrers = $om->getRepository('Symfony\\Cmf\\Bundle\\RoutingAutoBundle\\Doctrine\\Orm\\AutoRoute')->findBy(array('contentCode' => $this->contentResolver->getContentCode($document)));
             if ($referrers) {
                 foreach ($referrers as $autoRoute) {
                     $uow->scheduleForDelete($autoRoute);
                 }
             }
         }
     }
 }
開發者ID:fredpeaks,項目名稱:RoutingAutoBundle,代碼行數:25,代碼來源:AutoRouteListener.php

示例8: onFlush

 public function onFlush(OnFlushEventArgs $args)
 {
     if ($this->_isFlushing) {
         return;
     }
     $em = $args->getEntityManager();
     $uow = $em->getUnitOfWork();
     $entities = array_merge($uow->getScheduledEntityInsertions(), $uow->getScheduledEntityUpdates(), $uow->getScheduledEntityDeletions());
     foreach ($entities as $entity) {
         $structures = [];
         if ($entity instanceof Structure) {
             $structures[] = $entity;
         } else {
             if ($entity instanceof Node) {
                 $structures[] = $entity->structure;
             } else {
                 if ($entity instanceof Content) {
                     foreach ($entity->nodes as $node) {
                         $structures[] = $node->structure;
                     }
                 } else {
                     continue;
                 }
             }
         }
         foreach ($structures as $structure) {
             if (!in_array($structure, $this->_structures, true)) {
                 $this->_structures[] = $structure;
             }
         }
     }
 }
開發者ID:jacksleight,項目名稱:chalk,代碼行數:32,代碼來源:Listener.php

示例9: onFlush

 /**
  * @param OnFlushEventArgs $eventArgs
  */
 public function onFlush(OnFlushEventArgs $eventArgs)
 {
     $em = $eventArgs->getEntityManager();
     $uow = $em->getUnitOfWork();
     foreach ($uow->getScheduledEntityInsertions() as $entity) {
         if ($entity instanceof Customer) {
             $this->getLogger()->info('[CustomerConnectorSubscriber][onFlush] Scheduled for insertion');
             $this->getSubscriptionAdapter()->createCustomer($entity);
             $this->persistAndRecomputeChangeset($em, $uow, $entity);
         }
     }
     foreach ($uow->getScheduledEntityUpdates() as $entity) {
         if ($entity instanceof Customer) {
             $this->getLogger()->info('[CustomerConnectorSubscriber][onFlush] Scheduled for updates');
             $changeset = $uow->getEntityChangeSet($entity);
             $keys = array('email', 'firstName', 'lastName', 'companyName', 'billingCity', 'billingCountry', 'billingStreet');
             if ($this->arrayHasKeys($changeset, $keys)) {
                 $entity->setSubscriptionSynced(false);
             }
             if ($entity->getSubscriptionCustomerId() && $entity->isSubscriptionSynced() == false) {
                 $this->getSubscriptionAdapter()->updateCustomer($entity);
             } elseif (is_null($entity->getSubscriptionCustomerId())) {
                 $this->getSubscriptionAdapter()->createCustomer($entity);
             }
             $this->persistAndRecomputeChangeset($em, $uow, $entity);
         }
     }
 }
開發者ID:vik0803,項目名稱:SubscriptionBundle,代碼行數:31,代碼來源:CustomerConnectorSubscriber.php

示例10: onFlush

 /**
  * Upload the files on new and updated entities
  *
  * @param OnFlushEventArgs $eventArgs
  */
 public function onFlush(OnFlushEventArgs $eventArgs)
 {
     $em = $eventArgs->getEntityManager();
     $uow = $em->getUnitOfWork();
     $entities = array_merge($uow->getScheduledEntityInsertions(), $uow->getScheduledEntityUpdates());
     foreach ($entities as $entity) {
         $classMetadata = $em->getClassMetadata(get_class($entity));
         if (!$this->isEntitySupported($classMetadata)) {
             continue;
         }
         if (0 === count($entity->getUploadableFields())) {
             continue;
         }
         // If there is an error when moving the file, an exception will
         // be automatically thrown by move(). This will properly prevent
         // the entity from being persisted to the database on error
         foreach ($entity->getUploadableFields() as $field => $uploadDir) {
             // If a file has been uploaded
             if (null !== $entity->getUploadField($field)) {
                 // Generate the filename
                 $filename = $entity->generateFilename($entity->getUploadField($field), $field);
                 // Set the filename
                 $entity->setUploadPath($field, $filename);
                 $entity->getUploadField($field)->move($entity->getUploadRootDir($field), $entity->getUploadPath($field));
                 // Remove the previous file if necessary
                 $entity->removeUpload($field, true);
                 $entity->unsetUploadField($field);
             }
         }
         $em->persist($entity);
         $uow->recomputeSingleEntityChangeSet($classMetadata, $entity);
     }
 }
開發者ID:smart85,項目名稱:UnifikDoctrineBehaviorsBundle,代碼行數:38,代碼來源:UploadableListener.php

示例11: onFlush

 /**
  * @param OnFlushEventArgs $args
  * @return mixed|void
  */
 public function onFlush(OnFlushEventArgs $args)
 {
     $em = $args->getEntityManager();
     $unitOfWork = $em->getUnitOfWork();
     foreach ($unitOfWork->getScheduledEntityUpdates() as $entity) {
         if ($entity instanceof PageInterface) {
             if ($contentRoute = $entity->getContentRoute()) {
                 $contentRoute->setPath(PageHelper::getPageRoutePath($entity->getPath()));
                 $em->persist($contentRoute);
                 $unitOfWork->computeChangeSet($em->getClassMetadata(get_class($contentRoute)), $contentRoute);
                 foreach ($entity->getAllChildren() as $child) {
                     $contentRoute = $child->getContentRoute();
                     $contentRoute->setPath(PageHelper::getPageRoutePath($child->getPath()));
                     $em->persist($contentRoute);
                     $unitOfWork->computeChangeSet($em->getClassMetadata(get_class($contentRoute)), $contentRoute);
                     if ($entity->getStatus() == Page::STATUS_PUBLISHED) {
                         if ($childSnapshot = $child->getSnapshot()) {
                             $snapshotRoute = $childSnapshot->getContentRoute();
                             $newPath = PageHelper::getPageRoutePath($child->getPath());
                             $snapshotRoute->setPath($newPath);
                             $childSnapshot->setPath($newPath);
                             $em->persist($childSnapshot);
                             $em->persist($snapshotRoute);
                             $unitOfWork->computeChangeSet($em->getClassMetadata(get_class($childSnapshot)), $childSnapshot);
                             $unitOfWork->computeChangeSet($em->getClassMetadata(get_class($snapshotRoute)), $snapshotRoute);
                         }
                     }
                 }
             }
         }
     }
 }
開發者ID:networking,項目名稱:init-cms-bundle,代碼行數:36,代碼來源:PageListener.php

示例12: onFlush

 public function onFlush(OnFlushEventArgs $args)
 {
     if (!$this->container->has('orocrm_contact.contact.manager')) {
         return;
     }
     $em = $args->getEntityManager();
     $uow = $em->getUnitOfWork();
     $insertedEntities = $uow->getScheduledEntityInsertions();
     $updatedEntities = $uow->getScheduledEntityUpdates();
     $entities = array_merge($insertedEntities, $updatedEntities);
     foreach ($entities as $entity) {
         if (!$entity instanceof DiamanteUser) {
             continue;
         }
         $contactManager = $this->container->get('orocrm_contact.contact.manager');
         $contact = $contactManager->getRepository()->findOneBy(['email' => $entity->getEmail()]);
         if (empty($contact)) {
             continue;
         }
         if ($entity->getFirstName() == null) {
             $entity->setFirstName($contact->getFirstName());
         }
         if ($entity->getLastName() == null) {
             $entity->setLastName($contact->getLastName());
         }
         try {
             $em->persist($entity);
             $md = $em->getClassMetadata(get_class($entity));
             $uow->recomputeSingleEntityChangeSet($md, $entity);
         } catch (\Exception $e) {
             $this->container->get('monolog.logger.diamante')->addWarning(sprintf('Error saving Contact Information for Diamante User with email: %s', $entity->getEmail()));
         }
     }
 }
開發者ID:gitter-badger,項目名稱:diamantedesk-application,代碼行數:34,代碼來源:DiamanteUserListener.php

示例13: onFlush

 /**
  * @param OnFlushEventArgs $event
  * @param ContainerInterface $container
  * @return mixed
  */
 public function onFlush(OnFlushEventArgs $event, ContainerInterface $container)
 {
     $this->timelineRepository = $container->get('diamante.ticket_timeline.repository');
     $em = $event->getEntityManager();
     $uof = $em->getUnitOfWork();
     foreach ($uof->getScheduledEntityInsertions() as $entity) {
         if ($entity instanceof Ticket && (string) $entity->getStatus()->getValue() === 'new') {
             $this->increaseNewCounter();
             $this->persistCurrentDayRecord($em);
         }
     }
     foreach ($uof->getScheduledEntityUpdates() as $entity) {
         if ($entity instanceof Ticket) {
             $changes = $uof->getEntityChangeSet($entity);
             if (!isset($changes['status'])) {
                 continue;
             }
             $from = $changes['status'][0]->getValue();
             $to = $changes['status'][1]->getValue();
             if (isset($changes['status']) && $from !== $to) {
                 if ($to === 'closed') {
                     $this->increaseClosedCounter();
                     $this->persistCurrentDayRecord($em);
                 }
                 if ($from === 'closed') {
                     $this->increaseReopenCounter();
                     $this->persistCurrentDayRecord($em);
                 }
             }
         }
     }
 }
開發者ID:gitter-badger,項目名稱:diamantedesk-application,代碼行數:37,代碼來源:ReportTimelineServiceImpl.php

示例14: onFlush

 /**
  * @param OnFlushEventArgs $args
  */
 public function onFlush(OnFlushEventArgs $args)
 {
     $em = $args->getEntityManager();
     $uow = $em->getUnitOfWork();
     $emails = [];
     foreach ($uow->getScheduledEntityInsertions() as $oid => $entity) {
         if ($entity instanceof EmailUser) {
             /*
              * Collect already flushed emails with bodies and later check
              * if there is new binding to mailbox.
              * (email was sent from the system and now mailbox is synchronized)
              */
             $email = $entity->getEmail();
             if ($email && $email->getId() && $email->getEmailBody() && $entity->getMailboxOwner()) {
                 $emails[$email->getId()] = $email;
             }
         } elseif ($entity instanceof EmailBody) {
             $this->emailBodies[$oid] = $entity;
         }
     }
     if ($emails) {
         $emailsToProcess = $this->filterEmailsWithNewlyBoundMailboxes($em, $emails);
         foreach ($emailsToProcess as $email) {
             $this->emailBodies[spl_object_hash($email->getEmailBody())] = $email->getEmailBody();
         }
     }
 }
開發者ID:ramunasd,項目名稱:platform,代碼行數:30,代碼來源:MailboxEmailListener.php

示例15: onFlush

 /**
  * @param OnFlushEventArgs $eventArgs
  */
 public function onFlush(OnFlushEventArgs $eventArgs)
 {
     $em = $eventArgs->getEntityManager();
     $uow = $em->getUnitOfWork();
     foreach ($uow->getScheduledEntityInsertions() as $entity) {
         if ($entity instanceof Plan) {
             $this->getLogger()->info('[PlanConnectorSubscriber][onFlush] Scheduled for insertion');
             $this->getSubscriptionAdapter()->createPlan($entity);
             $this->persistAndRecomputeChangeset($em, $uow, $entity);
         }
     }
     foreach ($uow->getScheduledEntityUpdates() as $entity) {
         if ($entity instanceof Plan) {
             $changeset = $uow->getEntityChangeSet($entity);
             $keys = array('amount', 'trialPeriod', 'trialPeriodUnit');
             if ($this->arrayHasKeys($changeset, $keys)) {
                 $entity->setSubscriptionSynced(false);
             }
             $this->getLogger()->info('[PlanConnectorSubscriber][onFlush] Scheduled for updates');
             if ($entity->getSubscriptionPlanId() && $entity->isSubscriptionSynced() == false) {
                 $this->getSubscriptionAdapter()->updatePlan($entity);
             } elseif (is_null($entity->getSubscriptionPlanId())) {
                 $this->getSubscriptionAdapter()->createPlan($entity);
             }
             $this->persistAndRecomputeChangeset($em, $uow, $entity);
         }
     }
 }
開發者ID:vik0803,項目名稱:SubscriptionBundle,代碼行數:31,代碼來源:PlanConnectorSubscriber.php


注:本文中的Doctrine\ORM\Event\OnFlushEventArgs類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。