Skip to content

Instantly share code, notes, and snippets.

@chalasr
Created April 15, 2016 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chalasr/579d48a98cf6b3d915d2ad9a8a4185de to your computer and use it in GitHub Desktop.
Save chalasr/579d48a98cf6b3d915d2ad9a8a4185de to your computer and use it in GitHub Desktop.
Overridde the Doctrine UpdateSchemaCommand (doctrine:schema:update command).
// src/AppBundle/Command/CustomUpdateSchemaCommand.php
<?php
namespace AppBundle\Command;
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\UpdateSchemaDoctrineCommand;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Command\Command;
class CustomUpdateSchemaCommand extends UpdateSchemaDoctrineCommand
{
/** @var EntityManagerInterface */
private $em;
/**
* @param EntityManagerInterface $em
*/
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
parent::__construct();
}
/**
* {@inheritDoc}
*/
protected function configure()
{
parent::configure();
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Hello world');
$repository = $this->em->getRepository('AppBundle:Foo');
// Perform your custom query
return parent::execute($input, $output);
}
}
services:
app.command.custom_schema_update_command:
class: App\SportBundle\Command\CustomUpdateSchemaCommand
arguments: ["@doctrine.orm.entity_manager"]
tags:
- { name: console.command }
@chalasr
Copy link
Author

chalasr commented Apr 15, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment