| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
require_once(dirname(__FILE__).'/sfDoctrineBaseTask.class.php'); |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
class sfDoctrineBuildDbTask extends sfDoctrineBaseTask |
|---|
| 24 |
{ |
|---|
| 25 |
|
|---|
| 26 |
* @see sfTask |
|---|
| 27 |
*/ |
|---|
| 28 |
protected function configure() |
|---|
| 29 |
{ |
|---|
| 30 |
$this->addArguments(array( |
|---|
| 31 |
new sfCommandArgument('database', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, 'A specific database'), |
|---|
| 32 |
)); |
|---|
| 33 |
|
|---|
| 34 |
$this->addOptions(array( |
|---|
| 35 |
new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true), |
|---|
| 36 |
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), |
|---|
| 37 |
)); |
|---|
| 38 |
|
|---|
| 39 |
$this->aliases = array('doctrine:create-db'); |
|---|
| 40 |
$this->namespace = 'doctrine'; |
|---|
| 41 |
$this->name = 'build-db'; |
|---|
| 42 |
$this->briefDescription = 'Creates database for current model'; |
|---|
| 43 |
|
|---|
| 44 |
$this->detailedDescription = <<<EOF |
|---|
| 45 |
The [doctrine:build-db|INFO] task creates one or more databases based on |
|---|
| 46 |
configuration in [config/databases.yml|COMMENT]: |
|---|
| 47 |
|
|---|
| 48 |
[./symfony doctrine:build-db|INFO] |
|---|
| 49 |
|
|---|
| 50 |
You can specify what databases to create by providing their names: |
|---|
| 51 |
|
|---|
| 52 |
[./symfony doctrine:build-db slave1 slave2|INFO] |
|---|
| 53 |
EOF; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
* @see sfTask |
|---|
| 58 |
*/ |
|---|
| 59 |
protected function execute($arguments = array(), $options = array()) |
|---|
| 60 |
{ |
|---|
| 61 |
$databaseManager = new sfDatabaseManager($this->configuration); |
|---|
| 62 |
$databases = $this->getDoctrineDatabases($databaseManager, count($arguments['database']) ? $arguments['database'] : null); |
|---|
| 63 |
|
|---|
| 64 |
$environment = $this->configuration instanceof sfApplicationConfiguration ? $this->configuration->getEnvironment() : 'all'; |
|---|
| 65 |
|
|---|
| 66 |
foreach ($databases as $name => $database) |
|---|
| 67 |
{ |
|---|
| 68 |
$this->logSection('doctrine', sprintf('Creating "%s" environment "%s" database', $environment, $name)); |
|---|
| 69 |
try |
|---|
| 70 |
{ |
|---|
| 71 |
$database->getDoctrineConnection()->createDatabase(); |
|---|
| 72 |
} |
|---|
| 73 |
catch (Exception $e) |
|---|
| 74 |
{ |
|---|
| 75 |
$this->logSection('doctrine', $e->getMessage(), null, 'ERROR'); |
|---|
| 76 |
} |
|---|
| 77 |
} |
|---|
| 78 |
} |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|