Example #1
0
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $application = $this->getApplication();
     #source
     $source = $input->getOption('source-em') ?: 'default';
     $emSource = $application->getKernel()->getContainer()->get('doctrine')->getManager($source);
     $helperSet = $application->getHelperSet();
     $helperSet->set(new ConnectionHelper($emSource->getConnection()), 'source-db');
     $helperSet->set(new EntityManagerHelper($emSource), 'source-em');
     #audit
     $audit = $input->getOption('audit-em') ?: 'audit';
     $emAudit = $application->getKernel()->getContainer()->get('doctrine')->getManager($audit);
     $helperSet->set(new ConnectionHelper($emAudit->getConnection()), 'audit-db');
     $helperSet->set(new EntityManagerHelper($emAudit), 'audit-em');
     $sourceEmHelper = $this->getHelper('source-em');
     $auditEmHelper = $this->getHelper('audit-em');
     /* @var $em \Doctrine\ORM\EntityManager */
     $sourceEm = $sourceEmHelper->getEntityManager();
     $auditEm = $auditEmHelper->getEntityManager();
     $sourceMetadatas = $sourceEm->getMetadataFactory()->getAllMetadata();
     if (!empty($sourceMetadatas)) {
         // Create SchemaTool
         $auditTool = new SchemaTool($auditEm, $sourceEm);
         return $this->execSchemaCommand($input, $output, $auditTool, $sourceMetadatas);
     } else {
         $output->writeln('No Metadata Classes to process.');
         return 0;
     }
     return parent::execute($input, $output);
 }
 protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
 {
     /** @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
     $newMetadatas = [];
     foreach ($metadatas as $metadata) {
         if (!in_array($metadata->getName(), $this->ignoredEntities)) {
             array_push($newMetadatas, $metadata);
         }
     }
     parent::executeSchemaCommand($input, $output, $schemaTool, $newMetadatas);
 }
    /**
     * {@inheritDoc}
     */
    protected function configure()
    {
        parent::configure();
        $this->setName('rezzza:doctrine-multi-mapping:schema:update')->setDescription('Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata')->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')->setHelp(<<<EOT
The <info>rezzza:doctrine-multi-mapping:schema:update</info> command generates the SQL needed to
synchronize the database schema with the current mapping metadata of the
default entity manager.

For example, if you add metadata for a new column to an entity, this command
would generate and output the SQL needed to add the new column to the database:

<info>php app/console rezzza:doctrine-multi-mapping:schema:update --dump-sql</info>

Alternatively, you can execute the generated queries:

<info>php app/console rezzza:doctrine-multi-mapping:schema:update --force</info>

You can also update the database schema for a specific entity manager:

<info>php app/console rezzza:doctrine-multi-mapping:schema:update --em=default</info>
EOT
);
    }