setPurgeMode() 공개 메소드

Set the purge mode
public setPurgeMode ( $mode ) : void
$mode
리턴 void
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getEntityManager();
     if ($input->isInteractive() && !$input->getOption('append')) {
         if (!$this->askConfirmation($input, $output, '<question>Careful, database will be purged. Do you want to continue y/N ?</question>', false)) {
             return;
         }
     }
     $app = $this->getApp();
     $path = $app->getApplicationBase($app->getAppNamespace()) . '/DataFixture';
     $loader = new DataFixturesLoader();
     $loader->loadFromDirectory($path);
     $fixtures = $loader->getFixtures();
     if (!$fixtures) {
         throw new InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- {$path}"));
     }
     foreach ($fixtures as $fixture) {
         if ($fixture instanceof ContainerAwareInterface) {
             $fixture->setContainer($this->getContainer());
         }
     }
     $purger = new ORMPurger($em);
     if ($input->getOption('truncate-only')) {
         $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);
         $purger->purge();
         exit(0);
     }
     $purger->setPurgeMode($input->getOption('truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
     $executor = new ORMExecutor($em, $purger);
     $executor->setLogger(function ($message) use($output) {
         $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
     });
     $executor->execute($fixtures, $input->getOption('append'));
 }
예제 #2
0
 /**
  * Loads data fixtures (ported from LoadDataFixturesDoctrineCommand class)
  *
  * @throws \Codeception\Exception\Module
  */
 public function reloadFixtures()
 {
     $container = $this->getModule('Symfony2')->container;
     $kernel = $this->getModule('Symfony2')->kernel;
     $doctrine = $container->get('doctrine');
     $em = $doctrine->getManager();
     $paths = array();
     foreach ($kernel->getBundles() as $bundle) {
         $paths[] = $bundle->getPath() . '/DataFixtures/ORM';
     }
     $loader = new DataFixturesLoader($container);
     foreach ($paths as $path) {
         if (is_dir($path)) {
             $loader->loadFromDirectory($path);
         }
     }
     $fixtures = $loader->getFixtures();
     if (!$fixtures) {
         throw new InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- " . implode("\n- ", $paths)));
     }
     $purger = new ORMPurger($em);
     $purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE);
     $executor = new ORMExecutor($em, $purger);
     $executor->execute($fixtures, false);
 }
예제 #3
0
 protected function tearDown()
 {
     $purger = new ORMPurger($this->getDoctrine()->getManager());
     $purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE);
     $purger->purge();
     parent::tearDown();
 }
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $app = $this->getApplication()->getApp();
     $em = $app['em'];
     $dirOrFile = $input->getOption('fixtures');
     if ($dirOrFile) {
         $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
     } else {
         $paths = isset($app['em.fixtures']) ? $app['em.fixtures'] : array();
     }
     $loader = new Loader();
     foreach ($paths as $path) {
         if (is_dir($path)) {
             $loader->loadFromDirectory($path);
         }
     }
     $fixtures = $loader->getFixtures();
     if (!$fixtures) {
         throw new InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- " . implode("\n- ", $paths)));
     }
     $purger = new ORMPurger($em);
     $purger->setPurgeMode($input->getOption('purge-with-truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
     $executor = new ORMExecutor($em, $purger);
     $executor->setLogger(function ($message) use($output) {
         $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
     });
     $executor->execute($fixtures, $input->getOption('append'));
 }
예제 #5
0
 /**
  * {@inheritDoc}
  */
 public function setUp()
 {
     self::bootKernel();
     $this->em = static::$kernel->getContainer()->get('doctrine')->getManager("dblog");
     $purger = new ORMPurger($this->em);
     $purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE);
     $purger->purge();
 }
예제 #6
0
 /**
  * {@inheritDoc}
  */
 public function setUp()
 {
     self::bootKernel();
     $this->em = static::$kernel->getContainer()->get('doctrine')->getManager("dblog");
     $this->rep = $this->em->getRepository("MaallsDBLogBundle:DbLog");
     $purger = new ORMPurger($this->em);
     $purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE);
     $purger->purge();
 }
