From da2bd355e060bfcdae48ad137c87f793a9d9a130 Mon Sep 17 00:00:00 2001 From: Haydar KULEKCI Date: Sat, 13 Aug 2016 18:07:47 +0300 Subject: [PATCH 1/2] - added path option for console interface to be able to set a specific path while importing fixtures. - removed unused use statements and $key parameter of Fixture Factory getOption method. --- .../Command/ImportCommand.php | 14 ++++++++------ .../Service/FixtureFactory.php | 4 +--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/DoctrineDataFixtureModule/Command/ImportCommand.php b/src/DoctrineDataFixtureModule/Command/ImportCommand.php index f153d41..379374b 100644 --- a/src/DoctrineDataFixtureModule/Command/ImportCommand.php +++ b/src/DoctrineDataFixtureModule/Command/ImportCommand.php @@ -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; @@ -48,7 +45,7 @@ class ImportCommand extends Command /** * Service Locator instance - * @var Zend\ServiceManager\ServiceLocatorInterface + * @var \Zend\ServiceManager\ServiceLocatorInterface */ protected $serviceLocator; @@ -72,7 +69,8 @@ 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'); } public function execute(InputInterface $input, OutputInterface $output) @@ -84,6 +82,10 @@ public function execute(InputInterface $input, OutputInterface $output) $purger->setPurgeMode(self::PURGE_MODE_TRUNCATE); } + if ($input->getOption('path')) { + $this->setPath([$input->getOption('path')]); + } + $executor = new ORMExecutor($this->em, $purger); foreach ($this->paths as $key => $value) { @@ -94,7 +96,7 @@ public function execute(InputInterface $input, OutputInterface $output) public function setPath($paths) { - $this->paths=$paths; + $this->paths = $paths; } public function setEntityManager($em) diff --git a/src/DoctrineDataFixtureModule/Service/FixtureFactory.php b/src/DoctrineDataFixtureModule/Service/FixtureFactory.php index 223ec56..07df182 100644 --- a/src/DoctrineDataFixtureModule/Service/FixtureFactory.php +++ b/src/DoctrineDataFixtureModule/Service/FixtureFactory.php @@ -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'])) { From bced0bc1d7830c71e11a3456cdbbcd11071335e8 Mon Sep 17 00:00:00 2001 From: Haydar KULEKCI Date: Sat, 13 Aug 2016 18:48:24 +0300 Subject: [PATCH 2/2] added file parameter for console interface to be able to use direclt import from file --- .../Command/ImportCommand.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/DoctrineDataFixtureModule/Command/ImportCommand.php b/src/DoctrineDataFixtureModule/Command/ImportCommand.php index 379374b..6fcc7af 100644 --- a/src/DoctrineDataFixtureModule/Command/ImportCommand.php +++ b/src/DoctrineDataFixtureModule/Command/ImportCommand.php @@ -70,7 +70,8 @@ protected function configure() ) ->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('path', null, InputOption::VALUE_OPTIONAL, 'Set a specific path for fixtures'); + ->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) @@ -83,14 +84,16 @@ public function execute(InputInterface $input, OutputInterface $output) } if ($input->getOption('path')) { - $this->setPath([$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); - - foreach ($this->paths as $key => $value) { - $loader->loadFromDirectory($value); - } $executor->execute($loader->getFixtures(), $input->getOption('append')); }