本文整理汇总了PHP中Doctrine\ORM\Event\PreUpdateEventArgs::getEntityManager方法的典型用法代码示例。如果您正苦于以下问题:PHP PreUpdateEventArgs::getEntityManager方法的具体用法?PHP PreUpdateEventArgs::getEntityManager怎么用?PHP PreUpdateEventArgs::getEntityManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Event\PreUpdateEventArgs
的用法示例。
在下文中一共展示了PreUpdateEventArgs::getEntityManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preUpdate
public function preUpdate(PreUpdateEventArgs $eventArgs)
{
$order = $eventArgs->getEntity();
if (!$order instanceof \Shopware\Models\Order\Order) {
return;
}
//order or payment status changed?
if ($eventArgs->hasChangedField('paymentStatus') || $eventArgs->hasChangedField('orderStatus')) {
$historyData = array('userID' => null, 'change_date' => date('Y-m-d H:i:s'), 'orderID' => $order->getId());
if (Shopware()->Auth()->getIdentity() && Shopware()->Auth()->getIdentity()->id) {
$user = $eventArgs->getEntityManager()->find('Shopware\\Models\\User\\User', Shopware()->Auth()->getIdentity()->id);
$historyData['userID'] = $user->getId();
}
//order status changed?
if ($eventArgs->hasChangedField('orderStatus')) {
$historyData['previous_order_status_id'] = $eventArgs->getOldValue('orderStatus')->getId();
$historyData['order_status_id'] = $eventArgs->getNewValue('orderStatus')->getId();
} else {
$historyData['previous_order_status_id'] = $order->getOrderStatus()->getId();
$historyData['order_status_id'] = $order->getOrderStatus()->getId();
}
//payment status changed?
if ($eventArgs->hasChangedField('paymentStatus')) {
$historyData['previous_payment_status_id'] = $eventArgs->getOldValue('paymentStatus')->getId();
$historyData['payment_status_id'] = $eventArgs->getNewValue('paymentStatus')->getId();
} else {
$historyData['previous_payment_status_id'] = $order->getPaymentStatus()->getId();
$historyData['payment_status_id'] = $order->getPaymentStatus()->getId();
}
$eventArgs->getEntityManager()->getConnection()->insert('s_order_history', $historyData);
}
}
示例2: markAsModified
private function markAsModified(PreUpdateEventArgs $args)
{
$entity = $args->getEntity();
$securityToken = $this->securityContext->getToken();
if (!$entity instanceof Advertisement || null == $securityToken) {
return;
}
$user = $securityToken->getUser();
if (($args->hasChangedField('description') || $args->hasChangedField('title')) && $user instanceof Advertiser && $user->getId() == $entity->getAdvertiser()->getId()) {
$entity->markAsModified();
$args->getEntityManager()->getUnitOfWork()->computeChangeSet($args->getEntityManager()->getClassMetadata(get_class($entity)), $entity);
}
}
示例3: preUpdate
public function preUpdate(PreUpdateEventArgs $args)
{
//return;
$em = $args->getEntityManager();
$entity = $args->getEntity();
if ($entity instanceof Invoice && $entity->needsNumber()) {
$entity->setNumber($em->getRepository('SiwappInvoiceBundle:Invoice')->getNextNumber($entity->getSerie()));
}
}
示例4: preUpdate
/**
* @param PreUpdateEventArgs $args
*/
public function preUpdate(PreUpdateEventArgs $args)
{
$entity = $args->getEntity();
if (!$this->isContactEntity($entity)) {
return;
}
/** @var Contact $entity */
$this->setUpdatedProperties($entity, $args->getEntityManager(), true);
}
示例5: preUpdate
/**
* Pre update event process
*
* @param LifecycleEventArgs $args
* @return $this
*/
public function preUpdate(PreUpdateEventArgs $args)
{
$entityClass = ClassUtils::getClass($args->getEntity());
if (array_key_exists($entityClass, $this->notificationRules)) {
$rules = $this->notificationRules[$entityClass];
$event = new PreUpdateNotificationEvent($args->getEntity(), $args->getEntityChangeSet(), array('em' => $args->getEntityManager(), 'rules' => $rules));
$this->eventDispatcher->dispatch('numerique1.notification.event.entity_pre_update', $event);
}
return $this;
}
示例6: preUpdate
/** @ORM\PreUpdate */
public function preUpdate(Company $company, PreUpdateEventArgs $event)
{
$entity = $event->getEntity();
$entityManager = $event->getEntityManager();
if ($event->hasChangedField('identification')) {
$status = $entityManager->getRepository('MainCommonBundle:Status\\PhotographerStatus')->findOneById(1);
//To verify
$company->setStatus($status);
}
}
示例7: preUpdate
/**
* Prepares all Files linked to an Entity before updating the Files and
* persisting the changes to the database
* Once prepared Doctrine UnitOfWork is checked for changes
* to make sure the changes here are saved when it is flushed.
*
* Called on the preUpdate doctrine event.
*
* @param \Doctrine\ORM\Event\PreUpdateEventArgs $args
*
* @return void
*/
public function preUpdate(PreUpdateEventArgs $args)
{
if (!($entity = $args->getEntity()) instanceof FileUpload) {
return;
}
// Prepare multiple Files
$this->prePersistFilePreparation($entity);
// Recompute the change set for the Entity and Files. Makes sure the changes are saved properly
$this->recomputeChangeSetForEntity($entity, $args->getEntityManager());
}
示例8: preUpdate
/**
* @param PreUpdateEventArgs $args
*/
public function preUpdate(PreUpdateEventArgs $args)
{
$entity = $args->getEntity();
if (!$this->isActivityListEntity($entity)) {
return;
}
/** @var ActivityList $entity */
if ($this->isDateUpdatable($entity)) {
$this->setUpdatedProperties($entity, $args->getEntityManager(), true);
}
}
示例9: preUpdate
/**
* @param PreUpdateEventArgs $eventArgs
*/
public function preUpdate(PreUpdateEventArgs $eventArgs)
{
$entity = $eventArgs->getEntity();
if ($this->prepareMedia($entity)) {
// Hack ? Don't know, that's the behaviour Doctrine 2 seems to want
// See : http://www.doctrine-project.org/jira/browse/DDC-1020
$em = $eventArgs->getEntityManager();
$uow = $em->getUnitOfWork();
$uow->recomputeSingleEntityChangeSet($em->getClassMetadata(ClassLookup::getClass($entity)), $eventArgs->getEntity());
}
}
示例10: preUpdate
public function preUpdate(PreUpdateEventArgs $eventArgs)
{
$issue = $eventArgs->getEntity();
$entityManager = $eventArgs->getEntityManager();
if ($issue instanceof Issue) {
$user = $this->container->get('security.context')->getToken()->getUser();
if ($eventArgs->hasChangedField('status')) {
$this->setActivity($issue, $user, Activity::CHANGE_ISSUE_STATUS, $entityManager, true);
}
}
}
示例11: preUpdate
/**
* Set object updater
*
* @param PreUpdateEventArgs $args The event arguments
*/
public function preUpdate(PreUpdateEventArgs $args)
{
$obj = $args->getEntity();
$blameable = $this->driver->getBlameableAnnotation($obj);
if (null !== $blameable) {
$this->updateEntity($obj, $blameable);
$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();
$metadata = $em->getClassMetadata(get_class($obj));
$uow->recomputeSingleEntityChangeSet($metadata, $obj);
}
}
示例12: preUpdate
public function preUpdate(PreUpdateEventArgs $event)
{
$entity = $event->getEntity();
if (!$entity instanceof User) {
return;
}
$this->encodePassword($entity);
// force the save
$em = $event->getEntityManager();
$md = $em->getClassMetadata('Smartburk\\Bundle\\MainBundle\\Entity\\Series');
$em->getUnitOfWork()->recomputeSingleEntityChangeSet($md, $entity);
}
示例13: preUpdate
/**
* @param PreUpdateEventArgs $args
*/
public function preUpdate($args)
{
$object = $args->getEntity();
if ($object instanceof UserInterface) {
$this->updateUserFields($object);
// We are doing a update, so we must force Doctrine to update the
// changeset in case we changed something above
$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();
$meta = $em->getClassMetadata(get_class($object));
$uow->recomputeSingleEntityChangeSet($meta, $object);
}
}
示例14: preUpdate
public function preUpdate(PreUpdateEventArgs $args)
{
$entity = $args->getEntity();
$entityManager = $args->getEntityManager();
if (!$entity instanceof User) {
return;
}
if ($args->hasChangedField('username')) {
$class = ClassUtils::getRealClass($entity);
$old_username = $args->getOldValue('username');
$new_username = $args->getNewValue('username');
$entityManager->getConnection()->update('acl_security_identities', array('identifier' => sprintf('%s-%s', $class, $new_username)), array('identifier' => sprintf('%s-%s', $class, $old_username)));
}
}
示例15: preUpdate
/**
* Checks for updated reviews to update the average score of their site
*
* @param PreUpdateEventArgs $args
*/
public function preUpdate(PreUpdateEventArgs $args)
{
$em = $args->getEntityManager();
$entity = $args->getEntity();
$uow = $em->getUnitOfWork();
$entityClass = get_class($entity);
if ($entityClass == 'Application\\YrchBundle\\Entity\\Review' && $this->needsUpdate($args)) {
$oid = spl_object_hash($entity->getSite());
if (!array_key_exists($oid, $this->_pendingSiteUpdates)) {
$this->_pendingSiteUpdates[$oid] = $entity->getSite();
}
$this->_treatedSiteUpdates[$oid] = false;
}
}