예제 #7
0
 protected function doPurgeFixtures()
 {
     $purger = new ORMPurger();
     $purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE);
     $managers = $this->getContainer()->get('doctrine')->getManagerNames();
     foreach ($managers as $name => $service) {
         $purger->setEntityManager($this->getEntityManager($name));
         $purger->purge();
     }
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function beforeSuite(SuiteEvent $suiteEvent, array $options)
 {
     foreach ($options['managers'] as $managerName) {
         /** @var EntityManagerInterface $manager */
         $manager = $this->managerRegistry->getManager($managerName);
         $purger = new ORMPurger($manager);
         $purger->setPurgeMode(static::$purgeModes[$options['mode']]);
         $purger->purge();
     }
 }
예제 #9
0
 /**
  * This is a performance improvement.
  * https://github.com/KnpLabs/FriendlyContexts/issues/195
  *
  * @BeforeScenario
  */
 public function beforeScenario($event)
 {
     $this->storeTags($event);
     if ($this->hasTags(['reset-schema', '~not-reset-schema'])) {
         $em = $this->get('doctrine')->getManager();
         $em->getConnection()->executeUpdate("SET FOREIGN_KEY_CHECKS=0;");
         $purger = new ORMPurger($em);
         $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);
         $purger->purge();
         $em->getConnection()->executeUpdate("SET FOREIGN_KEY_CHECKS=1;");
     }
 }
예제 #10
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $loader = new Loader();
     $purger = new ORMPurger();
     $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);
     $executor = new ORMExecutor($this->em, $purger);
     $loader->loadFromDirectory($this->mainDir);
     foreach ($this->dirs as $dir) {
         $loader->loadFromDirectory($dir);
     }
     $executor->execute($loader->getFixtures());
 }
예제 #11
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $loader = new Loader();
     $purger = new ORMPurger();
     if ($input->getOption('purge-with-truncate')) {
         $purger->setPurgeMode(self::PURGE_MODE_TRUNCATE);
     }
     $executor = new ORMExecutor($this->em, $purger);
     foreach ($this->paths as $key => $value) {
         $loader->loadFromDirectory($value);
     }
     $executor->execute($loader->getFixtures(), $input->getOption('append'));
 }
예제 #12
0
 public function loadFixtures()
 {
     $path = sprintf('%s/Fixtures', __DIR__);
     $loader = new DataFixturesLoader($this->container);
     $loader->loadFromDirectory($path);
     $fixtures = $loader->getFixtures();
     if (!$fixtures) {
         throw new InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', $path));
     }
     $purger = new ORMPurger($this->em);
     $purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE);
     $executor = new ORMExecutor($this->em, $purger);
     $executor->execute($fixtures);
 }
