| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
class sfFilesystemFixturesLoadTask extends sfBaseTask |
|---|
| 19 |
{ |
|---|
| 20 |
|
|---|
| 21 |
* @see sfTask |
|---|
| 22 |
*/ |
|---|
| 23 |
protected function configure() |
|---|
| 24 |
{ |
|---|
| 25 |
$this->addOptions(array( |
|---|
| 26 |
new sfCommandOption('overwrite', null, sfCommandOption::PARAMETER_OPTIONAL, 'Overwrite existing files', null), |
|---|
| 27 |
new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', null), |
|---|
| 28 |
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), |
|---|
| 29 |
)); |
|---|
| 30 |
|
|---|
| 31 |
$this->namespace = 'fs-fixtures'; |
|---|
| 32 |
$this->name = 'load'; |
|---|
| 33 |
$this->briefDescription = 'Loads filesystem fixture data'; |
|---|
| 34 |
$this->detailedDescription = <<<EOF |
|---|
| 35 |
The [fs_fixtures:load|INFO] task loads filesystem fixture data: |
|---|
| 36 |
|
|---|
| 37 |
[./symfony fs_fixtures:load|INFO] |
|---|
| 38 |
|
|---|
| 39 |
Fixtures will also be loaded from the environment-specific directory if present. |
|---|
| 40 |
EOF; |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
* @see sfTask |
|---|
| 45 |
*/ |
|---|
| 46 |
protected function execute($arguments = null, $options = null) |
|---|
| 47 |
{ |
|---|
| 48 |
if (null === $options) $options = array(); |
|---|
| 49 |
$options = array_merge(array( |
|---|
| 50 |
'overwrite' => null, |
|---|
| 51 |
), $options); |
|---|
| 52 |
$options['overwrite'] = $this->translateStringBoolean($options['overwrite']); |
|---|
| 53 |
|
|---|
| 54 |
$this->processDirectory(sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fs_fixtures', $options); |
|---|
| 55 |
$this->processDirectory(sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fs_fixtures_'.sfFilesystemFixtures::getInstance()->getEnvironment(), $options); |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
* Translates a string into the equivalent boolean value |
|---|
| 60 |
* |
|---|
| 61 |
* @param string $value The string value |
|---|
| 62 |
* |
|---|
| 63 |
* @return boolean The boolean equivalent |
|---|
| 64 |
*/ |
|---|
| 65 |
protected function translateStringBoolean($value) |
|---|
| 66 |
{ |
|---|
| 67 |
if (null === $value || 'null' === $value) return null; |
|---|
| 68 |
|
|---|
| 69 |
$falseValues = array( |
|---|
| 70 |
'no', |
|---|
| 71 |
'off', |
|---|
| 72 |
'false', |
|---|
| 73 |
); |
|---|
| 74 |
|
|---|
| 75 |
if (!$value) return false; |
|---|
| 76 |
if (in_array(strtolower($value), $falseValues)) return false; |
|---|
| 77 |
|
|---|
| 78 |
return true; |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
* Copies files from the filesystem fixtures directory to their intended locations |
|---|
| 83 |
* |
|---|
| 84 |
* @param string $path The path containing the filesystem fixtures |
|---|
| 85 |
* @param array $options An array of options |
|---|
| 86 |
*/ |
|---|
| 87 |
protected function processDirectory($path, array $options) |
|---|
| 88 |
{ |
|---|
| 89 |
if (!is_dir($path)) return; |
|---|
| 90 |
if (!$path = realpath($path)) return; |
|---|
| 91 |
|
|---|
| 92 |
$this->logSection('fs-fixtures', 'Loading fs fixtures from "'.$path.'"'); |
|---|
| 93 |
sfFilesystemFixtures::getInstance()->processDirectory($path, $options['overwrite']); |
|---|
| 94 |
} |
|---|
| 95 |
} |
|---|