diff --git a/src/AppBundle/Command/LoadRelationCommand.php b/src/AppBundle/Command/LoadRelationCommand.php index d224dfd..055806b 100644 --- a/src/AppBundle/Command/LoadRelationCommand.php +++ b/src/AppBundle/Command/LoadRelationCommand.php @@ -2,8 +2,11 @@ namespace AppBundle\Command; +use AppBundle\Service\Loader\RelationLoader; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class LoadRelationCommand extends ContainerAwareCommand @@ -13,11 +16,17 @@ class LoadRelationCommand extends ContainerAwareCommand $this ->setName('app:load:relations') ->setDescription('Loads relations between LDraw models and Rebrickable parts.') - ->setHelp('This command allows you to load relation between models and parts into database.'); + ->setHelp('This command allows you to load relation between models and parts into database.') + ->setDefinition( + new InputDefinition([ + new InputOption('rewrite', 'r', InputOption::VALUE_NONE, 'Reload relations for all Rebrickable parts.'), + ]) + ); } protected function execute(InputInterface $input, OutputInterface $output) { + /** @var RelationLoader $relationLoader */ $relationLoader = $this->getContainer()->get('service.loader.relation'); $relationLoader->setOutput($output); @@ -27,7 +36,11 @@ class LoadRelationCommand extends ContainerAwareCommand '------------------------------------------------------------------------------', ]); - $relationLoader->loadAll(); + if ($input->getOption('rewrite')) { + $relationLoader->loadAll(); + } else { + $relationLoader->loadNotPaired(); + } $output->writeln(['Done!']); } diff --git a/src/AppBundle/Service/Loader/RelationLoader.php b/src/AppBundle/Service/Loader/RelationLoader.php index 87fc393..16f2c60 100644 --- a/src/AppBundle/Service/Loader/RelationLoader.php +++ b/src/AppBundle/Service/Loader/RelationLoader.php @@ -39,7 +39,7 @@ class RelationLoader extends BaseLoader $this->load($parts); } - public function loadNotPaired($parts) + public function loadNotPaired() { $parts = $this->partRepository->findAllNotPaired(); $this->load($parts);