vendor/doctrine/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     1 <?php
       
     2 /*
       
     3  *  $Id$
       
     4  *
       
     5  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
     6  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
     7  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
     8  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
     9  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    10  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    11  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    12  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    13  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    14  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    15  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    16  *
       
    17  * This software consists of voluntary contributions made by many individuals
       
    18  * and is licensed under the LGPL. For more information, see
       
    19  * <http://www.doctrine-project.org>.
       
    20 */
       
    21 
       
    22 namespace Doctrine\ORM\Tools\Console\Command;
       
    23 
       
    24 use Symfony\Component\Console\Input\InputArgument,
       
    25     Symfony\Component\Console\Input\InputOption,
       
    26     Symfony\Component\Console;
       
    27 
       
    28 /**
       
    29  * Validate that the current mapping is valid
       
    30  *
       
    31  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
       
    32  * @link        www.doctrine-project.com
       
    33  * @since       1.0
       
    34  * @version     $Revision$
       
    35  * @author      Benjamin Eberlei <kontakt@beberlei.de>
       
    36  * @author      Guilherme Blanco <guilhermeblanco@hotmail.com>
       
    37  * @author      Jonathan Wage <jonwage@gmail.com>
       
    38  * @author      Roman Borschel <roman@code-factory.org>
       
    39  */
       
    40 class ValidateSchemaCommand extends Console\Command\Command
       
    41 {
       
    42     /**
       
    43      * @see Console\Command\Command
       
    44      */
       
    45     protected function configure()
       
    46     {
       
    47         $this
       
    48         ->setName('orm:validate-schema')
       
    49         ->setDescription('Validate that the mapping files.')
       
    50         ->setHelp(<<<EOT
       
    51 'Validate that the mapping files are correct and in sync with the database.'
       
    52 EOT
       
    53         );
       
    54     }
       
    55 
       
    56     /**
       
    57      * @see Console\Command\Command
       
    58      */
       
    59     protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
       
    60     {
       
    61         $em = $this->getHelper('em')->getEntityManager();
       
    62 
       
    63         $validator = new \Doctrine\ORM\Tools\SchemaValidator($em);
       
    64         $errors = $validator->validateMapping();
       
    65 
       
    66         $exit = 0;
       
    67         if ($errors) {
       
    68             foreach ($errors AS $className => $errorMessages) {
       
    69                 $output->write("<error>[Mapping]  FAIL - The entity-class '" . $className . "' mapping is invalid:</error>\n");
       
    70                 foreach ($errorMessages AS $errorMessage) {
       
    71                     $output->write('* ' . $errorMessage . "\n");
       
    72                 }
       
    73                 $output->write("\n");
       
    74             }
       
    75             $exit += 1;
       
    76         } else {
       
    77             $output->write('<info>[Mapping]  OK - The mapping files are correct.</info>' . "\n");
       
    78         }
       
    79 
       
    80         if (!$validator->schemaInSyncWithMetadata()) {
       
    81             $output->write('<error>[Database] FAIL - The database schema is not in sync with the current mapping file.</error>' . "\n");
       
    82             $exit += 2;
       
    83         } else {
       
    84             $output->write('<info>[Database] OK - The database schema is in sync with the mapping files.</info>' . "\n");
       
    85         }
       
    86 
       
    87         exit($exit);
       
    88     }
       
    89 }