FixturesLoadCommand::execute()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 3
eloc 13
nc 4
nop 2
1
<?php
2
namespace Khepin\YamlFixturesBundle\Command;
3
4
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class FixturesLoadCommand extends ContainerAwareCommand
11
{
12
    protected function configure()
13
    {
14
        $this
15
            ->setName('khepin:yamlfixtures:load')
16
            ->setDescription('Loads all fixtures in a given context')
17
            ->addArgument(
18
                'context',
19
                InputArgument::OPTIONAL,
20
                'Specify a context from which to load additional fixtures'
21
            )
22
            ->addOption(
23
                'purge-orm',
24
                null,
25
                InputOption::VALUE_NONE,
26
                'If set, will purge the database before importing new fixtures'
27
            )
28
            ->addOption(
29
                'database-name',
30
                null,
31
                InputArgument::OPTIONAL,
32
                'If set, will purge the database specified. If not set, will purge all
33
                databases. (require purge option)'
34
            )
35
            ->addOption(
36
                'purge-mongodb',
37
                null,
38
                InputOption::VALUE_NONE,
39
                'If set, will purge the database before importing new fixtures'
40
            )
41
            ->addOption(
42
                'purge-with-truncate',
43
                null,
44
                InputOption::VALUE_NONE,
45
                'Purge data by using a database-level TRUNCATE statement (only for ORM)'
46
            )
47
        ;
48
    }
49
50
    protected function execute(InputInterface $input, OutputInterface $output)
51
    {
52
        $context = $input->getArgument('context');
53
        if ($input->getOption('purge-orm')) {
54
            $this->getContainer()->get('khepin.yaml_loader')->purgeDatabase(
55
                'orm',
56
                $input->getOption('database-name'),
57
                $input->getOption('purge-with-truncate')
58
            );
59
        }
60
        if ($input->getOption('purge-mongodb')) {
61
            $this->getContainer()->get('khepin.yaml_loader')->purgeDatabase(
62
                'mongodb',
63
                $input->getOption('database-name')
64
            );
65
        }
66
67
        $this->getContainer()->get('khepin.yaml_loader')->loadFixtures($context);
68
69
        $output->writeln('done!');
70
    }
71
}
72