1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Doctrine\ORM\Tools\Console\Command; |
21
|
|
|
|
22
|
|
|
use Doctrine\ORM\Tools\SchemaValidator; |
23
|
|
|
use Symfony\Component\Console\Command\Command; |
24
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
25
|
|
|
use Symfony\Component\Console\Input\InputOption; |
26
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
27
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Command to validate that the current mapping is valid. |
31
|
|
|
* |
32
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
33
|
|
|
* @link www.doctrine-project.com |
34
|
|
|
* @since 1.0 |
35
|
|
|
* @author Benjamin Eberlei <[email protected]> |
36
|
|
|
* @author Guilherme Blanco <[email protected]> |
37
|
|
|
* @author Jonathan Wage <[email protected]> |
38
|
|
|
* @author Roman Borschel <[email protected]> |
39
|
|
|
*/ |
40
|
|
|
class ValidateSchemaCommand extends Command |
41
|
|
|
{ |
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
protected function configure() |
46
|
|
|
{ |
47
|
|
|
$this->setName('orm:validate-schema') |
48
|
|
|
->setDescription('Validate the mapping files') |
49
|
|
|
->addOption('skip-mapping', null, InputOption::VALUE_NONE, 'Skip the mapping validation check') |
50
|
|
|
->addOption('skip-sync', null, InputOption::VALUE_NONE, 'Skip checking if the mapping is in sync with the database') |
51
|
|
|
->setHelp('Validate that the mapping files are correct and in sync with the database.'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
58
|
|
|
{ |
59
|
|
|
$ui = new SymfonyStyle($input, $output); |
60
|
|
|
|
61
|
|
|
$em = $this->getHelper('em')->getEntityManager(); |
62
|
|
|
$validator = new SchemaValidator($em); |
63
|
|
|
$exit = 0; |
64
|
|
|
|
65
|
|
|
$ui->section('Mapping'); |
66
|
|
|
|
67
|
|
|
if ($input->getOption('skip-mapping')) { |
68
|
|
|
$ui->text('<comment>[SKIPPED] The mapping was not checked.</comment>'); |
69
|
|
|
} elseif ($errors = $validator->validateMapping()) { |
70
|
|
|
foreach ($errors as $className => $errorMessages) { |
71
|
|
|
$ui->text( |
72
|
|
|
sprintf( |
73
|
|
|
'<error>[FAIL]</error> The entity-class <comment>%s</comment> mapping is invalid:', |
74
|
|
|
$className |
75
|
|
|
) |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
$ui->listing($errorMessages); |
79
|
|
|
$ui->newLine(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
++$exit; |
83
|
|
|
} else { |
84
|
|
|
$ui->success('The mapping files are correct.'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$ui->section('Database'); |
88
|
|
|
|
89
|
|
|
if ($input->getOption('skip-sync')) { |
90
|
|
|
$ui->text('<comment>[SKIPPED] The database was not checked for synchronicity.</comment>'); |
91
|
|
|
} elseif ( ! $validator->schemaInSyncWithMetadata()) { |
92
|
|
|
$ui->error('The database schema is not in sync with the current mapping file.'); |
93
|
|
|
$exit += 2; |
94
|
|
|
} else { |
95
|
|
|
$ui->success('The database schema is in sync with the mapping files.'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $exit; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|