<?php



/**
 * Enables an application in a given environment.
 *
 * @package    symfony
 * @subpackage task
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
 * @version    SVN: $Id$
 */
class sfProjectEnableTask extends sfBaseTask
{
  /**
   * @see sfTask
   */
  protected function configure()
  {
    $this->addArguments(array(
      new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'),
      new sfCommandArgument('env', sfCommandArgument::REQUIRED, 'The environment name'),
    ));

    $this->aliases = array('enable');
    $this->namespace = 'project';
    $this->name = 'enable';
    $this->briefDescription = 'Enables an application in a given environment';

    $this->detailedDescription = <<<EOF
The [project:enable|INFO] task enables an application for a specific environment:

  [./symfony project:enable frontend prod|INFO]
EOF;
  }

  /**
   * @see sfTask
   */
  protected function execute($arguments = array(), $options = array())
  {
    $app = $arguments['application'];
    $env = $arguments['env'];

    $lockFile = sfConfig::get('sf_data_dir').'/'.$app.'_'.$env.'.lck';
    if (!file_exists($lockFile))
    {
      $this->logSection('enable', sprintf('%s [%s] is currently ENABLED', $app, $env));
    }
    else
    {
      $this->getFilesystem()->remove($lockFile);

      $clearCache = new sfCacheClearTask($this->dispatcher, $this->formatter);
      $clearCache->setCommandApplication($this->commandApplication);
      $clearCache->run();

      $this->logSection('enable', sprintf('%s [%s] has been ENABLED', $app, $env));
    }
  }
}
