persist() 공개 메소드

The document will be entered into the database at or before transaction commit or as a result of the flush operation. NOTE: The persist operation always considers documents that are not yet known to this DocumentManager as NEW. Do not pass detached documents to the persist operation.
public persist ( object $document )
$document object The instance to make managed and persistent.
예제 #1
0
 public function updateAttendee(AttendeeInterface $attendee)
 {
     $attendee->setUpdatedAt(new \DateTime());
     $this->em->persist($attendee);
     $this->em->flush();
     return true;
 }
예제 #2
0
 protected function createImage(LoaderResult $loaderResult, $mimeType) : ImageInterface
 {
     $image = ($image = new Image())->setPath($loaderResult->getPath())->setSize($loaderResult->getSize())->setMimeType($mimeType)->setUploadedAt(new \DateTime());
     $this->dm->persist($image);
     $this->dm->flush($image);
     return $image;
 }
 /**
  * @param string $uniqueKey
  */
 public function track(DuplicableInterface $duplicable)
 {
     $duplicateEmail = new Duplication();
     $duplicateEmail->setTrackingDate(new \DateTime('now'))->setUniqueKey($duplicable->getUniqueKey());
     $this->dm->persist($duplicateEmail);
     $this->dm->flush($duplicateEmail);
 }
예제 #4
0
 public function create($username, $password, $roles)
 {
     $user = new Document\User();
     $user->setUsername($username)->setPassword($password)->setRoles($roles);
     $this->manager->persist($user);
     $this->manager->flush();
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $model = $input->getArgument('model');
     $seeds = $input->getArgument('seeds');
     $io = new SymfonyStyle($input, $output);
     if (!class_exists($model)) {
         $io->error(array('The model you specified does not exist.', 'You can create a model with the "model:create" command.'));
         return 1;
     }
     $this->dm = $this->createDocumentManager($input->getOption('server'));
     $faker = Faker\Factory::create();
     AnnotationRegistry::registerAutoloadNamespace('Hive\\Annotations', dirname(__FILE__) . '/../../');
     $reflectionClass = new \ReflectionClass($model);
     $properties = $reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC);
     $reader = new AnnotationReader();
     for ($i = 0; $i < $seeds; $i++) {
         $instance = new $model();
         foreach ($properties as $property) {
             $name = $property->getName();
             $seed = $reader->getPropertyAnnotation($property, 'Hive\\Annotations\\Seed');
             if ($seed !== null) {
                 $fake = $seed->fake;
                 if (class_exists($fake)) {
                     $instance->{$name} = $this->createFakeReference($fake);
                 } else {
                     $instance->{$name} = $faker->{$seed->fake};
                 }
             }
         }
         $this->dm->persist($instance);
     }
     $this->dm->flush();
     $io->success(array("Created {$seeds} seeds for {$model}"));
 }
 /**
  *  Loads all fixtures data into the testing database
  * @return $this
  */
 public function loadData()
 {
     $email = new EmailDocument('*****@*****.**');
     $this->odm->persist($email);
     $this->odm->flush();
     return $this;
 }
 function save($entity, $flush = 1)
 {
     $this->dm->persist($entity);
     if (1 == $flush) {
         $this->dm->flush($entity);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function updatePartner(PartnerInterface $partner, $andFlush = true)
 {
     $this->dm->persist($partner);
     if ($andFlush) {
         $this->dm->flush();
     }
 }
 /**
  * @return Form
  */
 public function testFormNew()
 {
     $form = new Form();
     $form->setName(static::$formName);
     $this->dm->persist($form);
     $this->dm->flush();
     return $form;
 }
예제 #10
0
 public function generateInvoice(Order $order)
 {
     $document = $this->createDocumentFromOrder($order);
     $this->eventDispatcher->dispatch(DocumentEvent::INVOICE_GENERATE_START, new DocumentEvent($document));
     $this->documentManager->persist($document);
     $this->documentManager->flush();
     $this->documentProducer->publish($document->getId(), 'document.invoice');
 }
예제 #11
0
 public function factory($userUri, $trackId)
 {
     $entry = new TrackDoc();
     $entry->setUserUri($userUri);
     $entry->setBrowserTrackId($trackId);
     $this->dm->persist($entry);
     return $entry;
 }
예제 #12
0
 /**
  * @return AbstractImportSession
  */
 protected function createSession()
 {
     /** @var AbstractImportSession $session */
     $session = new $this->sessionClassName();
     $session->setPhase($this->phasesStack->current()->getName())->setProvider($this->getName());
     $this->documentManager->persist($session);
     return $session;
 }
예제 #13
0
 /**
  * Persists a vote.
  *
  * @param VoteInterface $vote
  * @param VotableCommentInterface $comment
  * @return void
  */
 public function addVote(VoteInterface $vote, VotableCommentInterface $comment)
 {
     $vote->setComment($comment);
     $comment->setScore($comment->getScore() + $vote->getValue());
     $this->dm->persist($comment);
     $this->dm->persist($vote);
     $this->dm->flush();
 }
예제 #14
0
 /**
  * @param Aggregate $aggregate
  */
 public function add(Aggregate $aggregate)
 {
     foreach ($aggregate->getEvents() as $event) {
         $storedEvent = new StoredEvent($aggregate->getAggregateId(), get_class($event), $event);
         $this->manager->persist($storedEvent);
     }
     $this->manager->flush();
 }
예제 #15
0
파일: Currency.php 프로젝트: lexx7/course
 /**
  * Сохранение позиции в бд
  * @param $charCode
  * @param $item
  */
 protected function save($charCode, $item)
 {
     /** @var Courses $courses */
     $courses = $this->_repository->findOneBy(array('charCode' => $charCode));
     if (!$courses) {
         $courses = new Courses();
     }
     $document = $this->mergeFromArray($courses, (array) $item);
     $this->_dm->persist($document);
 }
예제 #16
0
 /**
  * {@inheritdoc}
  */
 public function associateScope(AccessTokenEntity $token, ScopeEntity $scopeEntity)
 {
     /** @var AccessToken $accessToken */
     $accessToken = $this->dm->getRepository(AccessToken::class)->find($token->getId());
     /** @var Scope $scope */
     $scope = $this->dm->getRepository(Scope::class)->find($scopeEntity->getId());
     $accessToken->associateScope($scope);
     $this->dm->persist($accessToken);
     $this->dm->flush($accessToken);
 }
 /**
  * @return Protocol
  */
 public function testCreateProtocol()
 {
     $form = new Form();
     $form->setName(static::$formName);
     $this->dm->persist($form);
     $protocol = new Protocol();
     $protocol->setForm($form);
     $this->dm->persist($protocol);
     $this->dm->flush();
     return $protocol;
 }
 public function testFindPartner()
 {
     $p = $this->partnerMgr->createPartner(Partner::ROLE_CUSTOMER, Partner::ORGANISATION);
     $p->setPartnerId('PartnerTest002');
     $p->addRole(Partner::ROLE_EMPLOYEE);
     $this->dm->persist($p);
     $this->dm->flush();
     $partner = $this->partnerMgr->findOneByPartnerId('PartnerTest002');
     $this->assertTrue($partner instanceof PartnerInterface);
     $this->assertEquals(Partner::ORGANISATION, $partner->getType());
     $this->assertEquals(array(Partner::ROLE_CUSTOMER, Partner::ROLE_EMPLOYEE), $partner->getRoles());
 }
예제 #19
0
 /**
  * @param string      $itemId
  * @param array       $data
  * @param string|null $collection
  * @return Item
  */
 public function post($itemId, array $data, $collection = null)
 {
     $this->setCollection($collection);
     // create new Item
     $item = new Item();
     $item->setId($itemId);
     $item->setAttributes($data);
     // save
     $this->dm->persist($item);
     $this->dm->flush();
     return $item;
 }
예제 #20
0
 public function set($key, $var, $ttl = self::DEFAULT_TTL)
 {
     $cache = $this->dm->getRepository('SGLiveChatBundle:CacheEntry')->getByKey($key);
     if (!$cache) {
         $cache = new CacheEntry();
         $cache->setKey($key);
         $this->dm->persist($cache);
     }
     $cache->setTtl($ttl);
     $cache->setData($var);
     $this->dm->flush();
     return true;
 }
예제 #21
0
 /**
  * Creates User, specially for fixtures
  *
  * @param array $userData
  *
  * @return BackendUser $user
  */
 public function registerFixturesUser(array $userData)
 {
     $user = new BackendUser();
     $user->setEmail($userData['email']);
     $user->setUsername($userData['username']);
     $user->setPlainPassword($userData['password']);
     $user->setEnabled(true);
     $user->setLocked(false);
     $user->setLastLogin(new \DateTime(date('Y-m-d H:i:s')));
     $this->dm->persist($user);
     $this->dm->flush();
     return $user;
 }
 private function persistEmailMessage(Message $message, $type, $status, $arguments)
 {
     $email = new Email();
     $email->setType($type);
     $email->setBody($message->getMessage());
     $email->setEmailAddress($message->getTo());
     $email->setFrom($message->getFrom());
     $email->setSubject($message->getSubject());
     $email->setArguments($arguments);
     $email->setStatus($status);
     $this->documentManager->persist($email);
     $this->documentManager->flush();
 }
 /**
  * @param User $user
  * @param $date
  * @param $lineNumber
  * @param $from
  * @param $to
  * @param $lineDeparture
  * @param int $continuation
  * @return Ticket|null
  */
 public function buyTicket(User $user, $date, $lineNumber, $from, $to, $lineDeparture, $continuation = 0)
 {
     // Get Trip
     $trip = $this->documentManager->getRepository('AppBundle:Trip')->findOneBy(['date' => $date, 'lineNumber' => (int) $lineNumber, 'departure' => (int) $lineDeparture]);
     // If doesn't exists
     if (!$trip) {
         // Check lineNumber | from | to | lineDeparture
         if (!($line = $this->trainInformation->verifyLine($lineNumber, $from, $to, $lineDeparture))) {
             throw new BadRequestHttpException('Invalid trip.');
         }
         // Create Trip
         $trip = new Trip($lineNumber, $line['stations'], $date, $lineDeparture, $this->trainInformation->getCapacity());
     }
     // Get Train capacity
     if ($trip->getAvailableCapacity($from, $to) == 0) {
         throw new BadRequestHttpException('Trip is full.');
     }
     if ($continuation == 1 && !$this->creditCardValidator->validate($user->getCreditCard())) {
         throw new BadRequestHttpException('Credit Card failed.');
     }
     // Create Ticket
     $ticket = new Ticket($user, $trip, $from, $to);
     // Update Trip
     $trip->addTicketBought($from, $to);
     // Persist
     $this->documentManager->persist($ticket);
     $this->documentManager->persist($trip);
     $this->documentManager->flush();
     return $ticket;
 }
예제 #24
0
 /**
  * Update parent for Node
  *
  * @param  array $params
  * @return Category $child
  *
  * @throws LogicException
  */
 public function updateParent($params)
 {
     /**
      * @var $child Category
      * @var $parent Category
      */
     $repo = $this->dm->getRepository($this->model);
     if ($categoryParentId = $params['parentId']) {
         $parent = $repo->find($categoryParentId);
         if (!$parent) {
             throw new LogicException('Nothing found');
         }
     }
     if ($categoryId = $params['id']) {
         $child = $repo->find($categoryId);
         if (!$child) {
             throw new LogicException('Nothing found');
         }
     }
     $child->setParent($parent);
     $this->dm->persist($child);
     $this->dm->flush();
     $parent->removeChild($child);
     $parent->addChild($child);
     $this->dm->persist($parent);
     $this->dm->flush();
     return $child;
 }
 /**
  * @param Doctrine\ODM\MongoDB\DocumentManager $documentManager
  */
 private function _save(DocumentManager $documentManager)
 {
     try {
         if ($this->queue->count() <= 0) {
             $this->getLog()->debug('Queue contains no documents for processing.');
             return;
         }
         $this->getLog()->debug('Queue contains: ' . $this->queue->count() . ' documents.');
         foreach ($this->queue as $object) {
             $name = $object->getName();
             $_id = $object->getId();
             if (empty($_id)) {
                 $document = $object->getInstance();
                 $this->getLog()->info('Saving document: ' . $name . ' (' . $document->__toString() . ')');
                 //Debug::dump($document, 3);
                 $documentManager->persist($document);
                 $documentManager->flush();
                 $documentId = $document->getId();
                 if (!empty($name) && !empty($documentId)) {
                     $this->getLog()->info('Marking document: ' . $name . ' (' . get_class($document) . ') as persisted in cache with ID: ' . $documentId);
                     $this->markAsPersisted($name, $documentId, $document);
                 }
             }
         }
         $this->queue->clear();
         $this->getLog()->debug('Finished saving documents, queue now contains: ' . $this->queue->count() . ' documents.');
     } catch (\Exception $ex) {
         $this->getLog()->err('An error occurred while attempting to save one or more documents. ' . get_class($ex) . ' handled, with message: ' . $ex->getMessage());
         $documentManager->close();
         throw $ex;
     }
 }
예제 #26
0
 /**
  * Create invoice for order Id
  *
  * @param Order $order
  *
  * @return Invoice $invoice|false
  *
  */
 public function createInvoiceForOrder(Order $order)
 {
     if ($order) {
         if (!$order->getInvoice()) {
             $invoice = new Invoice();
             $this->dm->persist($invoice);
             $this->dm->flush();
             // Update order data
             $order->setInvoice($invoice);
             $this->dm->persist($order);
             $this->dm->flush();
             return $invoice;
         }
     }
     return false;
 }
예제 #27
0
 /**
  * Saves a message
  *
  * @param MessageInterface $message
  * @param Boolean $andFlush Whether to flush the changes (default true)
  */
 public function saveMessage(MessageInterface $message, $andFlush = true)
 {
     $message->denormalize();
     $this->dm->persist($message);
     if ($andFlush) {
         $this->dm->flush();
     }
 }
예제 #28
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $limit = $input->getOption('limit');
     $emailsRepository = $this->documentManager->getRepository(Email::REPOSITORY);
     $emails = $emailsRepository->findBy(array('status' => Email::STATUS_TEMPORARY_ERROR), null, $limit);
     foreach ($emails as $email) {
         /* @var $email Email */
         $type = $email->getType();
         $emailAddress = $email->getEmailAddress();
         $arguments = $email->getArguments();
         $this->eventDispatcher->dispatch(EmailEvent::RESEND, new EmailEvent($type, $emailAddress, $arguments));
         $status = $this->communicationService->sendEmail($type, $emailAddress, $arguments);
         $email->setStatus($status);
         $this->documentManager->persist($email);
     }
     $this->documentManager->flush();
 }
예제 #29
0
 /**
  * Saves a thread
  *
  * @param ThreadInterface $thread
  * @param Boolean $andFlush Whether to flush the changes (default true)
  */
 public function saveThread(ThreadInterface $thread, $andFlush = true)
 {
     $this->denormalize($thread);
     $this->dm->persist($thread);
     if ($andFlush) {
         $this->dm->flush();
     }
 }
 public function testManyToManyReferences()
 {
     $categoryOne = new Category('one');
     $this->dm->persist($categoryOne);
     $categoryTwo = new Category('two');
     $this->dm->persist($categoryTwo);
     $document = new Document(new \MongoId(), 'document');
     $document->categories[] = $categoryOne;
     $this->dm->persist($document);
     $this->dm->flush();
     $form = $this->factory->create($this->typeFQCN ? FormType::CLASS : 'form', $document)->add('categories', $this->typeFQCN ? DocumentType::CLASS : 'document', ['class' => Category::class, 'multiple' => true, 'expanded' => true, 'document_manager' => 'default']);
     $view = $form->createView();
     $categoryView = $view['categories'];
     $this->assertInstanceOf(FormView::class, $categoryView);
     $this->assertCount(2, $categoryView->children);
     $this->assertTrue($categoryView->children[0]->vars['checked']);
     $this->assertFalse($categoryView->children[1]->vars['checked']);
 }