| 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 sfDoctrineLoadDataTask 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 |
new sfCommandOption('append', null, sfCommandOption::PARAMETER_NONE, 'Don\'t delete current data in the database'), |
|---|
| 34 |
new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'), |
|---|
| 35 |
new sfCommandOption('dir', null, sfCommandOption::PARAMETER_REQUIRED | sfCommandOption::IS_ARRAY, 'The directories to look for fixtures'), |
|---|
| 36 |
)); |
|---|
| 37 |
|
|---|
| 38 |
$this->aliases = array('doctrine-load-data'); |
|---|
| 39 |
$this->namespace = 'doctrine'; |
|---|
| 40 |
$this->name = 'data-load'; |
|---|
| 41 |
$this->briefDescription = 'Loads data from fixtures directory'; |
|---|
| 42 |
|
|---|
| 43 |
$this->detailedDescription = <<<EOF |
|---|
| 44 |
The [doctrine:data-load|INFO] task loads data fixtures into the database: |
|---|
| 45 |
|
|---|
| 46 |
[./symfony doctrine:data-load frontend|INFO] |
|---|
| 47 |
|
|---|
| 48 |
The task loads data from all the files found in [data/fixtures/|COMMENT]. |
|---|
| 49 |
|
|---|
| 50 |
If you want to load data from other directories, you can use |
|---|
| 51 |
the [--dir|COMMENT] option: |
|---|
| 52 |
|
|---|
| 53 |
[./symfony doctrine:data-load --dir="data/fixtures" --dir="data/data" frontend|INFO] |
|---|
| 54 |
|
|---|
| 55 |
If you don't want the task to remove existing data in the database, |
|---|
| 56 |
use the [--append|COMMENT] option: |
|---|
| 57 |
|
|---|
| 58 |
[./symfony doctrine:data-load --append frontend|INFO] |
|---|
| 59 |
EOF; |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
* @see sfTask |
|---|
| 64 |
*/ |
|---|
| 65 |
protected function execute($arguments = array(), $options = array()) |
|---|
| 66 |
{ |
|---|
| 67 |
$databaseManager = new sfDatabaseManager($this->configuration); |
|---|
| 68 |
|
|---|
| 69 |
$arguments = array(); |
|---|
| 70 |
if (isset($options['append']) && $options['append']) |
|---|
| 71 |
{ |
|---|
| 72 |
$arguments['append'] = $options['append']; |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
if (isset($options['dir']) && $options['dir']) |
|---|
| 76 |
{ |
|---|
| 77 |
$arguments['data_fixtures_path'] = $options['dir']; |
|---|
| 78 |
foreach ($options['dir'] as $dir) |
|---|
| 79 |
{ |
|---|
| 80 |
$this->logSection('doctrine', sprintf('loading data fixtures from "%s"', $dir)); |
|---|
| 81 |
} |
|---|
| 82 |
} else { |
|---|
| 83 |
$config = $this->getCliConfig(); |
|---|
| 84 |
$this->logSection('doctrine', sprintf('loading data fixtures from "%s"', $config['data_fixtures_path'][0])); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
$this->callDoctrineCli('load-data', $arguments); |
|---|
| 88 |
} |
|---|
| 89 |
} |
|---|