Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/DoctrineDataFixtureModule/Command/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\DBAL\Migrations\Configuration\Configuration;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader;
Expand All @@ -48,7 +45,7 @@ class ImportCommand extends Command

/**
* Service Locator instance
* @var Zend\ServiceManager\ServiceLocatorInterface
* @var \Zend\ServiceManager\ServiceLocatorInterface
*/
protected $serviceLocator;

Expand All @@ -72,7 +69,9 @@ protected function configure()
EOT
)
->addOption('append', null, InputOption::VALUE_NONE, 'Append data to existing data.')
->addOption('purge-with-truncate', null, InputOption::VALUE_NONE, 'Truncate tables before inserting data');
->addOption('purge-with-truncate', null, InputOption::VALUE_NONE, 'Truncate tables before inserting data')
->addOption('path', null, InputOption::VALUE_OPTIONAL, 'Set a specific path for fixtures')
->addOption('file', null, InputOption::VALUE_OPTIONAL, 'Set a specific file for fixtures');
}

public function execute(InputInterface $input, OutputInterface $output)
Expand All @@ -84,17 +83,23 @@ public function execute(InputInterface $input, OutputInterface $output)
$purger->setPurgeMode(self::PURGE_MODE_TRUNCATE);
}

$executor = new ORMExecutor($this->em, $purger);

foreach ($this->paths as $key => $value) {
$loader->loadFromDirectory($value);
if ($input->getOption('path')) {
$loader->loadFromDirectory($input->getOption('path'));
} elseif ($input->getOption('file')) {
$loader->loadFromFile($input->getOption('file'));
} else {
foreach ($this->paths as $key => $value) {
$loader->loadFromDirectory($value);
}
}

$executor = new ORMExecutor($this->em, $purger);
$executor->execute($loader->getFixtures(), $input->getOption('append'));
}

public function setPath($paths)
{
$this->paths=$paths;
$this->paths = $paths;
}

public function setEntityManager($em)
Expand Down
4 changes: 1 addition & 3 deletions src/DoctrineDataFixtureModule/Service/FixtureFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ public function createService(ServiceLocatorInterface $sl)
* Gets options from configuration based on name.
*
* @param ServiceLocatorInterface $sl
* @param string $key
* @param null|string $name
* @return \Zend\Stdlib\AbstractOptions
* @throws \RuntimeException
*/
public function getOptions(ServiceLocatorInterface $sl, $key)
public function getOptions(ServiceLocatorInterface $sl)
{
$options = $sl->get('config');
if (!isset($options['doctrine']['fixture'])) {
Expand Down