当前位置: 首页>>代码示例>>PHP>>正文


PHP ObjectManager::flush方法代码示例

本文整理汇总了PHP中Doctrine\Common\Persistence\ObjectManager::flush方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManager::flush方法的具体用法?PHP ObjectManager::flush怎么用?PHP ObjectManager::flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Common\Persistence\ObjectManager的用法示例。


在下文中一共展示了ObjectManager::flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load

 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $user = $this->createUser('sylius@example.com', 'sylius', true, ['ROLE_USER', 'ROLE_ADMINISTRATION_ACCESS']);
     $user->addAuthorizationRole($this->get('sylius.repository.role')->findOneBy(['code' => 'administrator']));
     $manager->persist($user);
     $manager->flush();
     $this->setReference('Sylius.User-Administrator', $user);
     for ($i = 1; $i <= 15; ++$i) {
         $username = $this->faker->username;
         while (isset($this->usernames[$username])) {
             $username = $this->faker->username;
         }
         $user = $this->createUser($username . '@example.com', $username, $this->faker->boolean());
         $user->setCreatedAt($this->faker->dateTimeThisMonth);
         $manager->persist($user);
         $this->usernames[$username] = true;
         $this->setReference('Sylius.User-' . $i, $user);
         $this->setReference('Sylius.Customer-' . $i, $user->getCustomer());
     }
     $customer = $this->getCustomerFactory()->createNew();
     $customer->setFirstname($this->faker->firstName);
     $customer->setLastname($this->faker->lastName);
     $customer->setEmail('customer@email.com');
     $manager->persist($customer);
     $manager->flush();
 }
开发者ID:polisys,项目名称:Sylius,代码行数:29,代码来源:LoadUsersData.php

示例2: process

 /**
  * Process form
  *
  * @param  EmailTemplate $entity
  *
  * @return bool True on successful processing, false otherwise
  */
 public function process(EmailTemplate $entity)
 {
     // always use default locale during template edit in order to allow update of default locale
     $entity->setLocale($this->defaultLocale);
     if ($entity->getId()) {
         // refresh translations
         $this->manager->refresh($entity);
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         // deny to modify system templates
         if ($entity->getIsSystem() && !$entity->getIsEditable()) {
             $this->form->addError(new FormError($this->translator->trans('oro.email.handler.attempt_save_system_template')));
             return false;
         }
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             // mark an email template creating by an user as editable
             if (!$entity->getId()) {
                 $entity->setIsEditable(true);
             }
             $this->manager->persist($entity);
             $this->manager->flush();
             return true;
         }
     }
     return false;
 }
开发者ID:Maksold,项目名称:platform,代码行数:35,代码来源:EmailTemplateHandler.php

示例3: load

 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $tipo1 = new Status();
     $tipo1->setName("Pendiente");
     $manager->persist($tipo1);
     $manager->flush();
     $this->addReference('estado-pendiente', $tipo1);
     $tipo2 = new Status();
     $tipo2->setName("Procesando");
     $manager->persist($tipo2);
     $manager->flush();
     $this->addReference('estado-procesando', $tipo2);
     $tipo3 = new Status();
     $tipo3->setName("Enviado");
     $manager->persist($tipo3);
     $manager->flush();
     $this->addReference('estado-enviado', $tipo3);
     $tipo4 = new Status();
     $tipo4->setName("Entregado");
     $manager->persist($tipo4);
     $manager->flush();
     $this->addReference('estado-entregado', $tipo4);
     $tipo5 = new Status();
     $tipo5->setName("Cancelado");
     $manager->persist($tipo5);
     $manager->flush();
     $this->addReference('estado-cancelado', $tipo5);
 }
开发者ID:pam81,项目名称:delivery,代码行数:31,代码来源:LoadStatusData.php

示例4: onSuccess

 /**
  * "Success" form handler
  *
  * @param Role            $entity
  * @param UserInterface[] $appendUsers
  * @param UserInterface[] $removeUsers
  */
 protected function onSuccess(Role $entity, array $appendUsers, array $removeUsers)
 {
     $this->appendUsers($entity, $appendUsers);
     $this->removeUsers($entity, $removeUsers);
     $this->manager->persist($entity);
     $this->manager->flush();
 }
