Development

/branches/1.1/lib/task/project/upgrade1.1/sfConfigUpgrade.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/task/project/upgrade1.1/sfConfigUpgrade.class.php

Revision 9191, 4.2 kB (checked in by fabien, 6 years ago)

fixed sfConfigUpgrade to allow optional whitespaces after the closing PHP tag

  • 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) 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  * Upgrade configuration.
13  *
14  * @package    symfony
15  * @subpackage task
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfConfigUpgrade extends sfUpgrade
20 {
21   public function upgrade()
22   {
23     if (file_exists(sfConfig::get('sf_lib_dir').'/ProjectConfiguration.class.php'))
24     {
25       throw new sfCommandException('Unable to upgrade your project automatically. Read the "NOTE to early adopters" at the end in the symfony UPGRADE file to upgrade your project manually.');
26     }
27
28     $this->checkConfigFiles();
29     $this->upgradeFrontControllers();
30     $this->upgradeConfigurationClasses();
31   }
32
33   protected function checkConfigFiles()
34   {
35     $finder = $this->getFinder('file')->name('config.php');
36     foreach ($finder->in($this->getProjectConfigDirectories()) as $file)
37     {
38       $this->logSection('config', sprintf('The following file is not used anymore. Please remove it.', $file));
39       $this->log('   '.$file);
40       $this->logSection('config', '  If you made some customization in this file,');
41       $this->logSection('config', '  please migrate the content to the configuration classes.');
42     }
43   }
44
45   protected function upgradeFrontControllers()
46   {
47     // update front web controllers only if no changes have been made
48     $finder = $this->getFinder('file')->name('*.php');
49     foreach ($finder->in(sfConfig::get('sf_web_dir')) as $file)
50     {
51       $content = file_get_contents($file);
52
53       // front controller?
54       if (false === strpos($content, 'define(\'SF_ROOT_DIR\''))
55       {
56         continue;
57       }
58
59       // already upgraded?
60       if (false !== strpos($content, 'sfContext::createInstance'))
61       {
62         continue;
63       }
64
65       if (!preg_match("/define\('SF_APP',\s*('|\")(.+?)\\1\)/", $content, $matches))
66       {
67         continue;
68       }
69       $app = $matches[2];
70
71       if (!preg_match("/define\('SF_ENVIRONMENT',\s*('|\")(.+?)\\1\)/", $content, $matches))
72       {
73         continue;
74       }
75       $environment = $matches[2];
76
77       if (!preg_match("/define\('SF_DEBUG',\s*(.+?)\)/", $content, $matches))
78       {
79         continue;
80       }
81       $debug = $matches[1];
82
83       // for 0.6.3 compatibility (or manual "fixing" the missing) remove closing at tag end of file
84       $content = preg_replace('/\?>\s*$/', '', $content);
85
86       $originalContent = <<<EOF
87 <?php
88
89 define('SF_ROOT_DIR',    realpath(dirname(__FILE__).'/..'));
90 define('SF_APP',         '$app');
91 define('SF_ENVIRONMENT', '$environment');
92 define('SF_DEBUG',       $debug);
93
94 require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
95
96 sfContext::getInstance()->getController()->dispatch();
97
98 EOF;
99
100       $newContent = file_get_contents(dirname(__FILE__).'/../../generator/skeleton/app/web/index.php');
101       $newContent = str_replace(array('##APP_NAME##', '##ENVIRONMENT##', '##IS_DEBUG##'), array($app, $environment, $debug), $newContent);
102
103       if ($originalContent == $content)
104       {
105         $content = $newContent;
106         $this->logSection('config', sprintf('Migrated "%s"', $file));
107       }
108       else
109       {
110         $this->logSection('config', '  You made some customization in the following file:');
111         $this->log('   '.$file);
112         $this->logSection('config', '  Please, upgrade manually (new code appended as a comment)');
113
114         $content .= sprintf("\n\n/*\n%s\n*/\n", $newContent);
115       }
116
117       file_put_contents($file, $content);
118     }
119   }
120
121   protected function upgradeConfigurationClasses()
122   {
123     foreach ($this->getApplications() as $application)
124     {
125       $configPath = sfConfig::get('sf_apps_dir').'/'.$application.'/config/'.$application.'Configuration.class.php';
126
127       if (file_exists($configPath))
128       {
129         continue;
130       }
131
132       $this->getFilesystem()->copy(dirname(__FILE__).'/../../generator/skeleton/app/app/config/ApplicationConfiguration.class.php', $configPath);
133
134       $this->getFilesystem()->replaceTokens($configPath, '##', '##', array('APP_NAME' => $application));
135     }
136   }
137 }
138
Note: See TracBrowser for help on using the browser.