| 1 |
Upgrading symfony to 0.6/0.7 from 0.4/0.5 |
|---|
| 2 |
========================================= |
|---|
| 3 |
|
|---|
| 4 |
If you have a project based on symfony 0.4.X or 0.5.X, it has to be upgraded |
|---|
| 5 |
in order to work with a 0.6.X or 0.7.X release. The process is quick and |
|---|
| 6 |
partly automated. |
|---|
| 7 |
|
|---|
| 8 |
>**Note**: Stable releases have even second digit, nightly releases have odd second digit. For instance: |
|---|
| 9 |
> |
|---|
| 10 |
>* release 0.6.0 is stable |
|---|
| 11 |
>* releases 0.6.xxx are also stable, and contain bug fixes to the 0.6.0 |
|---|
| 12 |
>* releases 0.7.xxx are subversion trunk nightly releases and bring additionnal features to the 0.6.0 |
|---|
| 13 |
|
|---|
| 14 |
Main steps |
|---|
| 15 |
---------- |
|---|
| 16 |
|
|---|
| 17 |
0. Update symfony to 0.6.XX (if it is not already done) |
|---|
| 18 |
|
|---|
| 19 |
$ pear upgrade symfony/symfony |
|---|
| 20 |
|
|---|
| 21 |
If you want to try symfony 0.6 alpha, use: |
|---|
| 22 |
|
|---|
| 23 |
$ pear upgrade symfony/symfony-alpha |
|---|
| 24 |
|
|---|
| 25 |
1. Make a backup of your project (this is the most important step!) |
|---|
| 26 |
|
|---|
| 27 |
2. Move all your application directories under a new `apps/` directory |
|---|
| 28 |
(see step 1-2 of the _Application modifications_ section below) |
|---|
| 29 |
|
|---|
| 30 |
3. Launch the following command in your project root directory: |
|---|
| 31 |
|
|---|
| 32 |
$ symfony upgrade 0.6 |
|---|
| 33 |
|
|---|
| 34 |
Or do manually the steps 3-12 described below |
|---|
| 35 |
|
|---|
| 36 |
4. Check the changes made to your project by the symfony upgrade command |
|---|
| 37 |
(`svn diff` if you use subversion) and make sure your code is still there. |
|---|
| 38 |
|
|---|
| 39 |
5. Update your `databases.yml` configuration file |
|---|
| 40 |
(see step 13 of the _Application modifications_ section below) |
|---|
| 41 |
|
|---|
| 42 |
6. Follow the manual steps numbered 14 to 19 below |
|---|
| 43 |
|
|---|
| 44 |
Be careful if your project directory contains external libraries using |
|---|
| 45 |
`SF_XXX`, `MOD_XXX` or `APP_XXX` constants. As the `upgrade` command |
|---|
| 46 |
transforms these constants into a class method call, you will probably need to |
|---|
| 47 |
overwrite the upgraded libraries by the the backup copy (for instance, this |
|---|
| 48 |
happens for the 'geshi' library). |
|---|
| 49 |
|
|---|
| 50 |
You can launch the `symfony upgrade 0.6` command several times without |
|---|
| 51 |
problem. |
|---|
| 52 |
|
|---|
| 53 |
Application modifications |
|---|
| 54 |
------------------------- |
|---|
| 55 |
|
|---|
| 56 |
For all your applications within a project: |
|---|
| 57 |
|
|---|
| 58 |
1. Move all your apps under an `apps/` directory |
|---|
| 59 |
|
|---|
| 60 |
0.4.X/0.5.X | 0.6.X/0.7.X |
|---|
| 61 |
-------------------------|---------------------------- |
|---|
| 62 |
`SF_ROOT_DIR/frontend` | `SF_ROOT_DIR/apps/frontend` |
|---|
| 63 |
`SF_ROOT_DIR/backend` | `SF_ROOT_DIR/apps/backend` |
|---|
| 64 |
|
|---|
| 65 |
2. Change the path to `config.php` in your `index.php` and all the other |
|---|
| 66 |
front controllers. |
|---|
| 67 |
|
|---|
| 68 |
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'); |
|---|
| 69 |
|
|---|
| 70 |
3. Update your `myapp/config/config.php` file with the new one |
|---|
| 71 |
(`data/symfony/skeleton/app/app/config/config.php`). |
|---|
| 72 |
|
|---|
| 73 |
4. Change the calls to all the symfony configuration constants in the php code |
|---|
| 74 |
(`SF_XXX`, `APP_XXX`, `MOD_XXX`) to calls to the new `sfConfig` class, except |
|---|
| 75 |
for the constants called in `index.php` (`SF_ROOT_DIR`, `SF_APP`, |
|---|
| 76 |
`SF_ENVIRONMENT, SF_DEBUG`): |
|---|
| 77 |
|
|---|
| 78 |
0.4.X/0.5.X | 0.6.X/0.7.X |
|---|
| 79 |
---------------------------|------------------------------------- |
|---|
| 80 |
`define('SF_FOO', 'bar')` | `sfConfig::set('sf_foo', 'bar')` |
|---|
| 81 |
`defined('SF_FOO')` | `sfConfig::get('sf_foo') or nothing` |
|---|
| 82 |
`SF_FOO` | `sfConfig::get('sf_foo')` |
|---|
| 83 |
|
|---|
| 84 |
5. In your template files, change the shortcuts to the symfony objects |
|---|
| 85 |
by adding a `sf_` prefix: |
|---|
| 86 |
|
|---|
| 87 |
0.4.X/0.5.X | 0.6.X/0.7.X |
|---|
| 88 |
-------------------|------------------- |
|---|
| 89 |
`$context` | `$sf_context` |
|---|
| 90 |
`$params` | `$sf_params` |
|---|
| 91 |
`$request` | `$sf_request` |
|---|
| 92 |
`$user` | `$sf_user` |
|---|
| 93 |
`$view` | `$sf_view` |
|---|
| 94 |
`$last_module` | `$sf_last_module` |
|---|
| 95 |
`$last_actio` | `$sf_last_action` |
|---|
| 96 |
`$first_module` | `$sf_first_module` |
|---|
| 97 |
`$first_action` | `$sf_first_action` |
|---|
| 98 |
|
|---|
| 99 |
6. Update the `settings.yml` configuration file: |
|---|
| 100 |
|
|---|
| 101 |
0.4.X/0.5.X | 0.6.X/0.7.X |
|---|
| 102 |
----------------------------------------|------------------------------------------- |
|---|
| 103 |
`standard_helpers: Partial,Cache,Form` | `standard_helpers: [Partial, Cache, Form]` |
|---|
| 104 |
`is_i18n: on` | `i18n: on` |
|---|
| 105 |
`default_culture: en` | -> new `i18n.yml` configuration file |
|---|
| 106 |
|
|---|
| 107 |
7. Move your `messages.xml` i18n XML file from `i18n/global` to the `i18n` |
|---|
| 108 |
directory. |
|---|
| 109 |
|
|---|
| 110 |
8. Replace any definition of the `disable_web_debug` attribute by a call to: |
|---|
| 111 |
|
|---|
| 112 |
sfConfig::set('sf_web_debug', false); |
|---|
| 113 |
|
|---|
| 114 |
(this is used to disable the web debug toolbar in development for |
|---|
| 115 |
non-html views). |
|---|
| 116 |
|
|---|
| 117 |
9. Rename the calls to the `sfPager` class to `sfPropelPager` |
|---|
| 118 |
|
|---|
| 119 |
10. `mail_to` has a new parameter |
|---|
| 120 |
|
|---|
| 121 |
0.4.X/0.5.X | 0.6.X/0.7.X |
|---|
| 122 |
------------------------------|------------------------------------- |
|---|
| 123 |
`mail_to($email, true)` | `mail_to($email, $name, 'encode=1')` |
|---|
| 124 |
|
|---|
| 125 |
11. Change all the deprecated methods in your actions |
|---|
| 126 |
|
|---|
| 127 |
0.4.X/0.5.X | 0.6.X/0.7.X |
|---|
| 128 |
-----------------------------|---------------------------- |
|---|
| 129 |
`$this->forward404_if()` | `$this->forward404If()` |
|---|
| 130 |
`$this->forward404_unless()` | `$this->forward404Unless()` |
|---|
| 131 |
`$this->forward_if()` | `$this->forwardIf()` |
|---|
| 132 |
`$this->forward_unless()` | `$this->forwardUnless()` |
|---|
| 133 |
`$this->redirect_if()` | `$this->redirectIf()` |
|---|
| 134 |
`$this->redirect_unless()` | `$this->redirectUnless()` |
|---|
| 135 |
|
|---|
| 136 |
12. Change all the comments in your YAML files from `;` to `#` |
|---|
| 137 |
|
|---|
| 138 |
13. Update your `databases.yml` configuration file. The `orm.yml` |
|---|
| 139 |
configuration file is not needed anymore. All database configuration now occur |
|---|
| 140 |
in the `databases.yml`. |
|---|
| 141 |
|
|---|
| 142 |
[0.4.X/0.5.X > orm.yml] |
|---|
| 143 |
all: |
|---|
| 144 |
adapter: mysql |
|---|
| 145 |
host: localhost |
|---|
| 146 |
database: dbname |
|---|
| 147 |
username: root |
|---|
| 148 |
password: |
|---|
| 149 |
|
|---|
| 150 |
[0.6.X/0.7.X > databases.yml] |
|---|
| 151 |
all: |
|---|
| 152 |
propel: |
|---|
| 153 |
class: sfPropelDatabase |
|---|
| 154 |
param: |
|---|
| 155 |
datasource: symfony |
|---|
| 156 |
phptype: mysql |
|---|
| 157 |
hostspec: localhost |
|---|
| 158 |
database: dbname |
|---|
| 159 |
username: root |
|---|
| 160 |
password: |
|---|
| 161 |
compat_assoc_lower: true |
|---|
| 162 |
compat_rtrim_string: true |
|---|
| 163 |
|
|---|
| 164 |
The `datasource` parameter (`symfony` in this example) refers to the database connection as defined in the the `name` attribute of the `<database>` tag in the `schema.xml`. |
|---|
| 165 |
|
|---|
| 166 |
If you don't specify the `datasource` param, it takes the value of the label given to the connection settings (`propel` in this example). |
|---|
| 167 |
|
|---|
| 168 |
To get a dabatase connection, you must now use the symfony database manager: |
|---|
| 169 |
|
|---|
| 170 |
0.4.X/0.5.X | 0.6.X/0.7.X |
|---|
| 171 |
-----------------------------|-------------------------------------------------------------------- |
|---|
| 172 |
`Propel::getConnection()` | `sfContext::getInstance()->getDatabaseConnection($connection_name)` |
|---|
| 173 |
|
|---|
| 174 |
`$connection_name` is the name of your connection (`propel` in the example above). |
|---|
| 175 |
|
|---|
| 176 |
14. Change all calls to the `->setSort()` method of the `sfPropelPager` object |
|---|
| 177 |
to the equivalent `Criteria` methods. |
|---|
| 178 |
|
|---|
| 179 |
15. Change your symlinks or apache configuration to move the `web/sf` directory: |
|---|
| 180 |
|
|---|
| 181 |
0.4.X/0.5.X | 0.6.X/0.7.X |
|---|
| 182 |
--------------------------------------|---------------------------- |
|---|
| 183 |
SVN | |
|---|
| 184 |
`/SYMFONY_PATH/data/symfony/web/sf` | `/SYMFONY_PATH/data/web/sf` |
|---|
| 185 |
| |
|---|
| 186 |
PEAR | |
|---|
| 187 |
`/PEAR_DATA_PATH/data/symfony/web/sf` | `/PEAR_DATA_PATH/data/web/sf` |
|---|
| 188 |
|
|---|
| 189 |
16. If your project use the `sfShoppingCart` or `sfFeed` classes, install the |
|---|
| 190 |
related plugins, since they are no longer shipped with the default symfony |
|---|
| 191 |
installation: |
|---|
| 192 |
|
|---|
| 193 |
$ symfony plugin-install [local|global] symfony/sfFeed |
|---|
| 194 |
$ symfony plugin-install [local|global] symfony/sfShoppingCart |
|---|
| 195 |
or |
|---|
| 196 |
$ pear install symfony/sfFeed (equivalent to the `global` install) |
|---|
| 197 |
$ pear install symfony/sfShoppingCart |
|---|
| 198 |
|
|---|
| 199 |
17. The first parameter of the `options_for_select()` helper changed to be |
|---|
| 200 |
more intuitive: |
|---|
| 201 |
|
|---|
| 202 |
0.4.X/0.5.X | 0.6.X/0.7.X |
|---|
| 203 |
---------------------------------------------------------|------------------------------------------------------- |
|---|
| 204 |
`options_for_select(array('France' => 1, 'USA' => 2))` | `options_for_select(array(1 => 'France', 2 => 'USA'))` |
|---|
| 205 |
`options_for_select(array_flip(array('France', 'USA')))` | `options_for_select(array('France', 'USA'))` |
|---|
| 206 |
|
|---|
| 207 |
18. If you have some batch files using database connection, you now have to |
|---|
| 208 |
initialize the context. Add the following line after `config.php` loading: |
|---|
| 209 |
|
|---|
| 210 |
sfContext::getInstance(); |
|---|
| 211 |
|
|---|
| 212 |
19. Clear the symfony cache |
|---|