开发者ID:aml-bendall,项目名称:ExpandAkeneoApi,代码行数:14,代码来源:RoleHandler.php

示例5: load

 public function load(ObjectManager $manager)
 {
     $yaml = new Parser();
     // TODO: find a way of obtainin Bundle's path with the help of $this->container
     $bpath = $this->container->get('kernel')->getBundle('SiwappEstimateBundle')->getPath();
     $value = $yaml->parse(file_get_contents($bpath . '/DataFixtures/estimates.yml'));
     foreach ($value['Item'] as $ref => $values) {
         $item = new Item();
         $estimate = new Estimate();
         foreach ($values as $fname => $fvalue) {
             if ($fname == 'Estimate') {
                 $fvalue = $manager->merge($this->getReference($fvalue));
                 $fvalue->addItem($item);
                 $manager->persist($fvalue);
             }
             $method = 'set' . Inflector::camelize($fname);
             if (is_callable(array($item, $method))) {
                 call_user_func(array($item, $method), $fvalue);
             }
         }
         $manager->persist($item);
         $manager->flush();
         $this->addReference($ref, $item);
     }
     foreach ($value['ItemTax'] as $ref => $values) {
         $item = $this->getReference($values['Item']);
         $tax = $this->getReference($values['Tax']);
         $item->addTax($tax);
         $manager->persist($item);
         $manager->flush();
     }
 }
开发者ID:siwapp,项目名称:siwapp-sf3,代码行数:32,代码来源:LoadItemData.php

示例6: load

 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     // T-Shirts...
     for ($i = 1; $i <= 120; ++$i) {
         switch (rand(0, 3)) {
             case 0:
                 $manager->persist($this->createTShirt($i));
                 break;
             case 1:
                 $manager->persist($this->createSticker($i));
                 break;
             case 2:
                 $manager->persist($this->createMug($i));
                 break;
             case 3:
                 $manager->persist($this->createBook($i));
                 break;
         }
         if (0 === $i % 20) {
             $manager->flush();
         }
     }
     $manager->flush();
     $this->defineTotalVariants();
 }
开发者ID:vikey89,项目名称:Sylius,代码行数:28,代码来源:LoadProductsData.php

示例7: load

 public function load(ObjectManager $manager)
 {
     /** @var Team $team1 */
     $team1 = $this->getReference('team-1');
     for ($i = 1; $i < 11; $i++) {
         $player = new Player();
         $player->setFirstName('FirstName ' . $i);
         $player->setLastName('LastName ' . $i);
         $player->setBirthdate(new \DateTime());
         $player->setPosition('guard');
         $player->addTeam($team1);
         $manager->persist($player);
     }
     $manager->flush();
     /** @var Team $team2 */
     $team2 = $this->getReference('team-2');
     for ($i = 11; $i < 21; $i++) {
         $player = new Player();
         $player->setFirstName('FirstName ' . $i);
         $player->setLastName('LastName ' . $i);
         $player->setBirthdate(new \DateTime());
         $player->setPosition('guard');
         $player->addTeam($team2);
         $manager->persist($player);
     }
     $manager->flush();
 }
开发者ID:pinoniq,项目名称:tritonleuven.be,代码行数:27,代码来源:LoadPlayerData.php

示例8: delete

 /**
  * @param LocationModel $location
  * @param bool          $withFlush
  */
 public function delete(LocationModel $location, $withFlush = true)
 {
     $this->objectManager->remove($location);
     if ($withFlush) {
         $this->objectManager->flush();
     }
 }
开发者ID:Appartin,项目名称:CoreBundle,代码行数:11,代码来源:LocationManager.php

示例9: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->init();
     $limit = 50;
     $offset = 0;
     $repository = $this->em->getRepository('AppBundle:Sale');
     $existingInvoices = $repository->findExistingInvoices();
     try {
         $json = $this->getSales($limit, $offset);
         $this->saveSales($json['sales'], $existingInvoices);
         $output->writeln('Saving bunch of sales...');
         $total = $json['numSales'];
         $this->em->flush();
         do {
             $offset += $limit;
             $json = $this->getSales($limit, $offset);
             $this->saveSales($json['sales'], $existingInvoices);
             $output->writeln('Saving bunch of sales...');
             $this->em->flush();
         } while ($total > $limit + $offset);
     } catch (\Exception $e) {
         $output->writeln($e->getMessage());
         return;
     }
     $output->writeln(sprintf('Imported %s sales', $total));
 }
