| 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 sfDoctrineDataLoadTask extends sfDoctrineBaseTask |
|---|
| 24 |
{ |
|---|
| 25 |
|
|---|
| 26 |
* @see sfTask |
|---|
| 27 |
*/ |
|---|
| 28 |
protected function configure() |
|---|
| 29 |
{ |
|---|
| 30 |
$this->addArguments(array( |
|---|
| 31 |
new sfCommandArgument('dir_or_file', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, 'Directory or file to load'), |
|---|
| 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 |
new sfCommandOption('append', null, sfCommandOption::PARAMETER_NONE, 'Don\'t delete current data in the database'), |
|---|
| 38 |
)); |
|---|
| 39 |
|
|---|
| 40 |
$this->aliases = array('doctrine-load-data'); |
|---|
| 41 |
$this->namespace = 'doctrine'; |
|---|
| 42 |
$this->name = 'data-load'; |
|---|
| 43 |
$this->briefDescription = 'Loads YAML fixture data'; |
|---|
| 44 |
|
|---|
| 45 |
$this->detailedDescription = <<<EOF |
|---|
| 46 |
The [doctrine:data-load|INFO] task loads data fixtures into the database: |
|---|
| 47 |
|
|---|
| 48 |
[./symfony doctrine:data-load|INFO] |
|---|
| 49 |
|
|---|
| 50 |
The task loads data from all the files found in [data/fixtures/|COMMENT]. |
|---|
| 51 |
|
|---|
| 52 |
If you want to load data from specific files or directories, you can append |
|---|
| 53 |
them as arguments: |
|---|
| 54 |
|
|---|
| 55 |
[./symfony doctrine:data-load data/fixtures/dev data/fixtures/users.yml|INFO] |
|---|
| 56 |
|
|---|
| 57 |
If you don't want the task to remove existing data in the database, |
|---|
| 58 |
use the [--append|COMMENT] option: |
|---|
| 59 |
|
|---|
| 60 |
[./symfony doctrine:data-load --append|INFO] |
|---|
| 61 |
EOF; |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
* @see sfTask |
|---|
| 66 |
*/ |
|---|
| 67 |
protected function execute($arguments = array(), $options = array()) |
|---|
| 68 |
{ |
|---|
| 69 |
$databaseManager = new sfDatabaseManager($this->configuration); |
|---|
| 70 |
|
|---|
| 71 |
if (!count($arguments['dir_or_file'])) |
|---|
| 72 |
{ |
|---|
| 73 |
|
|---|
| 74 |
$config = $this->getCliConfig(); |
|---|
| 75 |
$arguments['dir_or_file'] = $config['data_fixtures_path']; |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
$doctrineArguments = array( |
|---|
| 79 |
'data_fixtures_path' => $arguments['dir_or_file'], |
|---|
| 80 |
'append' => $options['append'], |
|---|
| 81 |
); |
|---|
| 82 |
|
|---|
| 83 |
foreach ($arguments['dir_or_file'] as $target) |
|---|
| 84 |
{ |
|---|
| 85 |
$this->logSection('doctrine', sprintf('Loading data fixtures from "%s"', $target)); |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
$this->callDoctrineCli('load-data', $doctrineArguments); |
|---|
| 89 |
} |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|