Development

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

You must first sign up to be able to contribute.

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

Revision 13213, 2.6 kB (checked in by FabianLange, 5 years ago)

[1.1] 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       $content = str_replace("# FROZEN_SF_LIB_DIR: {$match[1]}\n\n", '', $content);
59       // need to escape windows pathes "symfony\1.2" -> "symfony\\1.2"
60       // because preg_replace would then use \1 as group identifier resulting in "symfony.2"
61       $content = preg_replace('#^require_once.+?$#m', sprintf("require_once '%s/autoload/sfCoreAutoload.class.php';", str_replace('\\', '\\\\', $match[1])), $content, 1);
62       file_put_contents($config, $content);
63     }
64
65     $finder = sfFinder::type('any');
66     $this->getFilesystem()->remove($finder->in(sfConfig::get('sf_lib_dir').'/symfony'));
67     $this->getFilesystem()->remove(sfConfig::get('sf_lib_dir').'/symfony');
68     $this->getFilesystem()->remove($finder->in(sfConfig::get('sf_data_dir').'/symfony'));
69     $this->getFilesystem()->remove(sfConfig::get('sf_data_dir').'/symfony');
70     $this->getFilesystem()->remove($finder->in(sfConfig::get('sf_web_dir').'/sf'));
71     $this->getFilesystem()->remove(sfConfig::get('sf_web_dir').'/sf');
72   }
73 }
74
Note: See TracBrowser for help on using the browser.