开发者ID:nmuldoon,项目名称:atlassian-vendor-tools,代码行数:26,代码来源:ImportSaleCommand.php

示例10: importUsers

 /**
  * Import Users
  */
 private function importUsers()
 {
     $this->output->write(sprintf('%-30s', 'Importing users'));
     $previewUsers = $this->previewService->getUsers();
     $created = 0;
     $updated = 0;
     foreach ($previewUsers as $previewUser) {
         if (!strlen($previewUser->email)) {
             continue;
         }
         /**
          * @var User $user
          */
         $user = $this->entityManager->getRepository('ProjectPreviewUserBundle:User')->find($previewUser->id);
         if (is_null($user)) {
             $user = new User();
             $user->setId($previewUser->id);
             $user->setPassword('toto');
             $created++;
         } else {
             $updated++;
         }
         $user->setEmail($previewUser->email);
         $user->setUsername($previewUser->email);
         $user->setLastname($previewUser->lastname);
         $user->setFirstname($previewUser->firstname);
         if (isset($previewUser->avatar->urls->avatar_xs)) {
             $user->setAvatar($previewUser->avatar->urls->avatar_xs);
         }
         $this->entityManager->persist($user);
     }
     $this->output->writeln(sprintf('done (total: % 4d, created: % 4d, updated: % 4d)', $created + $updated, $created, $updated));
     $this->entityManager->flush();
 }
开发者ID:xavier-dubreuil,项目名称:ProjectPreview,代码行数:37,代码来源:ImportUsersCommand.php

示例11: load

 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $data = $this->userFixtureDataSource();
     // Have to keep a reference to all the user objects
     // or else they can't be flushed all at once.
     $items = array();
     $user = new User();
     foreach ($data['User'] as $item) {
         $user = new User();
         $user->setUuid($item['uuid'])->setUsername($item['username'])->setPassword($item['password'])->setEmail($item['email'])->setIsActive($item['is_active']);
         $this->addReference($user->getUuid(), $user);
         $items[] = $user;
         $manager->persist($user);
     }
     $manager->flush();
     $items = array();
     foreach ($data['Record'] as $item) {
         $record = new Record();
         $record->setCategory($item['category'])->setKey($item['aKey'])->setData($item['data'])->setOwner($manager->merge($this->getReference($item['owner_uuid'])));
         $timestamp = new \DateTime('now');
         if (!empty($item['timestamp'])) {
             $timestamp->setTimestamp($item['timestamp']);
         }
         $record->setTimestamp($timestamp);
         $items[] = $record;
         $manager->persist($record);
     }
     $manager->flush();
 }
开发者ID:Rud5G,项目名称:VirtualPersistAPI,代码行数:32,代码来源:LoadAPIControllerTestData.php

示例12: createMenuItems

 /**
  * @param \Doctrine\Common\Persistence\ObjectManager $manager
  * @param $locale
  */
 public function createMenuItems(ObjectManager $manager, $locale)
 {
     $menuRoot = new MenuItem();
     $menuRoot->setName('Main menu');
     $menuRoot->setLocale($locale);
     $menuRoot->setIsRoot(true);
     $menuRoot->setLvl(1);
     $menuRoot->setLft(1);
     $menuRoot->setRgt(2);
     $manager->persist($menuRoot);
     $manager->flush();
     $homePageMenu = new MenuItem();
     $homePageMenu->setName('Homepage');
     $homePageMenu->setPage($this->getReference('homepage_' . $locale));
     $homePageMenu->setParent($menuRoot);
     $manager->persist($homePageMenu);
     $manager->flush();
     $footerRoot = new MenuItem();
     $footerRoot->setName('Footer menu');
     $footerRoot->setLocale($locale);
     $footerRoot->setIsRoot(true);
     $footerRoot->setLvl(1);
     $footerRoot->setLft(1);
     $footerRoot->setRgt(2);
     $manager->persist($footerRoot);
     $manager->flush();
 }
