Development

/tags/RELEASE_1_1_0_BETA4/UPGRADE

You must first sign up to be able to contribute.

root/tags/RELEASE_1_1_0_BETA4/UPGRADE

Revision 8342, 21.5 kB (checked in by dwhittle, 8 months ago)

1.1: fixed typo

Line 
1 Upgrade from 1.0 to 1.1
2 =======================
3
4 This document describes the changes made in symfony 1.1 and what need
5 to be done to upgrade your symfony 1.0 projects.
6
7 WARNING: symfony 1.1 is only compatible with PHP > 5.1.
8
9 How to upgrade?
10 ---------------
11
12 To upgrade a project:
13
14   * If you don't use a SCM tool, please make a backup of your project.
15     As symfony replaces some files during the upgrade
16     (front controllers for example), you need a way to merge your
17     customizations after the upgrade.
18
19   * Update the `symfony` file located in the project root directory
20     by changing those three lines:
21
22         [php]
23         chdir(dirname(__FILE__));
24         include('config/config.php');
25         include($sf_symfony_data_dir.'/bin/symfony.php');
26
27     to
28
29         [php]
30         chdir(dirname(__FILE__));
31         require_once(dirname(__FILE__).'/config/ProjectConfiguration.class.php');
32         $configuration = new ProjectConfiguration();
33         include($configuration->getSymfonyLibDir().'/command/cli.php');
34
35     You can also copy the skeleton file from the symfony project skeleton directly:
36
37         $ cp /path/to/symfony/lib/task/generator/skeleton/project/symfony symfony
38
39   * Create a `config/ProjectConfiguration.class.php` file with the following content:
40
41         [php]
42         <?php
43
44         require_once '##SYMFONY_LIB_DIR##/autoload/sfCoreAutoload.class.php';
45         sfCoreAutoload::register();
46
47         class ProjectConfiguration extends sfProjectConfiguration
48         {
49           public function setup()
50           {
51           }
52         }
53
54     Then, replace `##SYMFONY_LIB_DIR##` with the path to the symfony 1.1
55     `lib/` directory. This is the new way to change the symfony version used
56     for your project.
57
58     You can also copy the skeleton file from the symfony project skeleton directly:
59
60         $ cp /path/to/symfony/lib/task/generator/skeleton/project/config/ProjectConfiguration.class.php config/ProjectConfiguration.class.php
61
62   * Launch the `project:upgrade1.1` task from your project directory
63     to perform an automatic upgrade:
64
65         $ ./symfony project:upgrade1.1
66
67     This task can be launched several times without any side effect. Each time
68     you upgrade to a new symfony 1.1 beta / RC or the final symfony 1.1, you
69     need to launch this task.
70
71   * If you don't plan to upgrade the validation or mailing system to
72     the new system, you must enable the compatibility mode in `settings.yml`:
73
74         [yml]
75         all:
76           .settings:
77             compat_10: on
78
79     Here is a list of the things that will be enabled when switching to the
80     compatibility mode (see the bundled `sfCompat10Plugin` plugin for
81     more information):
82
83       * Zend Framework and ezComponents bridges
84       * sfProcessCache
85       * validation system (validate.yml, validator classes, ...)
86       * fill in filter
87       * sfMail with phpmailer
88
89 The remaining sections explains backward incompatible changes.
90
91 Batch scripts
92 -------------
93
94 The use of batch scripts is deprecated, in favor of custom CLI tasks. The new CLI system makes it easy to add a new symfony command to a project, so refer to the Chapter 16 of the symfony book for a detailed how-to on CLI tasks.
95
96 If you just want your old batch scripts to work, you need to change the first lines of the every batch scripts--the lines that look like a front controller's initialization. So change the following:
97
98     [php]
99     <?php
100     define('SF_ROOT_DIR',    realpath(dirname(__FILE__).'/..'));
101     define('SF_APP',         'frontend');
102     define('SF_ENVIRONMENT', 'prod');
103     define('SF_DEBUG',       false);
104
105       require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
106     // your batch code here
107
108 To:
109
110     [php]
111     <?php
112     require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
113     $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);
114     sfContext::createInstance($configuration);
115
116     // your batch code here
117
118 If you need to initialize the database connection, just add the following lines:
119
120     [php]
121     $databaseManager = new sfDatabaseManager($configuration);
122     $databaseManager->loadConfiguration();
123
124 Flash attributes
125 ----------------
126
127 Flash attributes are now managed directly by `sfUser`. New usage:
128
129     [php]
130     // action
131     $this->getUser()->setFlash('notice', 'foo');
132     $notice = $this->getUser()->getFlash('notice');
133
134     // template
135     <?php $sf_user->hasFlash('notice'): ?>
136       <?php echo $sf_user->getFlash('notice') ?>
137     <?php endif; ?>
138
139 The `flash` entry in `filters.yml` must be removed too as the `sfFlashFilter`
140 was removed.
141
142 The `project:upgrade1.1` task makes all those changes for you.
143
144 Deprecated methods in sfComponent
145 ---------------------------------
146
147 The following methods of `sfComponent` have been removed:
148
149   * `->getPresentationFor()`
150   * `->sendEmail()`
151
152 They are accessible from `sfController`:
153
154     [php]
155     // action
156     $this->getController()->getPresentationFor(...);
157
158 The `project:upgrade1.1` task makes all those changes for you.
159
160 Singletons
161 ----------
162
163 The sfI18N, sfRouting, and sfLogger objects are now factories and
164 not singletons.
165
166 If you want to get one of those objects in your code, they are
167 available from `sfContext`:
168
169     [php]
170     sfContext::getInstance()->getI18N()
171     sfContext::getInstance()->getRouting()
172     sfContext::getInstance()->getLogger()
173
174 Routing
175 ~~~~~~~
176
177 Here is the default configuration for the routing in `factories.yml`:
178
179     [yml]
180     routing:
181       class: sfPatternRouting
182       param:
183         load_configuration: true
184
185 The `project:upgrade1.1` task makes all the changes for you.
186
187 Logging
188 ~~~~~~~
189
190 Here is the default configuration for logging in `factories.yml`:
191
192     [yml]
193     logger:
194       class: sfAggregateLogger
195       param:
196         level: debug
197         loggers:
198           sf_web_debug:
199             class: sfWebDebugLogger
200             param:
201               condition: %SF_WEB_DEBUG%
202               xdebug_logging: true
203           sf_file_debug:
204             class: sfFileLogger
205             param:
206               file: %SF_LOG_DIR%/%SF_APP%_%SF_ENVIRONMENT%.log
207
208 The `logging.yml` configuration file is not used anymore.
209 Instead, you can configure logging in `factories.yml`.
210
211 To disable logging in the production environment, you will have to change
212 your application `factories.yml`:
213
214     [yml]
215     prod:
216       logger:
217         class:   sfNoLogger
218         param:
219           level:   err
220           loggers: ~
221
222 There is also a new `logging_enabled` setting in `settings.yml`.
223 This can be used to prevent logging in the production environment altogether:
224
225     [yml]
226     prod:
227       .settings:
228         logging_enabled: off
229
230 The `project:upgrade1.1` task makes all those changes for you.
231
232 i18n
233 ~~~~
234
235 Here is the default configuration for i18n in `factories.yml`:
236
237     [yml]
238     i18n:
239       class: sfI18N
240       param:
241         source:              XLIFF
242         debug:               off
243         untranslated_prefix: "[T]"
244         untranslated_suffix: "[/T]"
245         cache:
246           class: sfFileCache
247           param:
248             automatic_cleaning_factor: 0
249             cache_dir:                 %SF_I18N_CACHE_DIR%
250             lifetime:                  86400
251             prefix:                    %SF_APP_DIR%
252
253 The `i18n.yml` configuration file is not used anymore.
254 Instead, you can configure i18n in `factories.yml`.
255
256 The only exception is the `default_culture` setting which is now configurable
257 in `settings.yml` and do not depend on the i18n framework anymore:
258
259   default_culture: en
260
261 If your project has some specific settings, you must move your current
262 configuration from the `i18n.yml` to the `factories.yml` and add the default
263 culture in `settings.yml` as shown above.
264
265 Cache Framework
266 ---------------
267
268 The `sfFunctionCache` class does not extend `sfFileCache` anymore.
269 You must now pass a cache object to the constructor.
270 The first argument to ->call() must now be a PHP callable.
271
272 Some `sfCache` configuration parameter have changed their named to underscore names:
273
274   * automaticCleaningFactor -> automatic_cleaning_factor
275   * cacheDir -> cache_dir
276
277 The `project:upgrade1.1` task makes all those changes for you.
278
279 Autoloading
280 -----------
281
282 The `autoloading_function` setting in `settings.yml` is not used anymore.
283 You can register autoloading callables in your application configuration class.
284
285 Thanks to the new `sfAutoload::autoloadAgain()` method, you won't need to clear
286 the cache when you add or move classes in your project. This method will
287 automatically find the changes and flush the autoloading cache.
288
289 VERSION
290 -------
291
292 The lib/VERSION file has been removed. If you want to get the current symfony
293 version, you can use the `SYMFONY_VERSION` constant. This constant is defined
294 in `autoload/sfCoreAutoload.class.php`
295
296 Routing
297 -------
298
299 To inject default route parameters, you can now use the `->setDefaultParameter()`
300 method instead of using the `sf_routing_defaults` setting:
301
302     [php]
303     $this->context->getRouting()->setDefaultParameter($key, $value);
304
305 I18N
306 ----
307
308 symfony core classes don't return internationalized strings anymore:
309
310     [php]
311     <?php echo __($sf_request->getError('foo')) ?>
312
313 This behavior has changed for the following methods and functions:
314
315     [php]
316     sfWebRequest::getError()
317     sfWebResponse::addMeta()
318
319 The following helpers (in sfCompat10Plugin) still return internationalized data:
320
321     [php]
322     form_error()
323     include_metas()
324
325 The `getGlobalMessageSource()` and `getGlobalMessageFormat()` methods has been
326 removed from the sfI18N class. They are now equivalent to `getMessageSource()`
327 and `getMessageFormat()`.
328
329 Logger
330 ------
331
332 Logger priorities are now constants:
333
334     [php]
335     sfLogger::INFO
336
337 The `project:upgrade1.1` task makes all those changes for you.
338
339 Deprecated methods in sfAction
340 ------------------------------
341
342 The following methods of `sfAction` have been deprecated and throw
343 a `sfConfigurationException` if `sf_compat_10` is set to `false`:
344
345   * `->validate()`
346   * `->handleError()`
347
348 Deprecated methods in sfRequest
349 -------------------------------
350
351 The following methods of `sfRequest` have been deprecated and throw
352 a `sfConfigurationException` if `sf_compat_10` is set to `false`:
353
354   * `->getError()`
355   * `->getErrors()`
356   * `->getErrorNames()`
357   * `->hasError()`
358   * `->hasErrors()`
359   * `->setError()`
360   * `->setErrors()`
361   * `->removeError()`
362
363 Deprecated methods in sfWebRequest
364 ----------------------------------
365
366 The following methods of `sfWebRequest` have been deprecated and throw
367 a `sfConfigurationException` if `sf_compat_10` is set to `false`:
368
369   * `->getFile()`
370   * `->getFileError()`
371   * `->getFileName()`
372   * `->getFileNames()`
373   * `->getFilePath()`
374   * `->getFileSize()`
375   * `->getFileType()`
376   * `->hasFile()`
377   * `->hasFileError()`
378   * `->hasFileErrors()`
379   * `->hasFiles()`
380   * `->getFileValue()`
381   * `->getFileValues()`
382   * `->getFileExtension()`
383   * `->moveFile()`
384
385 `->initialize()` methods
386 ------------------------
387
388 Most symfony core classes are initialized thanks to a `->initialize()` method.
389 As of symfony 1.1, this method is automatically called by `__construct()`,
390 so, there is no need to call it by yourself.
391
392 Configuration files loading
393 ---------------------------
394
395 Some core classes can be configured with a `.yml` file:
396
397  *Class*              | *Configuration file*
398  -------------------- | --------------------------------
399  `sfAction`           | `security.yml`
400  `sfAutoload`         | `autoload.yml`
401  `sfConfigCache`      | `config_handlers.yml`
402  `sfContext`          | `factories.yml`
403  `sfController`       | `generator.yml` and `module.yml`
404  `sfDatabaseManager`  | `databases.yml`
405  `sfFilterChain`      | `filters.yml`
406  `sfI18N`             | `i18n.yml`
407  `sfPatternRouting`   | `routing.yml`
408  `sfPHPView`          | `view.yml`
409  `sfViewCacheManager` | `cache.yml`
410
411 In symfony 1.1, the loading of the configuration file for ''independant''
412 sub-frameworks has been moved to a `loadConfiguration()` method to ease
413 decoupling and reuse them without needing the whole framework:
414
415   * `sfDatabaseManager`
416   * `sfI18N`
417   * `sfPatternRouting`
418
419 So, for example, if you need a database manager in your batch script,
420 you will have to change from:
421
422     [php]
423     $databaseManager = new sfDatabaseManager();
424     $databaseManager->initialize();
425
426 to:
427
428     [php]
429     $configuration = ProjectConfiguration::getApplicationConfiguration($application, $env, true);
430     $databaseManager = new sfDatabaseManager($configuration);
431     $databaseManager->loadConfiguration();
432
433 The `initialize()` call is not needed anymore (see the point above).
434
435 Web Debug
436 ---------
437
438 The `web_debug` entry in `filters.yml` must be removed as the `sfWebDebugFilter`
439 has been removed. The web debug toolbar is now injected in the response thanks
440 to a listener.
441
442 The `project:upgrade1.1` task makes all those changes for you.
443
444 Session timeout
445 ---------------
446
447 The `sf_timeout` setting is not used anymore. To change the session timeout,
448 you now have to edit `factories.yml` instead of the `settings.yml`,
449 and change the parameters of the `user` factory:
450
451     [yml]
452     all:
453       user:
454         class: myUser
455         param:
456           timeout:     1800     # session timeout in seconds
457
458 Routing configuration
459 ---------------------
460
461 The `sf_suffix`, `sf_default_module`, and `sf_default_action` settings are not
462 used anymore. To change the default suffix, module, or action, you now have
463 to edit `factories.yml` instead of `settings.yml`, and change the parameters
464 of the `routing` factory:
465
466     [yml]
467     all:
468       routing:
469         class: sfPatternRouting
470         param:
471           load_configuration: true
472           suffix:             .       # Default suffix for generated URLs. If set to a single dot (.), no suffix is added. Possible values: .html, .php, and so on.
473           default_module:     default # Default module and action to be called when
474           default_action:     index   # A routing rule doesn't set it
475
476 `php.yml` configuration file
477 ----------------------------
478
479 The `php.yml` configuration file has been removed.
480
481 The only setting you will have to check by hand is `log_errors`, which was set
482 to `on` by `php.yml`.
483
484 `php.yml` is replaced by the `check_configuration.php` utility you can find
485 in `data/bin`. It checks your environment against symfony requirements.
486 You can launch it from anywhere:
487
488     $ php /path/to/symfony/data/bin/check_configuration.php
489
490 Even if you can use this utility from the command line, it's strongly recommended
491 to launch it from the web by copying it under your web root directory as PHP can
492 use different php.ini configuration files for the CLI and the web.
493
494 `$sf_symfony_data_dir` removal
495 ------------------------------
496
497 In symfony 1.1, `$sf_symfony_data_dir` has been removed. All relevant files and
498 directories from the symfony `data` directory have been moved to the `lib`
499 directory:
500
501  *Old Location*         | *New Location*
502  ---------------------- | -----------------------------
503  `data/config`          | `lib/config/config`
504  `data/i18n`            | `lib/i18n/data`
505  `data/skeleton`        | `lib/task/generator/skeleton`
506  `data/modules/default` | `lib/controller/default`
507  `data/web/errors`      | `lib/exception/data`
508  `data/exception.*`     | `lib/exception/data`
509
510 The symfony core has been upgraded to take these changes into account.
511
512 sfLoader
513 --------
514
515 All `sfLoader` static methods (except `::getHelperDirs()` and `::loadHelpers()`)
516 have been moved to the `sfProjectConfiguration` and `sfApplicationConfiguration`
517 classes:
518
519   * `sfProjectConfiguration`:
520       * `->getGeneratorSkeletonDirs()`
521       * `->getGeneratorTemplate()`
522       * `->getGeneratorTemplateDirs()`
523       * `->getModelDirs()`
524
525   * `sfApplicationConfiguration`:
526       * `->getControllerDirs()`
527       * `->getTemplateDirs()`
528       * `->getTemplateDir()`
529       * `->getTemplatePath()`
530       * `->getI18NGlobalDirs()`
531       * `->getI18NDirs()`
532       * `->getConfigPaths()`
533
534 sfCore
535 ------
536
537 The `sfCore` has been removed. The code has been moved to `sfProjectConfiguration`,
538 `sfApplicationConfiguration`, and `sfContext` classes.
539
540 Front Controllers
541 -----------------
542
543 All front controllers have to be upgraded. The SF_DEBUG, SF_APP, SF_ENVIRONMENT,
544 and SF_ROOT_DIR constants are gone. If you use some of these constants in your
545 project, please use their sfConfig::get('') counterparts:
546
547  *Old*             | *New*
548  ----------------- | ---------------------------------
549  `SF_ROOT_DIR`     | `sfConfig::get('sf_root_dir')`
550  `SF_ENVIRONMENT`  | `sfConfig::get('sf_environment')`
551  `SF_APP`          | `sfConfig::get('sf_app')`
552  `SF_DEBUG`        | `sfConfig::get('sf_debug')`
553
554 The `project:upgrade1.1` task upgrades all front controllers for you.
555 If you made some customizations, symfony will issue a warning and won't
556 upgrade them automatically. You can then copy the default skeleton from
557 symfony: /path/to/symfony/lib/task/generator/skeleton/app/web/index.php
558
559 config.php
560 ----------
561
562 All `config.php` files have been removed. The are replaced by the `ProjectConfiguration`
563 class and the application configuration classes.
564
565 If you've added some cutomizations in `config.php` files, you will have to migrate them
566 to those new classes.
567
568 Directory structure
569 -------------------
570
571 All `sfConfig` constants ending with `_dir_name` have been removed.
572
573 Cache keys
574 ----------
575
576 The `sfViewCacheManager::removePattern()` and `sfToolkit::clearGlob()` don't work anymore
577 for removing several cache parts at once. But the `sfViewCacheManager::remove()` now
578 accepts internal URIs with wildcards. So you can replace:
579
580     $cacheManager->removePattern('*/all/user/show/id/*');
581
582 By:
583
584     $cacheManager->remove('user/show?id=*', '*', 'all');
585
586 This also works for partials and contextual partials. You can then replace:
587
588     $cacheManager->removePattern('/sf_cache_partial/user/_my_partial/sf_cache_key/*');
589
590 By:
591
592     $cacheManager->remove('@sf_cache_partial?module=user&action=_my_partial&sf_cache_key=*');
593
594 And the biggets benefit is that it allows you to clear 'glob' URIs in *any* cache
595 factory, not only the `sfFileCache`.
596
597 Layout
598 ------
599
600 The action template variables are not available anymore in the layout. This means that the layout
601 only has access to **global** variables (all `sf_` variables) and variables registered via the
602 `template.filter_parameters` event.
603
604 Refer to this wiki page for more information on how to upgrade:
605
606     http://trac.symfony-project.com/wiki/Symfony11LayoutUpgrade
607
608 Tasks
609 -----
610
611 The symfony command line task names have changed. They now use a namespace syntax. The old task names still work--they are just aliases for the new task names. Here is a table showing the name changes:
612
613     Old task name             |  New task name
614     --------------------------|-----------------
615     clear-cache               | cache:clear
616     clear-controllers         | project:clear-controllers
617     disable                   | project:disable
618     downgrade                 | [Not implemented]
619     enable                    | project:enable
620     fix-perms                 | project:permissions
621     freeze                    | project:freeze
622     init-app                  | generate:app
623     init-batch                | [Not implemented]
624     init-controller           | [Not implemented]
625     init-module               | generate:module
626     init-project              | generate:project
627     log-purge                 | log:clear
628     log-rotate                | log:rotate
629     plugin-install            | plugin:install
630     plugin-list               | plugin:list
631     plugin-uninstall          | plugin:uninstall
632     plugin-upgrade            | plugin:upgrade
633     propel-build-all          | propel:build-all
634     propel-build-all-load     | propel:build-all-load
635     propel-build-db           | propel:build-db
636     propel-build-model        | propel:build-model
637     propel-build-schema       | propel:build-schema
638     propel-build-sql          | propel:build-sql
639     propel-convert-xml-schema | propel:schema-to-yml
640     propel-convert-yml-schema | propel:schema-to-xml
641     propel-dump-data          | propel:data-dump
642     propel-generate-crud      | propel:generate-crud
643     propel-init-admin         | propel:init-admin
644     propel-init-crud          | [Not implemented]
645     propel-insert-sql         | propel:insert-sql
646     propel-load-data          | propel:data-load
647     sync                      | project:deploy
648     test-all                  | test:all
649     test-functional           | test:functional
650     test-unit                 | test:unit
651     unfreeze                  | project:unfreeze
652     upgrade                   | project:freeze
653
654 As before, if you want to list the available tasks, just call the `symfony` command with no argument:
655
656     > php symfony
657
658 NOTE to early adopters
659 ----------------------
660
661 If you have upgraded your project and have a `lib/ProjectConfiguration.class.php` file,
662 then you need to upgrade your project manually before being able to launch the
663 `project:upgrade1.1` task.
664
665 Here is how:
666
667   * Move `lib/ProjectConfiguration.class.php` to `config/ProjectConfiguration.class.php`
668
669   * Change the path to symfony in `config/ProjectConfiguration.class.php` if needed.
670
671   * Move all your application configuration classes (`lib/$APP_NAME$Configuration.class.php`)
672     to their respective `apps/$APP_NAME$/config/` directory.
673
674   * Remove the `require_once dirname(__FILE__).'/ProjectConfiguration.class.php';` in all
675     the application configuration classes.
676
677   * Change the location of `ProjectConfiguration.class.php` in the main `symfony` script to `config/`
678
679   * Change your front controllers so they look like this:
680
681       {{{
682         <?php
683
684         require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
685
686         $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
687         sfContext::createInstance($configuration)->dispatch();
688       }}}
689
690 You can now launch the `project:upgrade1.1` script to finish the upgrade.
Note: See TracBrowser for help on using the browser.