Nous avons vu dans les deux billets précédents comment créer une tâche et comment gérer le « mode maintenance » sur ses applications. Voyons maintenant comment le activer ou désactiver le mode maintenance depuis la ligne de commande.
Dans notre exemple on considère que le namespace est « netha » et la tache « maintenance ».
Dans le fichier lib/task/nethaMaintenanceTask.class.php :
<?php
class nethaMaintenanceTask extends sfBaseTask
{
protected function configure()
{
$this->addArguments(array(
new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'Application'),
));
$this->namespace = 'netha';
$this->name = 'maintenance';
$this->briefDescription = 'Gestion du mode maintenance';
$this->detailedDescription = <<<EOF
The [netha:maintenance|INFO] task does things.
Call it with:
[php symfony netha:maintenance|INFO]
EOF;
}
protected function execute($arguments = array(), $options = array())
{
$file = sfConfig::get('sf_data_dir').'/lock/'.$arguments['application'].'.lck';
if (file_exists($file))
{
if (unlink($file))
{
$this->logSection('info', 'Mode maintenance inactif.');
}
}
else
{
if (is_readable(sfConfig::get('sf_data_dir').'/lock'))
{
file_put_contents($file, array());
$this->logSection('info', 'Mode maintenance actif.');
}
}
}
}
A partir de maintenant la commande php.exe symfony netha:maintenance mon_application vous permettra de gérer le passage en mode maintenance.
Aucun commentaire