예제 #13
0
 /**
  * @BeforeScenario
  */
 public function beforeScenario()
 {
     $loader = new Loader();
     $loader->addFixture(new \Stfalcon\Bundle\EventBundle\DataFixtures\ORM\LoadEventData());
     $loader->addFixture(new \Stfalcon\Bundle\EventBundle\DataFixtures\ORM\LoadNewsData());
     $loader->addFixture(new \Application\Bundle\UserBundle\DataFixtures\ORM\LoadUserData());
     $this->em = $this->kernel->getContainer()->get('doctrine.orm.entity_manager');
     $this->em->getConnection()->executeUpdate("SET foreign_key_checks = 0;");
     $purger = new ORMPurger();
     $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);
     $executor = new ORMExecutor($this->em, $purger);
     $executor->purge();
     $executor->execute($loader->getFixtures(), true);
     $this->em->getConnection()->executeUpdate("SET foreign_key_checks = 1;");
 }
 public function importAction()
 {
     if (!$this->getRequest() instanceof ConsoleRequest) {
         throw new RuntimeException('You can only use this action from a console.');
     }
     $loader = new Loader();
     $purger = new ORMPurger();
     foreach ($this->dataFixtureManager->getAll() as $fixture) {
         $loader->addFixture($fixture);
     }
     if ($this->params()->fromRoute('purge-with-truncate')) {
         $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);
     }
     $executor = new ORMExecutor($this->dataFixtureManager->getObjectManager(), $purger);
     $executor->execute($loader->getFixtures(), (bool) $this->params()->fromRoute('append'));
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var $doctrine \Doctrine\Common\Persistence\ManagerRegistry */
     $doctrine = $this->getContainer()->get('doctrine');
     $em = $doctrine->getManager($input->getOption('em'));
     if ($input->isInteractive() && !$input->getOption('append')) {
         $dialog = $this->getHelperSet()->get('dialog');
         if (!$dialog->askConfirmation($output, '<question>Careful, database will be purged. Do you want to continue Y/N ?</question>', false)) {
             return;
         }
     }
     $dirOrFile = $input->getOption('fixtures');
     if ($dirOrFile) {
         $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
     } else {
         $paths = array();
         foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
             $paths[] = $bundle->getPath() . '/DataFixtures/ORM';
         }
     }
     $loader = new DataFixturesLoader($this->getContainer());
     foreach ($paths as $path) {
         if (is_dir($path)) {
             $loader->loadFromDirectory($path);
         }
     }
     $fixtures = $loader->getFixtures();
     if (!$fixtures) {
         throw new InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- " . implode("\n- ", $paths)));
     }
     $purger = new ORMPurger($em);
     $purger->setPurgeMode($input->getOption('purge-with-truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
     $executor = new ORMExecutor($em, $purger);
     $executor->setLogger(function ($message) use($output) {
         $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
     });
     $executor->execute($fixtures, $input->getOption('append'));
     // Serialize reference repository to a file. So fixtures will be accessible by names inside functional tests.
     $referenceRepositoryFile = $this->getContainer()->getParameter('fixtures.reference_repository_path');
     $serializedReferenceRepository = (new FixtureReferenceRepositorySerializer())->serialize($executor->getReferenceRepository());
     file_put_contents($referenceRepositoryFile, $serializedReferenceRepository);
     $output->writeln(sprintf('<info>Reference repository saved to:</info> <comment>%s</comment>', realpath($referenceRepositoryFile)));
 }
예제 #16
0
 /**
  * @BeforeScenario
  */
 public function beforeScen()
 {
     $loader = new Loader();
     $this->getMainContext()->getSubcontext('DoctrineFixturesContext')->loadFixtureClasses($loader, array('Stfalcon\\Bundle\\EventBundle\\DataFixtures\\ORM\\LoadNewsData', 'Stfalcon\\Bundle\\EventBundle\\DataFixtures\\ORM\\LoadPagesData', 'Stfalcon\\Bundle\\EventBundle\\DataFixtures\\ORM\\LoadReviewData', 'Stfalcon\\Bundle\\EventBundle\\DataFixtures\\ORM\\LoadMailQueueData', 'Application\\Bundle\\UserBundle\\DataFixtures\\ORM\\LoadUserData', 'Stfalcon\\Bundle\\EventBundle\\DataFixtures\\ORM\\LoadEventData', 'Stfalcon\\Bundle\\EventBundle\\DataFixtures\\ORM\\LoadPromoCodeData', 'Stfalcon\\Bundle\\EventBundle\\DataFixtures\\ORM\\LoadPaymentData', 'Stfalcon\\Bundle\\EventBundle\\DataFixtures\\ORM\\LoadMailQueueData', 'Stfalcon\\Bundle\\EventBundle\\DataFixtures\\ORM\\LoadTicketData', 'Stfalcon\\Bundle\\EventBundle\\DataFixtures\\ORM\\LoadMailQueueData'));
     /** @var $em \Doctrine\ORM\EntityManager */
     $em = $this->kernel->getContainer()->get('doctrine.orm.entity_manager');
     $em->getConnection()->executeUpdate("SET foreign_key_checks = 0;");
     $purger = new ORMPurger();
     $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);
     $executor = new ORMExecutor($em, $purger);
     $executor->purge();
     $executor->execute($loader->getFixtures(), true);
     $em->getConnection()->executeUpdate("SET foreign_key_checks = 1;");
     /** Maximize browser window */
     $driver = $this->getSession()->getDriver();
     if ($driver instanceof Selenium2Driver) {
         $driver->maximizeWindow();
     }
 }
