sfProjectUnfreezeTask.class.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * Unfreezes symfony libraries.
  11. *
  12. * @package symfony
  13. * @subpackage task
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfProjectUnfreezeTask.class.php 13212 2008-11-21 19:53:12Z FabianLange $
  16. */
  17. class sfProjectUnfreezeTask extends sfBaseTask
  18. {
  19. /**
  20. * @see sfTask
  21. */
  22. protected function configure()
  23. {
  24. $this->aliases = array('unfreeze');
  25. $this->namespace = 'project';
  26. $this->name = 'unfreeze';
  27. $this->briefDescription = 'Unfreezes symfony libraries';
  28. $this->detailedDescription = <<<EOF
  29. The [project:unfreeze|INFO] task removes all the symfony core files from
  30. the current project:
  31. [./symfony project:unfreeze|INFO]
  32. The task also changes [config/config.php|COMMENT] to switch to the
  33. old symfony files used before the [project:freeze|COMMENT] command was used.
  34. EOF;
  35. }
  36. /**
  37. * @see sfTask
  38. */
  39. protected function execute($arguments = array(), $options = array())
  40. {
  41. // remove lib/symfony and data/symfony directories
  42. if (!is_dir('lib/symfony'))
  43. {
  44. throw new sfCommandException('You can unfreeze only if you froze the symfony libraries before.');
  45. }
  46. // change symfony path in ProjectConfiguration.class.php
  47. $config = sfConfig::get('sf_config_dir').'/ProjectConfiguration.class.php';
  48. $content = file_get_contents($config);
  49. if (preg_match('/^# FROZEN_SF_LIB_DIR\: (.+?)$/m', $content, $match))
  50. {
  51. $publishAssets = new sfPluginPublishAssetsTask($this->dispatcher, $this->formatter);
  52. $publishAssets->setCommandApplication($this->commandApplication);
  53. $symfonyLibDir = $match[1];
  54. $content = str_replace("# FROZEN_SF_LIB_DIR: {$match[1]}\n\n", '', $content);
  55. // need to escape windows pathes "symfony\1.2" -> "symfony\\1.2"
  56. // because preg_replace would then use \1 as group identifier resulting in "symfony.2"
  57. $content = preg_replace('#^require_once.+?$#m', sprintf("require_once '%s/autoload/sfCoreAutoload.class.php';", str_replace('\\', '\\\\', $symfonyLibDir)), $content, 1);
  58. file_put_contents($config, $content);
  59. // re-publish assets
  60. $publishAssets->run(array(), array('--symfony-lib-dir='.$symfonyLibDir));
  61. // remove files
  62. $finder = sfFinder::type('any');
  63. $this->getFilesystem()->remove($finder->in(sfConfig::get('sf_lib_dir').'/symfony'));
  64. $this->getFilesystem()->remove(sfConfig::get('sf_lib_dir').'/symfony');
  65. $this->getFilesystem()->remove($finder->in(sfConfig::get('sf_data_dir').'/symfony'));
  66. $this->getFilesystem()->remove(sfConfig::get('sf_data_dir').'/symfony');
  67. $this->getFilesystem()->remove($finder->in(sfConfig::get('sf_web_dir').'/sf'));
  68. $this->getFilesystem()->remove(sfConfig::get('sf_web_dir').'/sf');
  69. }
  70. }
  71. }