| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
require_once(dirname(__FILE__).'/sfPropelBaseTask.class.php'); |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
class sfPropelBuildSchemaTask extends sfPropelBaseTask |
|---|
| 22 |
{ |
|---|
| 23 |
|
|---|
| 24 |
* @see sfTask |
|---|
| 25 |
*/ |
|---|
| 26 |
protected function configure() |
|---|
| 27 |
{ |
|---|
| 28 |
$this->addOptions(array( |
|---|
| 29 |
new sfCommandOption('xml', null, sfCommandOption::PARAMETER_NONE, 'Creates an XML schema instead of a YML one'), |
|---|
| 30 |
)); |
|---|
| 31 |
|
|---|
| 32 |
$this->aliases = array('propel-build-schema'); |
|---|
| 33 |
$this->namespace = 'propel'; |
|---|
| 34 |
$this->name = 'build-schema'; |
|---|
| 35 |
$this->briefDescription = 'Creates a schema from an existing database'; |
|---|
| 36 |
|
|---|
| 37 |
$this->detailedDescription = <<<EOF |
|---|
| 38 |
The [propel:build-schema|INFO] task introspects a database to create a schema: |
|---|
| 39 |
|
|---|
| 40 |
[./symfony propel:build-schema|INFO] |
|---|
| 41 |
|
|---|
| 42 |
By default, the task creates a YML file, but you can also create a XML file: |
|---|
| 43 |
|
|---|
| 44 |
[./symfony --xml propel:build-schema|INFO] |
|---|
| 45 |
|
|---|
| 46 |
The XML format contains more information than the YML one. |
|---|
| 47 |
EOF; |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
* @see sfTask |
|---|
| 52 |
*/ |
|---|
| 53 |
protected function execute($arguments = array(), $options = array()) |
|---|
| 54 |
{ |
|---|
| 55 |
$this->callPhing('creole', self::DO_NOT_CHECK_SCHEMA); |
|---|
| 56 |
|
|---|
| 57 |
$xmlSchemaPath = sfConfig::get('sf_config_dir').'/schema.xml'; |
|---|
| 58 |
$ymlSchemaPath = sfConfig::get('sf_config_dir').'/schema.yml'; |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
if (file_exists($xmlSchemaPath)) |
|---|
| 62 |
{ |
|---|
| 63 |
$schema = file_get_contents($xmlSchemaPath); |
|---|
| 64 |
$schema = preg_replace('/<database\s+name="[^"]+"/s', '<database name="propel" package="lib.model"', $schema); |
|---|
| 65 |
file_put_contents($xmlSchemaPath, $schema); |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
if (!$options['xml']) |
|---|
| 69 |
{ |
|---|
| 70 |
$this->schemaToYML(self::DO_NOT_CHECK_SCHEMA, ''); |
|---|
| 71 |
$this->cleanup(); |
|---|
| 72 |
|
|---|
| 73 |
if (file_exists($xmlSchemaPath)) |
|---|
| 74 |
{ |
|---|
| 75 |
unlink($xmlSchemaPath); |
|---|
| 76 |
} |
|---|
| 77 |
} |
|---|
| 78 |
else |
|---|
| 79 |
{ |
|---|
| 80 |
if (file_exists($ymlSchemaPath)) |
|---|
| 81 |
{ |
|---|
| 82 |
unlink($ymlSchemaPath); |
|---|
| 83 |
} |
|---|
| 84 |
} |
|---|
| 85 |
} |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|