本文整理汇总了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')));
}
}
示例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);
}
}
示例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);
}*/
}
}
示例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));
}
}
}
示例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 = [];
}
}
示例6: onFlush
/**
* @param OnFlushEventArgs $args
*/
public function onFlush(OnFlushEventArgs $args)
{
$uow = $args->getEntityManager()->getUnitOfWork();
foreach ($uow->getScheduledEntityDeletions() as $entity) {
$this->addPendingUpdates($entity);
}
}
示例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);
}
}
}
}
}
示例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;
}
}
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
}
}
}
}
}
示例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()));
}
}
}
示例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);
}
}
}
}
}
示例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();
}
}
}
示例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);
}
}
}