| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfProjectClearControllersTask extends sfBaseTask |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* @see sfTask |
|---|
| 23 |
*/ |
|---|
| 24 |
protected function configure() |
|---|
| 25 |
{ |
|---|
| 26 |
$this->aliases = array('clear-controllers'); |
|---|
| 27 |
$this->namespace = 'project'; |
|---|
| 28 |
$this->name = 'clear-controllers'; |
|---|
| 29 |
$this->briefDescription = 'Clears all non production environment controllers'; |
|---|
| 30 |
|
|---|
| 31 |
$this->detailedDescription = <<<EOF |
|---|
| 32 |
The [project:clear-controllers|INFO] task clears all non production environment |
|---|
| 33 |
controllers: |
|---|
| 34 |
|
|---|
| 35 |
[./symfony project:clear-controllers|INFO] |
|---|
| 36 |
|
|---|
| 37 |
You can use this task on a production server to remove all front |
|---|
| 38 |
controller scripts except the production ones. |
|---|
| 39 |
|
|---|
| 40 |
If you have two applications named [frontend|COMMENT] and [backend|COMMENT], |
|---|
| 41 |
you have four default controller scripts in [web/|COMMENT]: |
|---|
| 42 |
|
|---|
| 43 |
[index.php |
|---|
| 44 |
frontend_dev.php |
|---|
| 45 |
backend.php |
|---|
| 46 |
backend_dev.php|INFO] |
|---|
| 47 |
|
|---|
| 48 |
After executing the [project:clear-controllers|COMMENT] task, two front |
|---|
| 49 |
controller scripts are left in [web/|COMMENT]: |
|---|
| 50 |
|
|---|
| 51 |
[index.php |
|---|
| 52 |
backend.php|INFO] |
|---|
| 53 |
|
|---|
| 54 |
Those two controllers are safe because debug mode and the web debug |
|---|
| 55 |
toolbar are disabled. |
|---|
| 56 |
EOF; |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
* @see sfTask |
|---|
| 61 |
*/ |
|---|
| 62 |
protected function execute($arguments = array(), $options = array()) |
|---|
| 63 |
{ |
|---|
| 64 |
$finder = sfFinder::type('file')->maxdepth(1)->name('*.php'); |
|---|
| 65 |
foreach ($finder->in(sfConfig::get('sf_web_dir')) as $controller) |
|---|
| 66 |
{ |
|---|
| 67 |
$content = file_get_contents($controller); |
|---|
| 68 |
|
|---|
| 69 |
if (preg_match('/ProjectConfiguration::getApplicationConfiguration\(\'(.*?)\', \'(.*?)\'/', $content, $match)) |
|---|
| 70 |
{ |
|---|
| 71 |
|
|---|
| 72 |
if ($match[2] != 'prod') |
|---|
| 73 |
{ |
|---|
| 74 |
$this->getFilesystem()->remove($controller); |
|---|
| 75 |
} |
|---|
| 76 |
} |
|---|
| 77 |
} |
|---|
| 78 |
} |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|