Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / lib / Doctrine / ORM / Tools / Console / Command / ValidateSchemaCommand.php
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 Symfony\Component\Console\Input\InputArgument,
23     Symfony\Component\Console\Input\InputOption,
24     Symfony\Component\Console;
25
26 /**
27  * Validate that the current mapping is valid
28  *
29  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
30  * @link        www.doctrine-project.com
31  * @since       1.0
32  * @author      Benjamin Eberlei <kontakt@beberlei.de>
33  * @author      Guilherme Blanco <guilhermeblanco@hotmail.com>
34  * @author      Jonathan Wage <jonwage@gmail.com>
35  * @author      Roman Borschel <roman@code-factory.org>
36  */
37 class ValidateSchemaCommand extends Console\Command\Command
38 {
39     /**
40      * @see Console\Command\Command
41      */
42     protected function configure()
43     {
44         $this
45         ->setName('orm:validate-schema')
46         ->setDescription('Validate the mapping files.')
47         ->setHelp(<<<EOT
48 'Validate that the mapping files are correct and in sync with the database.'
49 EOT
50         );
51     }
52
53     /**
54      * @see Console\Command\Command
55      */
56     protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
57     {
58         $em = $this->getHelper('em')->getEntityManager();
59
60         $validator = new \Doctrine\ORM\Tools\SchemaValidator($em);
61         $errors = $validator->validateMapping();
62
63         $exit = 0;
64         if ($errors) {
65             foreach ($errors as $className => $errorMessages) {
66                 $output->write("<error>[Mapping]  FAIL - The entity-class '" . $className . "' mapping is invalid:</error>\n");
67                 foreach ($errorMessages as $errorMessage) {
68                     $output->write('* ' . $errorMessage . "\n");
69                 }
70                 $output->write("\n");
71             }
72             $exit += 1;
73         } else {
74             $output->write('<info>[Mapping]  OK - The mapping files are correct.</info>' . "\n");
75         }
76
77         if (!$validator->schemaInSyncWithMetadata()) {
78             $output->write('<error>[Database] FAIL - The database schema is not in sync with the current mapping file.</error>' . "\n");
79             $exit += 2;
80         } else {
81             $output->write('<info>[Database] OK - The database schema is in sync with the mapping files.</info>' . "\n");
82         }
83
84         return $exit;
85     }
86 }