/** * {@inheritdoc} */ public function unpack($object) { if ($object instanceof ObjectSignature) { return $this->em->getReference($object->getClass(), $object->getIdentity()); } return null; }
/** * @param PostFlushEventArgs $args */ public function postFlush(PostFlushEventArgs $args) { if ($this->isInProgress) { return; } $this->initializeFromEventArgs($args); if (count($this->queued) > 0) { $toOutDate = []; foreach ($this->queued as $customerIdentity => $groupedByEntityUpdates) { foreach ($groupedByEntityUpdates as $data) { /** @var Account $account */ $account = is_object($data['account']) ? $data['account'] : $this->em->getReference('OroCRMAccountBundle:Account', $data['account']); /** @var Channel $channel */ $channel = is_object($data['channel']) ? $data['channel'] : $this->em->getReference('OroCRMChannelBundle:Channel', $data['channel']); $entity = $this->createHistoryEntry($customerIdentity, $account, $channel); $toOutDate[] = [$account, $channel, $entity]; $this->em->persist($entity); } } $this->isInProgress = true; $this->em->flush(); foreach (array_chunk($toOutDate, self::MAX_UPDATE_CHUNK_SIZE) as $chunks) { $this->lifetimeRepo->massStatusUpdate($chunks); } $this->queued = []; $this->isInProgress = false; } }
/** * @param Channel $channel * @param string $entity * * @throws \Exception */ protected function fillChannelToEntity(Channel $channel, $entity) { $interfaces = class_implements($entity) ?: []; if (!in_array('OroCRM\\Bundle\\ChannelBundle\\Model\\ChannelAwareInterface', $interfaces)) { return; } /** @var QueryBuilder $qb */ $qb = $this->em->getRepository($entity)->createQueryBuilder('e'); $iterator = new BufferedQueryResultIterator($qb); $writeCount = 0; $toWrite = []; try { $this->em->beginTransaction(); /** @var ChannelAwareInterface $data */ foreach ($iterator as $data) { $writeCount++; if (!$data->getDataChannel()) { $channelReference = $this->em->getReference(ClassUtils::getClass($channel), $channel->getId()); $data->setDataChannel($channelReference); $toWrite[] = $data; } if (0 === $writeCount % static::BATCH_SIZE) { $this->write($toWrite); $toWrite = []; } } if (count($toWrite) > 0) { $this->write($toWrite); } $this->em->commit(); } catch (\Exception $exception) { $this->em->rollback(); throw $exception; } }
/** * @param $id * @return integer */ public function excluir($id) { $entity = $this->em->getReference('Admin\\Domain\\Entity\\OtherEntity', (int) $id); $this->em->remove($entity); $this->em->flush(); return (int) $id; }
/** * @param Notification $notification * @param int $userId */ protected function addPushMessage(Notification $notification, $userId) { $pushMessage = new PushMessage(); $pushMessage->setNotification($notification); $pushMessage->setUser($this->entityManager->getReference(User::CLASS_NAME, $userId)); $notification->addPushMessage($pushMessage); }
/** * @param string $countryCode ISO2 code * @param string $code region code * * @return null|Region */ protected function getRegionReference($countryCode, $code) { if (null === $this->regionByCountryMap) { $this->regionByCountryMap = $this->loadRegionByCountryMap(); } return isset($this->regionByCountryMap[$countryCode], $this->regionByCountryMap[$countryCode][$code]) ? $this->em->getReference('OroAddressBundle:Region', $this->regionByCountryMap[$countryCode][$code]) : null; }
/** * @param Request $request * @return RedirectResponse * @throws \Doctrine\ORM\ORMException */ public function deleteAction(Request $request) { $invoiceId = $request->get('invoiceId'); $invoiceReference = $this->entityManager->getReference('Invoicity\\Business\\Entity\\Invoice', $invoiceId); $this->entityManager->remove($invoiceReference); $this->entityManager->flush(); return new RedirectResponse($this->router->generate('invoicity_invoice_index')); }
public function update(array $data) { $entity = $this->em->getReference('Advocacia\\Entity\\Cadastro', $data['id']); $entity = Configurator::configure($entity, $data); $this->em->persist($entity); $this->em->flush(); return $entity; }
public function delete($id) { $cod_cli = $id; $entity = $this->em->getReference ( 'Pc_help\Entity\Cliente', $cod_cli ); if ($entity) { $this->em->remove ( $entity ); $this->em->flush (); return $id; } }
public function delete($id) { $entity = $this->em->getReference($this->entity, $id); if ($entity) { $this->em->remove($entity); $this->em->flush(); return $id; } }
public function insert(array $data) { $entity = new solucaoService ( $data ); $problema = $this->em->getReference ( "Pc_help\Entity\Problema", $data ['id'] ); $entity->setProblema ( $problema ); $this->em->persist ( $entity ); $this->em->flush (); return $entity; }
/** * Insert un message de team en base * * @param User $user * @param integer $teamId * @param string $message * * @author Benjamin Levoir <*****@*****.**> */ public function insertMessage(User $user, $teamId, $message) { $m = new \CoreBundle\Entity\TeamMessage(); $m->setContent($message); $m->setSender($this->em->getReference('CoreBundle:User', $user->getId())); $m->setTeam($this->em->getReference('CoreBundle:Team', $teamId)); $this->em->persist($m); $this->em->flush(); return $this; }
/** * @param Notification $notification * @param int $userId */ protected function addPushMessage(Notification $notification, $userId) { if ($this->frequencyFilter->filter($userId)) { return; } $this->frequencyFilter->addPushedUser($userId); $pushMessage = new PushMessage(); $pushMessage->setNotification($notification); $pushMessage->setUser($this->entityManager->getReference(User::CLASS_NAME, $userId)); $notification->addPushMessage($pushMessage); }
public function insert(array $data) { $maquina = new clienteService ( $data ); $cliente = $this->em->getReference ( "Pc_help\Entity\Cliente", $data ['id'] ); $maquina->setCliente ( $cliente ); $this->em->persist ( $maquina ); $this->em->flush (); return $maquina; }
public function update(array $data) { // find // da set automaticamnete $entity = $this->em->getReference ( 'Pc_help\Entity\Problema', $data ['id'] ); $entity = Configurator::configure ( $entity, $data ); $this->em->persist ( $entity ); $this->em->flush (); return $entity; }
/** * Returns current user identity, if any. * @return IIdentity|NULL */ public function getIdentity() { $identity = parent::getIdentity(); // if we have our fake identity, we now want to // convert it back into the real entity // returning reference provides potentially lazy behavior if ($identity instanceof FakeIdentity) { return $this->entityManager->getReference($identity->getClass(), $identity->getId()); } return $identity; }
/** * @param array $data * * @return Notification */ public function create($data) { $leaderId = $data['leader']; $notification = new Notification(); $notification->setName(Notification::NEW_FOLLOWER); $notification->setContent(array('follower' => $data['follower'], 'followerFullName' => $data['followerFullName'], 'image' => $data['followerImage'])); $translatedMessage = $this->translator->trans($notification->getTranslationKey(), array('%name%' => $data['followerFullName'])); $notification->setMessage($translatedMessage); $pushMessage = new PushMessage(); $pushMessage->setNotification($notification); $pushMessage->setUser($this->entityManager->getReference(User::CLASS_NAME, $leaderId)); $notification->addPushMessage($pushMessage); return $notification; }
/** * Authenticate via the form using users defined in authorized_users * * @param AuthenticationEvent $event * * @return bool|void */ public function onUserFormAuthentication(AuthenticationEvent $event) { $username = $event->getUsername(); $password = $event->getToken()->getCredentials(); $user = new User(); $user->setUsername($username); $authorizedUsers = $this->parametersHelper->getParameter('authorized_users'); if (is_array($authorizedUsers) && isset($authorizedUsers[$username])) { $testUser = $authorizedUsers[$username]; $user->setPassword($testUser['password']); if ($this->encoder->isPasswordValid($user, $password)) { $user->setFirstName($testUser['firstname'])->setLastName($testUser['lastname'])->setEmail($testUser['email'])->setRole($this->em->getReference('MauticUserBundle:Role', 1)); $event->setIsAuthenticated('authorized_users', $user, true); } } }
/** * {@inheritdoc} */ public function loadCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, EntityCacheEntry $entry, $entity = null) { $data = $entry->data; $hints = self::$hints; if ($entity !== null) { $hints[Query::HINT_REFRESH] = true; $hints[Query::HINT_REFRESH_ENTITY] = $entity; } foreach ($metadata->associationMappings as $name => $assoc) { if (!isset($assoc['cache']) || !isset($data[$name])) { continue; } $assocClass = $data[$name]->class; $assocId = $data[$name]->identifier; $isEagerLoad = $assoc['fetch'] === ClassMetadata::FETCH_EAGER || $assoc['type'] === ClassMetadata::ONE_TO_ONE && !$assoc['isOwningSide']; if (!$isEagerLoad) { $data[$name] = $this->em->getReference($assocClass, $assocId); continue; } $assocKey = new EntityCacheKey($assoc['targetEntity'], $assocId); $assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']); $assocRegion = $assocPersister->getCacheRegion(); $assocEntry = $assocRegion->get($assocKey); if ($assocEntry === null) { return null; } $data[$name] = $this->uow->createEntity($assocEntry->class, $assocEntry->resolveAssociationEntries($this->em), $hints); } if ($entity !== null) { $this->uow->registerManaged($entity, $key->identifier, $data); } $result = $this->uow->createEntity($entry->class, $data, $hints); $this->uow->hydrationComplete(); return $result; }
public function save(array $data = []) { if (isset($data['id'])) { $entity = $this->entityManager->getReference($this->entity, $data['id']); $data['userUpdated'] = $this->entityManager->getReference('Application\\Entity\\WcUser', $this->getUserLogged()->getId()); $hydrator = new ClassMethods(); $hydrator->hydrate($data, $entity); } else { $data['userCreated'] = $this->entityManager->getReference("Application\\Entity\\WcUser", $this->getUserLogged()->getId()); $data['userUpdated'] = $this->entityManager->getReference("Application\\Entity\\WcUser", $this->getUserLogged()->getId()); $entity = new $this->entity($data); } $this->entityManager->persist($entity); $this->entityManager->flush(); return $entity; }
/** * {@inheritdoc} */ public function postLoad(LifecycleEventArgs $args) { $document = $args->getDocument(); $metadata = $args->getDocumentManager()->getClassMetadata(get_class($document)); foreach ($metadata->fieldMappings as $field => $mapping) { if ('entity' === $mapping['type']) { if (!isset($mapping['targetEntity'])) { throw new \RuntimeException(sprintf('Please provide the "targetEntity" of the %s::$%s field mapping', $metadata->name, $field)); } $value = $metadata->reflFields[$field]->getValue($document); if (null !== $value && !$value instanceof $mapping['targetEntity']) { $metadata->reflFields[$field]->setValue($document, $this->entityManager->getReference($mapping['targetEntity'], $value)); } } } }
/** * Maps ids of associations to references * * @param ClassMetadata $class * @param string $field * @param mixed $value */ protected function mapValue(ClassMetadata $class, $field, &$value) { if (!$class->isSingleValuedAssociation($field)) { return; } $mapping = $class->getAssociationMapping($field); $value = $value ? $this->em->getReference($mapping['targetEntity'], $value) : null; }
/** * @param EmailOrigin $emailOrigin */ protected function initEnv(EmailOrigin $emailOrigin) { $this->currentUser = $this->em->getRepository('OroEmailBundle:Mailbox')->findOneByOrigin($emailOrigin); if ($this->currentUser === null) { $this->currentUser = $emailOrigin->getOwner() ? $this->em->getReference('Oro\\Bundle\\UserBundle\\Entity\\User', $emailOrigin->getOwner()->getId()) : null; } $this->currentOrganization = $this->em->getReference('Oro\\Bundle\\OrganizationBundle\\Entity\\Organization', $emailOrigin->getOrganization()->getId()); }
/** * Processing mixed value * * @param mixed $value value * @param string $targetClass targetClass * * @return mixed */ private function processValue($value, $targetClass) { if (is_array($value)) { $value = $this->processArrayValue($value, $targetClass); } else { $value = $this->entityManager->getReference($targetClass, $value); } return $value; }
/** * @param EntityManager $manager * @param array $addressData * @param AbstractDefaultTypedAddress $address */ protected function addAddress(EntityManager $manager, array $addressData, AbstractDefaultTypedAddress $address) { $defaults = []; foreach ($addressData['types'] as $type => $isDefault) { /** @var AddressType $addressType */ $addressType = $manager->getReference('Oro\\Bundle\\AddressBundle\\Entity\\AddressType', $type); $address->addType($addressType); if ($isDefault) { $defaults[] = $addressType; } } /** @var Country $country */ $country = $manager->getReference('OroAddressBundle:Country', $addressData['country']); /** @var Region $region */ $region = $manager->getReference('OroAddressBundle:Region', $addressData['country'] . '-' . $addressData['region']); $address->setDefaults($defaults); $address->setPrimary($addressData['primary'])->setStreet($addressData['street'])->setCity($addressData['city'])->setPostalCode($addressData['postalCode'])->setCountry($country)->setRegion($region); $manager->persist($address); $this->addReference($addressData['label'], $address); }
private function restoreBadgeCollections() { if ($this->connection->getSchemaManager()->tablesExist(array('claro_badge_collection_badges'))) { $this->log('Restoring badge collections...'); $rowBadgeCollections = $this->connection->query('SELECT * FROM claro_badge_collection_badges'); foreach ($rowBadgeCollections as $rowBadgeCollection) { /** @var \Icap\BadgeBundle\Entity\BadgeCollection $badgeCollection */ $badgeCollection = $this->entityManager->getRepository('IcapBadgeBundle:BadgeCollection')->find($rowBadgeCollection['badgecollection_id']); if (null !== $badgeCollection) { /** @var \Icap\BadgeBundle\Repository\UserBadgeRepository $userBadgeRepository */ $userBadgeRepository = $this->entityManager->getRepository('IcapBadgeBundle:UserBadge'); /** @var \Icap\BadgeBundle\Entity\UserBadge $userBadge */ $userBadge = $userBadgeRepository->findOneBy(['user' => $badgeCollection->getUser(), 'badge' => $this->entityManager->getReference('IcapBadgeBundle:Badge', $rowBadgeCollection['badge_id'])]); if (null !== $userBadge) { $this->connection->insert('claro_badge_collection_user_badges', ['badgecollection_id' => $rowBadgeCollection['badgecollection_id'], 'userbadge_id' => $userBadge->getId()]); } } } $this->connection->getSchemaManager()->dropTable('claro_badge_collection_badges'); } }
public function let(TraceableEventDispatcher $dispatcher, EntityManager $em, Article $article, Language $language) { $article->getNumber()->willReturn(10); $article->getName()->willReturn("test article"); $article->getPublicationId()->willReturn(2); $article->getLanguageId()->willReturn(1); $article->getIssueId()->willReturn(20); $article->getSectionId()->willReturn(30); $em->getReference('Newscoop\\Entity\\Language', 1)->willReturn($language); $language->getCode()->willReturn('en'); $this->beConstructedWith($dispatcher, $em); }
function it_transforms_value_of_a_entity_field_into_lazy_reference_to_an_entity(LifecycleEventArgs $args, ValueStub $entity, DocumentManager $dm, ClassMetadata $documentMetadata, \ReflectionProperty $reflFoo, FooStub $foo16, EntityManager $entityManager) { $args->getDocument()->willReturn($entity); $args->getDocumentManager()->willReturn($dm); $dm->getClassMetadata(Argument::any())->willReturn($documentMetadata); $documentMetadata->reflFields = ['bar' => $reflFoo]; $documentMetadata->fieldMappings = ['foo' => ['type' => 'text'], 'bar' => ['type' => 'entity', 'targetEntity' => 'Acme/Entity/Foo']]; $reflFoo->getValue($entity)->willReturn(16); $entityManager->getReference('Acme/Entity/Foo', 16)->willReturn($foo16); $reflFoo->setValue($entity, $foo16)->shouldBeCalled(); $this->postLoad($args); }
/** * Runs static repository restriction query and stores it state into snapshot entity * * @param Segment $segment * * @throws \LogicException * @throws \Exception */ public function run(Segment $segment) { if ($segment->getType()->getName() !== SegmentType::TYPE_STATIC) { throw new \LogicException('Only static segments could have snapshots.'); } $this->em->getRepository('OroSegmentBundle:SegmentSnapshot')->removeBySegment($segment); $qb = $this->dynamicSegmentQB->build($segment); $iterator = new BufferedQueryResultIterator($qb); $writeCount = 0; try { $this->em->beginTransaction(); $this->em->clear(ClassUtils::getClass($segment)); foreach ($iterator as $data) { // only not composite identifiers are supported $id = reset($data); $writeCount++; /** @var Segment $reference */ $reference = $this->em->getReference(ClassUtils::getClass($segment), $segment->getId()); $snapshot = new SegmentSnapshot($reference); $snapshot->setEntityId($id); $this->toWrite[] = $snapshot; if (0 === $writeCount % $this->batchSize) { $this->write($this->toWrite); $this->toWrite = []; } } if (count($this->toWrite) > 0) { $this->write($this->toWrite); } $this->em->commit(); } catch (\Exception $exception) { $this->em->rollback(); throw $exception; } $segment = $this->em->merge($segment); $segment->setLastRun(new \DateTime('now', new \DateTimeZone('UTC'))); $this->em->persist($segment); $this->em->flush(); }
/** * {@inheritdoc} */ public function move($id, $locale, $destCollection) { try { $mediaEntity = $this->mediaRepository->findMediaById($id); if ($mediaEntity === null) { throw new MediaNotFoundException($id); } $mediaEntity->setCollection($this->em->getReference(self::ENTITY_NAME_COLLECTION, $destCollection)); $this->em->flush(); return $this->addFormatsAndUrl(new Media($mediaEntity, $locale, null)); } catch (DBALException $ex) { throw new CollectionNotFoundException($destCollection); } }