예제 #17
0
 /**
  * @BeforeScenario
  */
 public function beforeScen()
 {
     $loader = new Loader();
     $loader->addFixture(new \Stfalcon\Bundle\EventBundle\DataFixtures\ORM\LoadEventData());
     $loader->addFixture(new \Stfalcon\Bundle\EventBundle\DataFixtures\ORM\LoadNewsData());
     $em = $this->kernel->getContainer()->get('doctrine.orm.entity_manager');
     /** @var $em \Doctrine\ORM\EntityManager */
     $connection = $em->getConnection();
     $connection->beginTransaction();
     $connection->query('SET FOREIGN_KEY_CHECKS=0');
     $connection->commit();
     $purger = new ORMPurger();
     $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);
     $executor = new ORMExecutor($em, $purger);
     $executor->purge();
     $connection->beginTransaction();
     $connection->query('SET FOREIGN_KEY_CHECKS=1');
     $connection->commit();
     $executor->execute($loader->getFixtures(), true);
 }
예제 #18
0
 /**
  * @BeforeScenario
  */
 public function purgeDatabase(BeforeScenarioScope $scope)
 {
     $loader = new Loader();
     $loader->addFixture(new \Application\Bundle\CoreBundle\DataFixtures\ORM\LoadSolutionData());
     $loader->addFixture(new \Application\Bundle\CoreBundle\DataFixtures\ORM\LoadTaskData());
     $entityManager = $this->getService('doctrine.orm.entity_manager');
     /** @var $em \Doctrine\ORM\EntityManager */
     $connection = $entityManager->getConnection();
     $connection->beginTransaction();
     $connection->query('SET FOREIGN_KEY_CHECKS=0');
     $connection->commit();
     $purger = new ORMPurger($entityManager);
     $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);
     $executor = new ORMExecutor($entityManager, $purger);
     $executor->purge();
     $connection->beginTransaction();
     $connection->query('SET FOREIGN_KEY_CHECKS=1');
     $connection->commit();
     $executor->execute($loader->getFixtures(), true);
 }
예제 #19
0
/**
 * Remove all data from the app.
 */
function clear_app()
{
    // remove all old data from the database
    $em = doctrine()->getManager();
    $purger = new ORMPurger($em);
    $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);
    $purger->purge();
    // clear the elasticsearch database
    if (container()->has('fos_elastica.index_manager')) {
        $es_index_manager = container()->get('fos_elastica.index_manager');
        $es_resetter = container()->get('fos_elastica.resetter');
        foreach ($es_index_manager->getAllIndexes() as $name => $index) {
            $es_resetter->resetIndex($name, false, true);
        }
    }
    $finder = new Finder();
    foreach ($finder->in(__DIR__ . "/data/")->name('*.sql') as $file) {
        load_sql($file);
    }
}
예제 #20
0
 /**
  * Purge the Doctrine ORM database
  */
 protected function purgeDatabase()
 {
     /** @var EntityManager $em */
     $em = $this->getEntityManager();
     try {
         $connection = $em->getConnection();
         if ($connection->getDriver() instanceof \Doctrine\DBAL\Driver\PDOMySql\Driver) {
             $connection->executeUpdate("SET foreign_key_checks = 0;");
         }
         $purger = new ORMPurger();
         $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);
         $executor = new ORMExecutor($em, $purger);
         $referenceRepository = new ProxyReferenceRepository($em);
         $executor->setReferenceRepository($referenceRepository);
         $executor->purge();
     } catch (\Exception $ex) {
         throw new RuntimeException(sprintf('Could not purge database! Have you initialized it? Run: ' . PHP_EOL . 'app/console doctrine:database:create --env=test ' . PHP_EOL . 'app/console doctrine:schema:update --force --env=test'));
     }
     if ($connection->getDriver() instanceof \Doctrine\DBAL\Driver\PDOMySql\Driver) {
         $em->getConnection()->executeUpdate("SET foreign_key_checks = 1;");
     }
 }
