| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
class sfFilesystemFixturesCleanTask extends sfFilesystemFixturesBaseTask |
|---|
| 19 |
{ |
|---|
| 20 |
|
|---|
| 21 |
* @see sfTask |
|---|
| 22 |
*/ |
|---|
| 23 |
protected function configure() |
|---|
| 24 |
{ |
|---|
| 25 |
$this->addOptions(array( |
|---|
| 26 |
new sfCommandOption('remove-dirs', null, sfCommandOption::PARAMETER_OPTIONAL, 'Remove directories if empty', 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 = 'clean'; |
|---|
| 33 |
$this->briefDescription = 'Removes existing filesystem fixture data'; |
|---|
| 34 |
$this->detailedDescription = <<<EOF |
|---|
| 35 |
The [fs-fixtures:clean|INFO] task removes existing filesystem fixture data: |
|---|
| 36 |
|
|---|
| 37 |
[./symfony fs-fixtures:clean|INFO] |
|---|
| 38 |
|
|---|
| 39 |
Fixtures from the environment-specific directory will also be removed 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 |
'remove-dirs' => null, |
|---|
| 51 |
), $options); |
|---|
| 52 |
$options['remove-dirs'] = $this->translateStringBoolean($options['remove-dirs']); |
|---|
| 53 |
|
|---|
| 54 |
$this->cleanDirectory(sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fs_fixtures', $options); |
|---|
| 55 |
$this->cleanDirectory(sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fs_fixtures_'.sfFilesystemFixtures::getInstance()->getEnvironment(), $options); |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
* Removes files from the filesystem that would be placed there by the filesystem fixtures system |
|---|
| 60 |
* |
|---|
| 61 |
* @param string $path The path containing the filesystem fixtures |
|---|
| 62 |
* @param array $options An array of options |
|---|
| 63 |
*/ |
|---|
| 64 |
protected function cleanDirectory($path, array $options) |
|---|
| 65 |
{ |
|---|
| 66 |
if (!is_dir($path)) return; |
|---|
| 67 |
if (!$path = realpath($path)) return; |
|---|
| 68 |
|
|---|
| 69 |
$this->logSection('fs-fixtures', 'Cleaning fs fixtures from "'.$path.'"'); |
|---|
| 70 |
sfFilesystemFixtures::getInstance()->cleanDirectory($path, $options['remove-dirs']); |
|---|
| 71 |
} |
|---|
| 72 |
} |
|---|