Development

/branches/1.2/lib/task/project/sfProjectUnfreezeTask.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/task/project/sfProjectUnfreezeTask.class.php

Revision 13212, 2.9 kB (checked in by FabianLange, 5 years ago)

[1.2] fixed regular expression back reference bug on windows pathes like "symfony\1.2". fixes #5021

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