开发者ID:rapemer,项目名称:init-cms-bundle,代码行数:31,代码来源:LoadMenu.php

示例13: load

 public function load(ObjectManager $manager)
 {
     // Les variables
     $listCours = array('Français', 'Math', 'Allemand');
     $classeName = "8P7";
     $classeDescription = "La classe 8P7 de Mme Gomez";
     $classe = new Classe();
     $classe->setName($classeName);
     $classe->setDescription($classeDescription);
     $manager->persist($classe);
     $manager->flush();
     $em = $this->container->get('doctrine')->getEntityManager('default');
     $repository = $em->getRepository('Sulaz1xSecurityBundle:User');
     $students = $repository->findAll();
     foreach ($students as $student) {
         $student->setClasse($classe);
         $manager->persist($student);
     }
     foreach ($listCours as $coursname) {
         // On crée l'utilisateur
         $cours = new Cours();
         // Le nom d'utilisateur et le mot de passe sont identiques
         $cours->setName($coursname);
         $cours->setDescription("Un cours de test");
         $cours->setStart(new \Datetime('25-08-2015'));
         $cours->setEnd(new \Datetime('25-07-2016'));
         $classe->addCours($cours);
         $manager->persist($cours);
         $manager->persist($classe);
     }
     // On déclenche l'enregistrement
     $manager->flush();
 }
开发者ID:sulazix,项目名称:lescrapules,代码行数:33,代码来源:LoadDefault.php

示例14: load

 public function load(ObjectManager $manager)
 {
     $category1 = new Categories();
     $category1->setName("DECORATION");
     $category1->setCreated(new \DateTime('now '));
     $category1->setUpdated(new \DateTime('now '));
     $this->addReference("category1", $category1);
     $manager->persist($category1);
     $manager->flush();
     $category2 = new Categories();
     $category2->setName("TABLEAUX");
     $category2->setCreated(new \DateTime('now '));
     $category2->setUpdated(new \DateTime('now '));
     $this->addReference("category2", $category2);
     $manager->persist($category2);
     $manager->flush();
     $category3 = new Categories();
     $category3->setName("BOUGEOIRS");
     $category3->setCreated(new \DateTime('now '));
     $category3->setUpdated(new \DateTime('now '));
     $this->addReference("category3", $category3);
     $manager->persist($category3);
     $manager->flush();
     $category4 = new Categories();
     $category4->setName("MAISON");
     $category4->setCreated(new \DateTime('now '));
     $category4->setUpdated(new \DateTime('now '));
     $this->addReference("category4", $category4);
     $manager->persist($category4);
     $manager->flush();
 }
开发者ID:resing,项目名称:store,代码行数:31,代码来源:LoadCategory.php

示例15: load

 public function load(ObjectManager $manager)
 {
     $projectPhoto = new ProjectPhoto();
     $projectPhoto->setFilename('slide1.jpg');
     $projectPhoto->setProject($this->getReference('project1'));
     $manager->persist($projectPhoto);
     $manager->flush();
     $projectPhoto = new ProjectPhoto();
     $projectPhoto->setFilename('slide2.jpg');
     $projectPhoto->setProject($this->getReference('project1'));
     $manager->persist($projectPhoto);
     $manager->flush();
     $projectPhoto = new ProjectPhoto();
     $projectPhoto->setFilename('slide3.jpg');
     $projectPhoto->setProject($this->getReference('project1'));
     $manager->persist($projectPhoto);
     $manager->flush();
     $projectPhoto = new ProjectPhoto();
     $projectPhoto->setFilename('slide4.jpg');
     $projectPhoto->setProject($this->getReference('project1'));
     $manager->persist($projectPhoto);
     $manager->flush();
     $projectPhoto = new ProjectPhoto();
     $projectPhoto->setFilename('slide5.jpg');
     $projectPhoto->setProject($this->getReference('project1'));
     $manager->persist($projectPhoto);
     $manager->flush();
 }
开发者ID:OscarAvR,项目名称:web_specialisatie_poc,代码行数:28,代码来源:LoadProjectPhotoData.php


注:本文中的Doctrine\Common\Persistence\ObjectManager::flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。