| 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 sfDoctrineDumpDataTask extends sfDoctrineBaseTask |
|---|
| 24 |
{ |
|---|
| 25 |
|
|---|
| 26 |
* @see sfTask |
|---|
| 27 |
*/ |
|---|
| 28 |
protected function configure() |
|---|
| 29 |
{ |
|---|
| 30 |
$this->addArguments(array( |
|---|
| 31 |
new sfCommandArgument('target', sfCommandArgument::OPTIONAL, 'The target filename'), |
|---|
| 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-dump-data'); |
|---|
| 40 |
$this->namespace = 'doctrine'; |
|---|
| 41 |
$this->name = 'data-dump'; |
|---|
| 42 |
$this->briefDescription = 'Dumps data to the fixtures directory'; |
|---|
| 43 |
|
|---|
| 44 |
$this->detailedDescription = <<<EOF |
|---|
| 45 |
The [doctrine:data-dump|INFO] task dumps database data: |
|---|
| 46 |
|
|---|
| 47 |
[./symfony doctrine:data-dump|INFO] |
|---|
| 48 |
|
|---|
| 49 |
The task dumps the database data in [data/fixtures/%target%|COMMENT]. |
|---|
| 50 |
|
|---|
| 51 |
The dump file is in the YML format and can be reimported by using |
|---|
| 52 |
the [doctrine:data-load|INFO] task. |
|---|
| 53 |
|
|---|
| 54 |
[./symfony doctrine:data-load frontend|INFO] |
|---|
| 55 |
EOF; |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
* @see sfTask |
|---|
| 60 |
*/ |
|---|
| 61 |
protected function execute($arguments = array(), $options = array()) |
|---|
| 62 |
{ |
|---|
| 63 |
$databaseManager = new sfDatabaseManager($this->configuration); |
|---|
| 64 |
|
|---|
| 65 |
$config = $this->getCliConfig(); |
|---|
| 66 |
$dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'fixtures'; |
|---|
| 67 |
Doctrine_Lib::makeDirectories($dir); |
|---|
| 68 |
|
|---|
| 69 |
$args = array(); |
|---|
| 70 |
if (isset($arguments['target'])) |
|---|
| 71 |
{ |
|---|
| 72 |
$filename = $arguments['target']; |
|---|
| 73 |
|
|---|
| 74 |
if (!sfToolkit::isPathAbsolute($filename)) |
|---|
| 75 |
{ |
|---|
| 76 |
$filename = $dir . DIRECTORY_SEPARATOR . $filename; |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
Doctrine_Lib::makeDirectories(dirname($filename)); |
|---|
| 80 |
|
|---|
| 81 |
$args = array('data_fixtures_path' => array($filename)); |
|---|
| 82 |
$this->logSection('doctrine', sprintf('dumping data to fixtures to "%s"', $filename)); |
|---|
| 83 |
} else { |
|---|
| 84 |
$this->logSection('doctrine', sprintf('dumping data to fixtures to "%s"', $config['data_fixtures_path'][0])); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
$this->callDoctrineCli('dump-data', $args); |
|---|
| 88 |
} |
|---|
| 89 |
} |
|---|