1 | <?php |
||
9 | class GeneratorHelper |
||
10 | { |
||
11 | |||
12 | private $container; |
||
13 | private $apppaths; |
||
14 | |||
15 | 1 | public function __construct($container) |
|
20 | |||
21 | 1 | public function getDestinationEntityYmlPath($bundlePath) |
|
27 | |||
28 | 1 | public function checktables($destinationPath, $wbFile, $output) |
|
29 | { |
||
30 | 1 | $finder = new Finder(); |
|
31 | 1 | $fs = new Filesystem(); |
|
32 | |||
33 | 1 | $pathdoctrineyml = $destinationPath; |
|
34 | |||
35 | //Si converte il nome file tabella.orm.yml se ha undercore |
||
36 | 1 | $finder->in($pathdoctrineyml)->files()->name('*_*'); |
|
37 | 1 | $table = new Table(); |
|
38 | |||
39 | 1 | foreach ($finder as $file) { |
|
40 | $oldfilename = $file->getPathName(); |
||
41 | $newfilename = $pathdoctrineyml . DIRECTORY_SEPARATOR . $table->beautify($file->getFileName()); |
||
42 | $fs->rename($oldfilename, $newfilename, true); |
||
43 | } |
||
44 | |||
45 | //Si cercano file con nomi errati |
||
46 | 1 | $finderwrong = new Finder(); |
|
47 | 1 | $finderwrong->in($pathdoctrineyml)->files()->name('*_*'); |
|
48 | 1 | $wrongfilename = array(); |
|
49 | 1 | if (count($finderwrong) > 0) { |
|
50 | foreach ($finderwrong as $file) { |
||
51 | $wrongfilename[] = $file->getFileName(); |
||
52 | $fs->remove($pathdoctrineyml . DIRECTORY_SEPARATOR . $file->getFileName()); |
||
53 | } |
||
54 | } |
||
55 | 1 | $finderwrongcapitalize = new Finder(); |
|
56 | 1 | $finderwrongcapitalize->in($pathdoctrineyml)->files()->name('*.yml'); |
|
57 | 1 | foreach ($finderwrongcapitalize as $file) { |
|
58 | 1 | if (!ctype_upper(substr($file->getFileName(), 0, 1))) { |
|
59 | $wrongfilename[] = $file->getFileName(); |
||
60 | 1 | $fs->remove($pathdoctrineyml . DIRECTORY_SEPARATOR . $file->getFileName()); |
|
61 | } |
||
62 | } |
||
63 | |||
64 | 1 | if (count($wrongfilename) > 0) { |
|
65 | $errout = '<error>Ci sono tabelle nel file ' . $wbFile . ' con nomi non consentiti:' . |
||
66 | implode(',', $wrongfilename) . |
||
67 | '. I nomi tabella devono essere : con la prima lettera maiuscola,underscore ammesso,doppio underscore non ammesso</error>'; |
||
68 | |||
69 | $output->writeln($errout); |
||
70 | |||
71 | return -1; |
||
72 | } else { |
||
73 | 1 | return 0; |
|
74 | } |
||
75 | } |
||
76 | |||
77 | 1 | public function checkprerequisiti($bundlename, $mwbfile, $output) |
|
128 | |||
129 | 1 | public function getScriptGenerator() |
|
130 | { |
||
131 | 1 | $scriptGenerator = ""; |
|
132 | 1 | if (version_compare(\Symfony\Component\HttpKernel\Kernel::VERSION, '3.0') >= 0) { |
|
133 | 1 | $scriptGenerator = $this->apppaths->getVendorBinPath() . DIRECTORY_SEPARATOR . 'mysql-workbench-schema-export'; |
|
134 | } else { |
||
135 | try { |
||
136 | $scriptGenerator = $this->apppaths->getBinPath() . DIRECTORY_SEPARATOR . 'mysql-workbench-schema-export'; |
||
137 | } catch (\Exception $exc) { |
||
138 | //echo $exc->getTraceAsString(); |
||
|
|||
139 | if (!file_exists($scriptGenerator)) { |
||
140 | $scriptGenerator = $this->apppaths->getVendorBinPath() . DIRECTORY_SEPARATOR . 'mysql-workbench-schema-export'; |
||
141 | } |
||
142 | } |
||
143 | } |
||
144 | 1 | if (!file_exists($scriptGenerator)) { |
|
145 | $scriptGenerator = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . |
||
146 | 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'mysql-workbench-schema-export'; |
||
147 | } |
||
148 | 1 | if (!$scriptGenerator) { |
|
149 | throw new \Exception("mysql-workbench-schema-export non trovato", -100); |
||
150 | } |
||
151 | 1 | return $scriptGenerator; |
|
152 | } |
||
153 | |||
154 | 1 | public function getExportJsonFile() |
|
155 | { |
||
156 | 1 | $fs = new Filesystem(); |
|
157 | 1 | $cachedir = $this->apppaths->getCachePath(); |
|
158 | 1 | $exportJson = $cachedir . DIRECTORY_SEPARATOR . 'export.json'; |
|
159 | 1 | if ($fs->exists($exportJson)) { |
|
160 | 1 | $fs->remove($exportJson); |
|
161 | } |
||
162 | |||
163 | 1 | return $exportJson; |
|
164 | } |
||
165 | |||
166 | 1 | public function removeExportJsonFile() |
|
172 | |||
173 | 1 | public static function getJsonMwbGenerator() |
|
198 | } |
||
199 |
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.