예제 #21
0
 /**
  * Gets the executor for the matching the given object manager.
  *
  * @param ObjectManager   $manager
  * @param LoaderInterface $loader
  * @param bool|null       $purgeMode
  *
  * @return ExecutorInterface
  */
 private function getExecutor(ObjectManager $manager, LoaderInterface $loader, $purgeMode)
 {
     switch (true) {
         case $manager instanceof EntityManagerInterface:
             $executor = new ORMExecutor($manager, $loader);
             $purger = new ORMPurger($manager);
             $purger->setPurgeMode($purgeMode ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
             break;
         case $manager instanceof MongoDBDocumentManager:
             $executor = new MongoDBExecutor($manager, $loader);
             $purger = new MongoDBPurger($manager);
             break;
         case $manager instanceof PHPCRDocumentManager:
             $executor = new PHPCRExecutor($manager, $loader);
             $purger = new PHPCRPurger($manager);
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Unsupported manager type %s', get_class($manager)));
     }
     $executor->setPurger($purger);
     return $executor;
 }
예제 #22
0
 /**
  * {@inheritdoc}
  */
 public function forwardAction(ProcessContextInterface $context)
 {
     $request = $this->getRequest();
     $form = $this->createForm('sylius_setup');
     $em = $this->getDoctrine()->getManager();
     if ($form->handleRequest($request)->isValid()) {
         $params = $this->get('doctrine')->getConnection()->getParams();
         $dbname = $params['dbname'];
         unset($params['dbname']);
         $schemaManager = DriverManager::getConnection($params)->getSchemaManager();
         if (!in_array($dbname, $schemaManager->listDatabases())) {
             $schemaManager->createDatabase($dbname);
         }
         $schemaTool = new SchemaTool($em);
         $schemaTool->dropSchema($em->getMetadataFactory()->getAllMetadata());
         $schemaTool->createSchema($em->getMetadataFactory()->getAllMetadata());
         if ($form->get('load_fixtures')->getData()) {
             $loader = new ContainerAwareLoader($this->container);
             foreach ($this->get('kernel')->getBundles() as $bundle) {
                 if (is_dir($path = $bundle->getPath() . '/DataFixtures/ORM')) {
                     $loader->loadFromDirectory($path);
                 }
             }
             $purger = new ORMPurger($em);
             $purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE);
             $executor = new ORMExecutor($em, $purger);
             $executor->execute($loader->getFixtures());
         }
         $user = $form->getData();
         $user->setEnabled(true);
         $user->setRoles(array('ROLE_SYLIUS_ADMIN'));
         $em->persist($user);
         $em->flush();
         $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('sylius.flashes.installed'));
         return $this->complete();
     }
     return $this->render('SyliusInstallerBundle:Process/Step:setup.html.twig', array('form' => $form->createView()));
 }
예제 #23
0
 public function setUp()
 {
     global $app;
     try {
         /* delete the existing entities before each test */
         /* if we delete the entities the ids go out of sync, which means the data 
          * in the fixures is not what the tests expect - guess we should use mocks 
          * but I find that messy */
         /* so we kill the whole db before each test and then reload the fixtures */
         self::setUpBeforeClass();
         /* load the fixtures */
         $loader = new Loader();
         $loader->loadFromDirectory('config/doctrine/fixtures/');
         $fixtures = $loader->getFixtures();
         $purger = new ORMPurger($app['orm.em']);
         $purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE);
         $executor = new ORMExecutor($app['orm.em'], $purger);
         $executor->execute($fixtures);
     } catch (\Exception $e) {
         /* ignored */
     }
     parent::setUp();
 }
예제 #24
0
 /**
  * @BeforeScenario
  */
 public function loadFixturesBeforeScenarios()
 {
     $paths = array();
     foreach ($this->kernel->getBundles() as $bundle) {
         $paths[] = $bundle->getPath() . '/DataFixtures/ORM';
     }
     $loader = new DataFixturesLoader($this->getContainer());
     foreach ($paths as $path) {
         if (is_dir($path)) {
             $loader->loadFromDirectory($path);
         }
     }
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $fixtures = $loader->getFixtures();
     $purger = new ORMPurger($em);
     //$purger->setPurgeMode($input->getOption('purge-with-truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
     $purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE);
     $executor = new ORMExecutor($em, $purger);
     //         $executor->setLogger(function($message) use ($output) {
     //             $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
     //         });
     $append = false;
     $executor->execute($fixtures, $append);
 }
