Skip to content

Loading…

[WIP] added support for ODM's #26

Open
wants to merge 1 commit into from

4 participants

@lsmith77
Doctrine member

No description provided.

@lsmith77 lsmith77 commented on the diff
Command/LoadDataFixturesDoctrineCommand.php
((5 lines not shown))
$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);
+
+ $purgerClass = 'Doctrine\\Common\\DataFixtures\Purger\\' . $type . 'Purger';
@lsmith77 Doctrine member
lsmith77 added a note

should we add a container parameter for this class name for each type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@lsmith77 lsmith77 commented on the diff
Command/LoadDataFixturesDoctrineCommand.php
((5 lines not shown))
$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);
+
+ $purgerClass = 'Doctrine\\Common\\DataFixtures\Purger\\' . $type . 'Purger';
+ $purger = new $purgerClass($om);
+ if ('ORM' === $type) {
+ $purger->setPurgeMode($input->getOption('purge-with-truncate')
+ ? $purgerClass::PURGE_MODE_TRUNCATE : $purgerClass::PURGE_MODE_DELETE);
+ }
+
+ $executorClass = 'Doctrine\\Common\\DataFixtures\Executor\\' . $type . 'Executor';
@lsmith77 Doctrine member
lsmith77 added a note

should we add a container parameter for this class name for each type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@stof
Doctrine member

@lsmith77 as the bundle now only provides a command (the ContainerAwareLoader has been moved to the bridge in 2.1 and so is not needed in the bundle anymore), I'm thinking about dropping the bundle altogether and moving the command to DoctrineBundle itself (activating it only when DataFixtures is available)

@lsmith77
Doctrine member

sounds like a good idea to me

@stof stof referenced this pull request
Open

New "generate" command #13

@azr

So, is there any chances of seeing a Data Fixture loader/dumper here soon ? ?

@stof
Doctrine member

@Azer- the loading is in the bundle for the ODM.

@azr

@stof Ok, but no command for fixture dumping ? That would get the loader to be more used ( lazy me ... ).

@dbu
Doctrine member
dbu commented

is this still relevant? afaik we do have phpcr-odm integrated with the fixtures bundle

@lsmith77 lsmith77 referenced this pull request in doctrine/DoctrinePHPCRBundle
Merged

[POC] ODM Initializer #97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 9, 2012
  1. @lsmith77

    added support for ODM's

    lsmith77 committed
This page is out of date. Refresh to see the latest.
Showing with 34 additions and 18 deletions.
  1. +34 −18 Command/LoadDataFixturesDoctrineCommand.php
View
52 Command/LoadDataFixturesDoctrineCommand.php
@@ -20,7 +20,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Finder\Finder;
-use Doctrine\Bundle\FrameworkBundle\Util\Filesystem;
use Doctrine\Bundle\FixturesBundle\Common\DataFixtures\Loader as DataFixturesLoader;
use Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
@@ -45,7 +44,8 @@ protected function configure()
->setDescription('Load data fixtures to your database.')
->addOption('fixtures', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The directory or file to load data fixtures from.')
->addOption('append', null, InputOption::VALUE_NONE, 'Append the data fixtures instead of deleting all data from the database first.')
- ->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
+ ->addOption('om', null, InputOption::VALUE_OPTIONAL, 'The object manager to use for this command.', null)
+ ->addOption('type', null, InputOption::VALUE_OPTIONAL, 'The object manager type (\'ORM\', \'MongoDB\', \'PHPCR\') to use for this command.', 'ORM')
->addOption('purge-with-truncate', null, InputOption::VALUE_NONE, 'Purge data by using a database-level TRUNCATE statement')
->setHelp(<<<EOT
The <info>doctrine:fixtures:load</info> command loads data fixtures from your bundles:
@@ -60,7 +60,7 @@ protected function configure()
<info>./app/console doctrine:fixtures:load --append</info>
-By default Doctrine Data Fixtures uses DELETE statements to drop the existing rows from
+By default when using the ORM type Doctrine Data Fixtures uses DELETE statements to drop the existing rows from
the database. If you want to use a TRUNCATE statement instead you can use the <info>--purge-with-truncate</info> flag:
<info>./app/console doctrine:fixtures:load --purge-with-truncate</info>
@@ -70,27 +70,35 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
- $emName = $input->getOption('em');
- $emName = $emName ? $emName : 'default';
- $emServiceName = sprintf('doctrine.orm.%s_entity_manager', $emName);
+ $type = strtoupper($input->getOption('type'));
- 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
- )
- );
+ switch ($type) {
+ case 'ORM':
+ $registryName = 'doctrine';
+ break;
+ case 'MongoDB':
+ $registryName = 'doctrine_mongodb';
+ break;
+ case 'PHPCR':
+ $registryName = 'doctrine_phpcr';
+ break;
+ default:
+ throw new InvalidArgumentException(
+ sprintf('The provided type %s is not supported.', $type)
+ );
}
- $em = $this->getContainer()->get($emServiceName);
+ $registry = $this->getContainer()->get($registryName);
+ $omName = $input->getOption('om');
+ $om = $registry->getManager($omName);
+
$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';
+ $paths[] = $bundle->getPath().'/DataFixtures/'. $type;
}
}
@@ -100,15 +108,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
$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);
+
+ $purgerClass = 'Doctrine\\Common\\DataFixtures\Purger\\' . $type . 'Purger';
@lsmith77 Doctrine member
lsmith77 added a note

should we add a container parameter for this class name for each type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ $purger = new $purgerClass($om);
+ if ('ORM' === $type) {
+ $purger->setPurgeMode($input->getOption('purge-with-truncate')
+ ? $purgerClass::PURGE_MODE_TRUNCATE : $purgerClass::PURGE_MODE_DELETE);
+ }
+
+ $executorClass = 'Doctrine\\Common\\DataFixtures\Executor\\' . $type . 'Executor';
@lsmith77 Doctrine member
lsmith77 added a note

should we add a container parameter for this class name for each type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ $executor = new $executorClass($om, $purger);
$executor->setLogger(function($message) use ($output) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
});
Something went wrong with that request. Please try again.