| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the symfony package.
|
|
|
5 |
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
6 |
* (c) Jonathan H. Wage <jonwage@gmail.com>
|
|
|
7 |
*
|
|
|
8 |
* For the full copyright and license information, please view the LICENSE
|
|
|
9 |
* file that was distributed with this source code.
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
require_once(dirname(__FILE__).'/sfDoctrineBaseTask.class.php');
|
|
|
13 |
|
|
|
14 |
/**
|
|
|
15 |
* Create SQL for the current model.
|
|
|
16 |
*
|
|
|
17 |
* @package symfony
|
|
|
18 |
* @subpackage doctrine
|
|
|
19 |
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
20 |
* @author Jonathan H. Wage <jonwage@gmail.com>
|
|
|
21 |
* @version SVN: $Id: sfDoctrineBuildSqlTask.class.php 23922 2009-11-14 14:58:38Z fabien $
|
|
|
22 |
*/
|
|
|
23 |
class sfDoctrineBuildSqlTask extends sfDoctrineBaseTask
|
|
|
24 |
{
|
|
|
25 |
/**
|
|
|
26 |
* @see sfTask
|
|
|
27 |
*/
|
|
|
28 |
protected function configure()
|
|
|
29 |
{
|
|
|
30 |
$this->addOptions(array(
|
|
|
31 |
new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
|
|
|
32 |
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
|
|
|
33 |
));
|
|
|
34 |
|
|
|
35 |
$this->namespace = 'doctrine';
|
|
|
36 |
$this->name = 'build-sql';
|
|
|
37 |
$this->briefDescription = 'Creates SQL for the current model';
|
|
|
38 |
|
|
|
39 |
$this->detailedDescription = <<<EOF
|
|
|
40 |
The [doctrine:build-sql|INFO] task creates SQL statements for table creation:
|
|
|
41 |
|
|
|
42 |
[./symfony doctrine:build-sql|INFO]
|
|
|
43 |
|
|
|
44 |
The generated SQL is optimized for the database configured in [config/databases.yml|COMMENT]:
|
|
|
45 |
|
|
|
46 |
[doctrine.database = mysql|INFO]
|
|
|
47 |
EOF;
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* @see sfTask
|
|
|
52 |
*/
|
|
|
53 |
protected function execute($arguments = array(), $options = array())
|
|
|
54 |
{
|
|
|
55 |
$this->logSection('doctrine', 'generating sql for models');
|
|
|
56 |
|
|
|
57 |
$path = sfConfig::get('sf_data_dir').'/sql';
|
|
|
58 |
if (!is_dir($path)) {
|
|
|
59 |
$this->getFilesystem()->mkdirs($path);
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
$databaseManager = new sfDatabaseManager($this->configuration);
|
|
|
63 |
$this->callDoctrineCli('generate-sql');
|
|
|
64 |
}
|
|
|
65 |
}
|