| author | ymh <ymh.work@gmail.com> |
| Tue, 21 Feb 2012 15:15:22 +0100 | |
| changeset 74 | 901463f9b11c |
| parent 42 | 0e57c730bb18 |
| permissions | -rwxr-xr-x |
| 25 | 1 |
<?php |
2 |
/* |
|
3 |
* This file is part of the WikiTagBundle package. |
|
4 |
* |
|
5 |
* (c) IRI <http://www.iri.centrepompidou.fr/> |
|
6 |
* |
|
7 |
* For the full copyright and license information, please view the LICENSE |
|
8 |
* file that was distributed with this source code. |
|
9 |
*/ |
|
10 |
||
11 |
namespace IRI\Bundle\WikiTagBundle\Command; |
|
12 |
||
13 |
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
14 |
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
15 |
use Symfony\Component\Console\Input\InputArgument; |
|
16 |
use Symfony\Component\Console\Input\InputOption; |
|
17 |
use Symfony\Component\Console\Input\InputInterface; |
|
18 |
use Symfony\Component\Console\Output\OutputInterface; |
|
19 |
use Symfony\Component\Console\Output\Output; |
|
20 |
use Doctrine\ORM\Tools\SchemaTool; |
|
21 |
use Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand; |
|
22 |
use Symfony\Bundle\DoctrineBundle\Command\Proxy\DoctrineCommandHelper; |
|
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
25
diff
changeset
|
23 |
use IRI\Bundle\WikiTagBundle\Utils\FilteredSchemaTool; |
| 25 | 24 |
|
25 |
/** |
|
26 |
* Command to execute the SQL needed to generate the database schema for |
|
27 |
* a given entity manager. |
|
28 |
* |
|
29 |
* This file is a direct adaptation of the Symfony\Bundle\DoctrineBundle\Command\Proxy\CreateSchemaDoctrineCommand |
|
30 |
* |
|
31 |
*/ |
|
32 |
class CreateSchemaDoctrineCommand extends CreateCommand implements ContainerAwareInterface |
|
33 |
{ |
|
34 |
protected function configure() |
|
35 |
{ |
|
36 |
parent::configure(); |
|
37 |
||
38 |
$this |
|
39 |
->setName('wikitag:schema:create') |
|
40 |
->setDescription('Executes (or dumps) the SQL needed to generate the database schema') |
|
41 |
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command') |
|
42 |
->setHelp(<<<EOT |
|
43 |
The <info>doctrine:schema:create</info> command executes the SQL needed to |
|
44 |
generate the database schema for the default entity manager: |
|
45 |
||
46 |
<info>php app/console doctrine:schema:create</info> |
|
47 |
||
48 |
You can also generate the database schema for a specific entity manager: |
|
49 |
||
50 |
<info>php app/console doctrine:schema:create --em=default</info> |
|
51 |
||
52 |
Finally, instead of executing the SQL, you can output the SQL: |
|
53 |
||
54 |
<info>php app/console doctrine:schema:create --dump-sql</info> |
|
55 |
EOT |
|
56 |
); |
|
57 |
} |
|
58 |
||
59 |
/** |
|
60 |
* @var ContainerInterface |
|
61 |
*/ |
|
62 |
private $container; |
|
63 |
||
64 |
protected function getContainer() |
|
65 |
{ |
|
66 |
if (null === $this->container) { |
|
67 |
$this->container = $this->getApplication()->getKernel()->getContainer(); |
|
68 |
} |
|
69 |
||
70 |
return $this->container; |
|
71 |
} |
|
72 |
||
73 |
/** |
|
74 |
* @see ContainerAwareInterface::setContainer() |
|
75 |
*/ |
|
76 |
public function setContainer(ContainerInterface $container = null) |
|
77 |
{ |
|
78 |
$this->container = $container; |
|
79 |
} |
|
80 |
||
81 |
||
82 |
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas) |
|
83 |
{ |
|
84 |
||
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
25
diff
changeset
|
85 |
$filteredSchemaTool = new FilteredSchemaTool($this->getHelper("em")->getEntityManager(), $this->getContainer()); |
| 25 | 86 |
|
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
25
diff
changeset
|
87 |
parent::executeSchemaCommand($input, $output, $filteredSchemaTool, $metadatas); |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
25
diff
changeset
|
88 |
|
| 25 | 89 |
} |
90 |
||
91 |
protected function execute(InputInterface $input, OutputInterface $output) |
|
92 |
{ |
|
93 |
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em')); |
|
94 |
||
95 |
parent::execute($input, $output); |
|
96 |
} |
|
97 |
} |