Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 87 lines (76 sloc) 3.007 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
<?php

/**
* This file is part of the PropelBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Propel\PropelBundle\Command;

use Propel\PropelBundle\Command\AbstractCommand;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;

/**
* ReverseCommand.
*
* @author William DURAND <william.durand1@gmail.com>
*/
class ReverseCommand extends AbstractCommand
{
    /**
* @see Command
*/
    protected function configure()
    {
        $this
            ->setDescription('Generate XML schema from reverse-engineered database')
            ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use')
            ->setHelp(<<<EOT
The <info>propel:reverse</info> command generates an XML schema from reverse-engineered database.
  <info>php app/console propel:reverse</info>

The <info>--connection</info> parameter allows you to change the connection to use.
The default connection is the active connection (propel.dbal.default_connection).
EOT
            )
            ->setName('propel:reverse')
        ;

    }

    /**
* @see Command
*
* @throws \InvalidArgumentException When the target directory does not exist
*/
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if ($input->getOption('verbose')) {
            $this->additionalPhingArgs[] = 'verbose';
        }

        list($name, $defaultConfig) = $this->getConnection($input, $output);

        $ret = $this->callPhing('reverse', array(
            'propel.project' => $name,
            'propel.database' => $defaultConfig['adapter'],
            'propel.database.url' => $defaultConfig['connection']['dsn'],
            'propel.database.user' => $defaultConfig['connection']['user'],
            'propel.database.password' => isset($defaultConfig['connection']['password']) ? $defaultConfig['connection']['password'] : '',
        ));

        if (true === $ret) {
            $filesystem = new Filesystem();
            $generated = $this->getCacheDir().'/schema.xml';
            $filename = $name . '_reversed_schema.xml';
            $destFile = $this->getApplication()->getKernel()->getRootDir() . '/propel/generated-schemas/' . $filename;

            if (file_exists($generated)) {
                $filesystem->copy($generated, $destFile);
                $output->writeln(array(
                    '',
                    sprintf('>> <info>File+</info> %s', $destFile),
                ));
            } else {
                $output->writeln(array('', 'No generated files.'));
            }
        } else {
            $this->writeTaskError($output, 'reverse');
        }
    }
}
Something went wrong with that request. Please try again.