예제 #25
0
 /**
  * Installs data fixtures for the application
  *
  * @return array|bool Array containing the flash message data on a failure, boolean true on success
  */
 private function performFixtureInstall()
 {
     try {
         $entityManager = $this->getEntityManager();
         $paths = array(dirname(__DIR__) . '/InstallFixtures/ORM');
         $loader = new ContainerAwareLoader($this->container);
         foreach ($paths as $path) {
             if (is_dir($path)) {
                 $loader->loadFromDirectory($path);
             }
         }
         $fixtures = $loader->getFixtures();
         if (!$fixtures) {
             throw new \InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- " . implode("\n- ", $paths)));
         }
         $purger = new ORMPurger($entityManager);
         $purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE);
         $executor = new ORMExecutor($entityManager, $purger);
         $executor->execute($fixtures, true);
     } catch (\Exception $exception) {
         return array('type' => 'error', 'msg' => 'mautic.installer.error.adding.fixtures', 'msgVars' => array('%exception%' => $exception->getMessage()));
     }
     return true;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $emName = $input->getOption('em');
     $emName = $emName ? $emName : 'default';
     $emServiceName = sprintf('doctrine.orm.%s_entity_manager', $emName);
     if (!$this->getContainer()->has($emServiceName)) {
         throw new InvalidArgumentException(sprintf('Could not find an entity manager configured with the name "%s". Check your ' . 'application configuration to configure your Doctrine entity managers.', $emName));
     }
     $em = $this->getContainer()->get($emServiceName);
     $dirOrFile = $input->getOption('fixtures');
     if ($dirOrFile) {
         $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
     } else {
         $paths = array();
         foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
             $paths[] = $bundle->getPath() . '/DataFixtures/ORM';
         }
     }
     $loader = new DataFixturesLoader($this->getContainer());
     foreach ($paths as $path) {
         if (is_dir($path)) {
             $loader->loadFromDirectory($path);
         }
     }
     $fixtures = $loader->getFixtures();
     if (!$fixtures) {
         throw new InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- " . implode("\n- ", $paths)));
     }
     $purger = new ORMPurger($em);
     $purger->setPurgeMode($input->getOption('purge-with-truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
     $executor = new ORMExecutor($em, $purger);
     $executor->setLogger(function ($message) use($output) {
         $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
     });
     $executor->execute($fixtures, $input->getOption('append'));
 }
예제 #27
0
 /**
  * Initialize ORM database.
  */
 protected function initializeORM()
 {
     $entityManager = $this->get('doctrine')->getManager();
     $purger = new ORMPurger($entityManager);
     $purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE);
     $purger->purge();
 }
예제 #28
0
 /**
  * @BeforeScenario @database
  */
 public function cleanDatabase()
 {
     $purger = new ORMPurger($this->getDoctrine()->getManager());
     $purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE);
     $purger->purge();
 }
예제 #29
0
 /**
  * Installs data fixtures for the application
  *
  * @return array|bool Array containing the flash message data on a failure, boolean true on success
  */
 private function installDatabaseFixtures()
 {
     $entityManager = $this->get('doctrine.orm.entity_manager');
     $paths = [dirname(__DIR__) . '/InstallFixtures/ORM'];
     $loader = new ContainerAwareLoader($this->container);
     foreach ($paths as $path) {
         if (is_dir($path)) {
             $loader->loadFromDirectory($path);
         }
     }
     $fixtures = $loader->getFixtures();
     if (!$fixtures) {
         throw new \InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- " . implode("\n- ", $paths)));
     }
     $purger = new ORMPurger($entityManager);
     $purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE);
     $executor = new ORMExecutor($entityManager, $purger);
     $executor->execute($fixtures, true);
 }
 /**
  * Purge database and execute fixtures loading
  *
  * @param OutputInterface $output
  * @param array           $fixtures
  * @param boolean         $purgeWithTruncate
  * @param boolean         $appendFixtures
  */
 protected function purgeAndExecute(OutputInterface $output, array $fixtures, $purgeWithTruncate, $appendFixtures)
 {
     $purger = new ORMPurger($this->em);
     $purger->setPurgeMode($purgeWithTruncate ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
     // we use here our own Pim\Bundle\InstallerBundle\DataFixtures\Executor\ORMExecutor\ORMExecutor
     $executor = new ORMExecutor($this->em, $purger);
     $executor->setLogger(function ($message) use($output) {
         $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
     });
     $executor->execute($fixtures, $appendFixtures);
 }