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.
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>.
20 namespace Doctrine\ORM\Tools\Console\Command;
22 use Symfony\Component\Console\Input\InputArgument,
23 Symfony\Component\Console\Input\InputOption,
24 Symfony\Component\Console;
27 * Validate that the current mapping is valid
29 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
30 * @link www.doctrine-project.com
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>
37 class ValidateSchemaCommand extends Console\Command\Command
40 * @see Console\Command\Command
42 protected function configure()
45 ->setName('orm:validate-schema')
46 ->setDescription('Validate the mapping files.')
48 'Validate that the mapping files are correct and in sync with the database.'
54 * @see Console\Command\Command
56 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
58 $em = $this->getHelper('em')->getEntityManager();
60 $validator = new \Doctrine\ORM\Tools\SchemaValidator($em);
61 $errors = $validator->validateMapping();
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");
74 $output->write('<info>[Mapping] OK - The mapping files are correct.</info>' . "\n");
77 if (!$validator->schemaInSyncWithMetadata()) {
78 $output->write('<error>[Database] FAIL - The database schema is not in sync with the current mapping file.</error>' . "\n");
81 $output->write('<info>[Database] OK - The database schema is in sync with the mapping files.</info>' . "\n");