Completed
Push — master ( 9b53e2...2758ff )
by Andrea
19:08 queued 08:29
created

GenerateymlentitiesCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 5
dl 0
loc 94
ccs 45
cts 54
cp 0.8333
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 9 1
B execute() 0 47 4
B getExportJsonCommand() 0 28 2
1
<?php
2
3
namespace Fi\PannelloAmministrazioneBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Fi\OsBundle\DependencyInjection\OsFunctions;
10
11
class GenerateymlentitiesCommand extends ContainerAwareCommand
12
{
13
14
    protected $apppaths;
15
    protected $genhelper;
16
    protected $pammutils;
17
18 3
    protected function configure()
19
    {
20 3
        $this
21 3
                ->setName('pannelloamministrazione:generateymlentities')
22 3
                ->setDescription('Genera le entities partendo da un modello workbeanch mwb')
23 3
                ->setHelp('Genera i ifle yml per le entities partendo da un modello workbeanch mwb, <br/>fifree.mwb Fi/CoreBundle default<br/>')
24 3
                ->addArgument('mwbfile', InputArgument::REQUIRED, 'Nome file mwb, fifree.mwb')
25 3
                ->addArgument('bundlename', InputArgument::REQUIRED, 'Nome del bundle, Fi/CoreBundle');
26 3
    }
27
28 1
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30 1
        set_time_limit(0);
31 1
        $this->apppaths = $this->getContainer()->get("pannelloamministrazione.projectpath");
32 1
        $this->genhelper = $this->getContainer()->get("pannelloamministrazione.generatorhelper");
33 1
        $this->pammutils = $this->getContainer()->get("pannelloamministrazione.utils");
34
35 1
        $bundlename = $input->getArgument('bundlename');
36 1
        $mwbfile = $input->getArgument('mwbfile');
37
38 1
        $wbFile = $this->apppaths->getDocPath() . DIRECTORY_SEPARATOR . $mwbfile;
39 1
        $checkprerequisiti = $this->genhelper->checkprerequisiti($bundlename, $mwbfile, $output);
40
41 1
        if ($checkprerequisiti < 0) {
42
            return -1;
43
        }
44
45 1
        $destinationPath = $this->genhelper->getDestinationEntityYmlPath($bundlename);
46
47 1
        $command = $this->getExportJsonCommand($bundlename, $wbFile);
48
49 1
        $schemaupdateresult = $this->pammutils->runCommand($command);
50 1
        if ($schemaupdateresult["errcode"] < 0) {
51
            $output->writeln($schemaupdateresult["errmsg"]);
52
            return 1;
53
        } else {
54 1
            $output->writeln($schemaupdateresult["errmsg"]);
55
        }
56
57 1
        $this->genhelper->removeExportJsonFile();
58
59 1
        $tablecheck = $this->genhelper->checktables($destinationPath, $wbFile, $output);
60
61 1
        if ($tablecheck < 0) {
62
            return 1;
63
        }
64
65 1
        $output->writeln('<info>Entities yml create</info>');
66
        /* $generateentitiesresult = $this->pammutils->clearCache();
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
67
          if ($generateentitiesresult["errcode"] < 0) {
68
          $output->writeln($generateentitiesresult["errmsg"]);
69
          return 1;
70
          } else {
71
          $output->writeln($generateentitiesresult["errmsg"]);
72
          } */
73 1
        return 0;
74
    }
75
76 1
    private function getExportJsonCommand($bundlePath, $wbFile)
77
    {
78 1
        $exportJson = $this->genhelper->getExportJsonFile();
79 1
        $scriptGenerator = $this->genhelper->getScriptGenerator();
80 1
        $destinationPathEscaped = str_replace('/', "\/", str_replace('\\', '/', $this->genhelper->getDestinationEntityYmlPath($bundlePath)));
81 1
        $bundlePathEscaped = str_replace('\\', '\\\\', str_replace('/', '\\', $bundlePath));
82
83 1
        $exportjsonfile = $this->genhelper->getJsonMwbGenerator();
84
85 1
        $bundlejson = str_replace('[bundle]', str_replace('/', '', $bundlePathEscaped), $exportjsonfile);
86 1
        $exportjsonreplaced = str_replace('[dir]', $destinationPathEscaped, $bundlejson);
87 1
        file_put_contents($exportJson, $exportjsonreplaced);
88 1
        $sepchr = OsFunctions::getSeparator();
89 1
        if (OsFunctions::isWindows()) {
90
            $command = 'cd ' . $this->apppaths->getRootPath() . $sepchr
91
                    . $scriptGenerator . '.bat --export=doctrine2-yaml '
92
                    . ' --config=' .
93
                    $exportJson . ' ' . $wbFile . ' ' . $destinationPathEscaped;
94
        } else {
95 1
            $phpPath = OsFunctions::getPHPExecutableFromPath();
96 1
            $command = 'cd ' . $this->apppaths->getRootPath() . $sepchr
97 1
                    . $phpPath . ' ' . $scriptGenerator . ' --export=doctrine2-yaml '
98 1
                    . ' --config=' .
99 1
                    $exportJson . ' ' . $wbFile . ' ' . $destinationPathEscaped;
100
        }
101
102 1
        return $command;
103
    }
104
}
105