|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sylius\Bundle\FixturesBundle\Command; |
|
13
|
|
|
|
|
14
|
|
|
use Sylius\Bundle\FixturesBundle\Loader\SuiteLoaderInterface; |
|
15
|
|
|
use Sylius\Bundle\FixturesBundle\Suite\SuiteRegistryInterface; |
|
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
17
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
19
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
|
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
21
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
22
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
23
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @author Kamil Kokot <[email protected]> |
|
27
|
|
|
*/ |
|
28
|
|
|
final class FixturesLoadCommand extends ContainerAwareCommand |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritdoc} |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function configure() |
|
34
|
|
|
{ |
|
35
|
|
|
$this |
|
36
|
|
|
->setName('sylius:fixtures:load') |
|
37
|
|
|
->setDescription('Loads fixtures from given suite') |
|
38
|
|
|
->addArgument('suite', InputArgument::OPTIONAL, 'Suite name', 'default') |
|
39
|
|
|
; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
46
|
|
|
{ |
|
47
|
|
|
if ($input->isInteractive()) { |
|
48
|
|
|
/** @var QuestionHelper $questionHelper */ |
|
49
|
|
|
$questionHelper = $this->getHelper('question'); |
|
50
|
|
|
|
|
51
|
|
|
$output->writeln(sprintf( |
|
52
|
|
|
"\n<error>Warning! Loading fixtures will purge your database for the %s environment.</error>\n", |
|
53
|
|
|
$input->getOption('env') |
|
54
|
|
|
)); |
|
55
|
|
|
|
|
56
|
|
|
if (!$questionHelper->ask($input, $output, new ConfirmationQuestion('Continue? (y/N) ', false))) { |
|
57
|
|
|
return; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$this->loadSuites($input); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param InputInterface $input |
|
66
|
|
|
*/ |
|
67
|
|
|
private function loadSuites(InputInterface $input) |
|
68
|
|
|
{ |
|
69
|
|
|
$suiteName = $input->getArgument('suite'); |
|
70
|
|
|
$suite = $this->getSuiteRegistry()->getSuite($suiteName); |
|
71
|
|
|
|
|
72
|
|
|
$this->getSuiteLoader()->load($suite); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return SuiteRegistryInterface |
|
77
|
|
|
*/ |
|
78
|
|
|
private function getSuiteRegistry() |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->getContainer()->get('sylius_fixtures.suite_registry'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return SuiteLoaderInterface |
|
85
|
|
|
*/ |
|
86
|
|
|
private function getSuiteLoader() |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->getContainer()->get('sylius_fixtures.suite_loader'); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|