Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand::execute PHP Method

execute() public method

public execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    public function execute(InputInterface $input, OutputInterface $output)
    {
        $isDbalOld = DbalVersion::compare('2.2.0') > 0;
        $configuration = $this->getMigrationConfiguration($input, $output);
        $conn = $configuration->getConnection();
        $platform = $conn->getDatabasePlatform();
        if ($filterExpr = $input->getOption('filter-expression')) {
            if ($isDbalOld) {
                throw new \InvalidArgumentException('The "--filter-expression" option can only be used as of Doctrine DBAL 2.2');
            }
            $conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpr);
        }
        $fromSchema = $conn->getSchemaManager()->createSchema();
        $toSchema = $this->getSchemaProvider()->createSchema();
        //Not using value from options, because filters can be set from config.yml
        if (!$isDbalOld && ($filterExpr = $conn->getConfiguration()->getFilterSchemaAssetsExpression())) {
            foreach ($toSchema->getTables() as $table) {
                $tableName = $table->getName();
                if (!preg_match($filterExpr, $this->resolveTableName($tableName))) {
                    $toSchema->dropTable($tableName);
                }
            }
        }
        $up = $this->buildCodeFromSql($configuration, $fromSchema->getMigrateToSql($toSchema, $platform), $input->getOption('formatted'), $input->getOption('line-length'));
        $down = $this->buildCodeFromSql($configuration, $fromSchema->getMigrateFromSql($toSchema, $platform), $input->getOption('formatted'), $input->getOption('line-length'));
        if (!$up && !$down) {
            $output->writeln('No changes detected in your mapping information.', 'ERROR');
            return;
        }
        $version = $configuration->generateVersionNumber();
        $path = $this->generateMigration($configuration, $input, $version, $up, $down);
        $output->writeln(sprintf('Generated new migration class to "<info>%s</info>" from schema differences.', $path));
        $output->writeln(file_get_contents($path));
    }

Usage Example

 public function execute(InputInterface $input, OutputInterface $output)
 {
     DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
     $configuration = $this->getMigrationConfiguration($input, $output);
     DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
     parent::execute($input, $output);
 }
All Usage Examples Of Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand::execute