removed data fixtures from core (moved to https://github.com/symfony/DoctrineFixturesBundle)
This commit is contained in:
parent
4df010757b
commit
0632327b77
@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Symfony\Bundle\DoctrineAbstractBundle\Common\DataFixtures;
|
|
||||||
|
|
||||||
use Doctrine\Common\DataFixtures\FixtureInterface;
|
|
||||||
use Doctrine\Common\DataFixtures\Loader as BaseLoader;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
|
||||||
|
|
||||||
class Loader extends BaseLoader
|
|
||||||
{
|
|
||||||
private $container;
|
|
||||||
|
|
||||||
public function __construct(ContainerInterface $container)
|
|
||||||
{
|
|
||||||
$this->container = $container;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addFixture(FixtureInterface $fixture)
|
|
||||||
{
|
|
||||||
if ($fixture instanceof ContainerAwareInterface) {
|
|
||||||
$fixture->setContainer($this->container);
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::addFixture($fixture);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Symfony\Bundle\DoctrineAbstractBundle\Tests\Common;
|
|
||||||
|
|
||||||
use Doctrine\Common\DataFixtures\FixtureInterface;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
|
||||||
|
|
||||||
class ContainerAwareFixture implements FixtureInterface, ContainerAwareInterface
|
|
||||||
{
|
|
||||||
public $container;
|
|
||||||
|
|
||||||
public function setContainer(ContainerInterface $container = null)
|
|
||||||
{
|
|
||||||
$this->container = $container;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function load($manager)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Symfony\Bundle\DoctrineAbstractBundle\Tests\Common\DataFixtures;
|
|
||||||
|
|
||||||
use Symfony\Bundle\DoctrineAbstractBundle\Tests\TestCase;
|
|
||||||
use Symfony\Bundle\DoctrineAbstractBundle\Tests\Common\ContainerAwareFixture;
|
|
||||||
use Symfony\Bundle\DoctrineAbstractBundle\Common\DataFixtures\Loader;
|
|
||||||
|
|
||||||
class LoaderTest extends TestCase
|
|
||||||
{
|
|
||||||
public function testShouldSetContainerOnContainerAwareFixture()
|
|
||||||
{
|
|
||||||
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
|
|
||||||
$loader = new Loader($container);
|
|
||||||
$fixture = new ContainerAwareFixture();
|
|
||||||
|
|
||||||
$loader->addFixture($fixture);
|
|
||||||
|
|
||||||
$this->assertSame($container, $fixture->container);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Symfony\Bundle\DoctrineAbstractBundle\Tests;
|
|
||||||
|
|
||||||
class TestCase extends \PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
protected function setUp()
|
|
||||||
{
|
|
||||||
if (!class_exists('Doctrine\Common\DataFixtures\Loader')) {
|
|
||||||
$this->markTestSkipped('Doctrine Data Fixtures is not available.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,106 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony package.
|
|
||||||
*
|
|
||||||
* (c) Fabien Potencier <fabien@symfony.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Symfony\Bundle\DoctrineBundle\Command;
|
|
||||||
|
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
|
||||||
use Symfony\Component\Console\Output\Output;
|
|
||||||
use Symfony\Component\Finder\Finder;
|
|
||||||
use Symfony\Component\HttpKernel\Util\Filesystem;
|
|
||||||
use Symfony\Bundle\DoctrineAbstractBundle\Common\DataFixtures\Loader as DataFixturesLoader;
|
|
||||||
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
|
|
||||||
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
|
|
||||||
use Doctrine\ORM\EntityManager;
|
|
||||||
use Doctrine\ORM\Internal\CommitOrderCalculator;
|
|
||||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load data fixtures from bundles.
|
|
||||||
*
|
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
|
||||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
|
||||||
*/
|
|
||||||
class LoadDataFixturesDoctrineCommand extends DoctrineCommand
|
|
||||||
{
|
|
||||||
protected function configure()
|
|
||||||
{
|
|
||||||
$this
|
|
||||||
->setName('doctrine:data:load')
|
|
||||||
->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 flushing the database first.')
|
|
||||||
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
|
|
||||||
->setHelp(<<<EOT
|
|
||||||
The <info>doctrine:data:load</info> command loads data fixtures from your bundles:
|
|
||||||
|
|
||||||
<info>./app/console doctrine:data:load</info>
|
|
||||||
|
|
||||||
You can also optionally specify the path to fixtures with the <info>--fixtures</info> option:
|
|
||||||
|
|
||||||
<info>./app/console doctrine:data:load --fixtures=/path/to/fixtures1 --fixtures=/path/to/fixtures2</info>
|
|
||||||
|
|
||||||
If you want to append the fixtures instead of flushing the database first you can use the <info>--append</info> option:
|
|
||||||
|
|
||||||
<info>./app/console doctrine:data:load --append</info>
|
|
||||||
EOT
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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->container->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->container->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->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);
|
|
||||||
$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'));
|
|
||||||
}
|
|
||||||
}
|
|
@ -40,9 +40,6 @@ install_git assetic git://github.com/kriswallsmith/assetic.git
|
|||||||
# Doctrine ORM
|
# Doctrine ORM
|
||||||
install_git doctrine git://github.com/doctrine/doctrine2.git 2.0.4
|
install_git doctrine git://github.com/doctrine/doctrine2.git 2.0.4
|
||||||
|
|
||||||
# Doctrine Data Fixtures Extension
|
|
||||||
install_git doctrine-data-fixtures git://github.com/doctrine/data-fixtures.git
|
|
||||||
|
|
||||||
# Doctrine DBAL
|
# Doctrine DBAL
|
||||||
install_git doctrine-dbal git://github.com/doctrine/dbal.git 2.0.4
|
install_git doctrine-dbal git://github.com/doctrine/dbal.git 2.0.4
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user