Symfony tutorial

Upgrading Projects from 1.2 to 1.3/1.4

symfony training
Be trained by symfony experts
Sep 07: Online (Nouveautés de 1.3/1.4 - Français)
Sep 22: Paris (Maîtrise de & Doctrine - Français)
Oct 05: Online (Nouveautés de 1.3/1.4 - Français)
Oct 20: Paris (Maîtrise de & Doctrine - Français)
Nov 24: Paris (Maîtrise de & Doctrine - Français)
and more...

About

You are currently reading "symfony Tutorials" which is licensed under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License license.

Content

Chapter Content

Upgrading to symfony 1.4

How to upgrade to symfony 1.3?

Deprecations

Autoloading

Routing

JavaScripts and Stylesheets

Removal of the common filter

Tasks

Formatters

Escaping

Doctrine Integration

Required Doctrine Version

Admin Generator Delete

Override Doctrine Plugin Schema

Query logging

Plugins

Widgets

Mailer

YAML

Propel

Tests

You are currently browsing "symfony Tutorials" in English for the 1.4 version - Switch to version: - Switch to language:
Creative Commons License This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License.
You have been redirected to the symfony 1.4 documentation.
Both symfony 1.3 and symfony 1.4 share the same feature set and documentation.
Read about why we have two different versions.

This document describes the changes made in symfony 1.3/1.4 and what need to be done to upgrade your symfony 1.2 projects.

If you want more detailed information on what has been changed/added in symfony 1.3/1.4, you can read the What's new? tutorial.

symfony 1.3/1.4 is compatible with PHP 5.2.4 or later. It might also work with PHP 5.2.0 to 5.2.3 but there is no guarantee.

Upgrading to symfony 1.4

There is no upgrade task in symfony 1.4 as this version is the same as symfony 1.3 (minus all the deprecated features). To upgrade to 1.4, you must first upgrade to 1.3, and then switch to the 1.4 release.

Before upgrading to 1.4, you can also validate that your project does not use any deprecated class/method/function/setting/... by running the project:validate task:

$ php symfony project:validate

The task lists all the files you need to change before switching to symfony 1.4.

Be aware that the task is a glorified regular expression and might gives you many false positives. Also, it cannot detect everything, so it is just a tool that helps you identifying possible problems, not a magic tool. You still need to read the DEPRECATED tutorial carefully.

sfCompat10Plugin and sfProtoculousPlugin have been removed from 1.4. If you are explicitly disabling them in your project's configuration class files, such as config/ProjectConfiguration.class.php, you must remove all mention of them from those files.

How to upgrade to symfony 1.3?

To upgrade a project:

The remaining sections explain the main changes made in symfony 1.3 that need some kind of upgrade (automatic or not).

Deprecations

During the symfony 1.3 development, we have deprecated and removed some settings, classes, methods, functions, and tasks. Please refer to Deprecations in 1.3 for more information.

Autoloading

As of symfony 1.3, the files under the lib/vendor/ directory are not autoloaded anymore by default. If you want to autoload some lib/vendor/ sub-directories, add a new entry in the application autoload.yml configuration file:

autoload:
  vendor_some_lib:
    path:      %SF_LIB_DIR%/vendor/some_lib_dir
    recursive: on

The automatic autoloading of the lib/vendor/ directory was problematic for several reasons:

Autoloading in symfony 1.3 is now case-insensitive.

Routing

The sfPatternRouting::setRoutes(), sfPatternRouting::prependRoutes(), sfPatternRouting::insertRouteBefore(), and sfPatternRouting::connect() methods do not return the routes as an array as they did in previous versions.

The lazy_routes_deserialize option has been removed as it is not needed anymore.

As of symfony 1.3, the cache for the routing is disabled, as this is the best option for most projects as far as performance are concerned. So, if you have not customized the routing cache, it will be automatically disabled for all your applications. If after upgrading to 1.3, your project is slower, you might want to add some routing cache to see if it helps. Here is the symfony 1.2 default configuration you can add back to your factories.yml:

routing:
  param:
    cache:
      class: sfFileCache
      param:
        automatic_cleaning_factor: 0
        cache_dir:                 %SF_CONFIG_CACHE_DIR%/routing
        lifetime:                  31556926
        prefix:                    %SF_APP_DIR%/routing

JavaScripts and Stylesheets

Removal of the common filter

The sfCommonFilter has been deprecated and is not used anymore by default. This filter used to automatically inject the JavaScripts and stylesheets tags into the response content. You now need to manually include these assets by explicitly call the include_stylesheets() and include_javascripts() helpers in your layout:

<?php include_javascripts() ?>
<?php include_stylesheets() ?>

It has been removed for several reasons:

How to upgrade?

The sfCommonFilter class is still bundled with symfony 1.3, and so you can still use it in your filters.yml if you need to.

Tasks

The following task classes have been renamed:

symfony 1.2 symfony 1.3
sfConfigureDatabaseTask sfDoctrineConfigureDatabaseTask or sfPropelConfigureDatabaseTask
sfDoctrineLoadDataTask sfDoctrineDataLoadTask
sfDoctrineDumpDataTask sfDoctrineDataDumpTask
sfPropelLoadDataTask sfPropelDataLoadTask
sfPropelDumpDataTask sfPropelDataDumpTask

The signature for the *:data-load tasks has changed. Specific directories or files must now be provided as arguments. The --dir option has been removed.

$ php symfony doctrine:data-load data/fixtures/dev

Formatters

The sfFormatter::format() third argument has been removed.

Escaping

The esc_js_no_entities(), refered to by ESC_JS_NO_ENTITIES was updated to correctly handle non-ANSI characters. Before this change all but characters with ANSI value 37 to 177 were escaped. Now it will only escape backslashes \, quotes ' & " and linebreaks \n & \r. However it is unlikely that you previously relied on this broken behaviour.

Doctrine Integration

Required Doctrine Version

The externals to Doctrine have been updated to use the latest and greatest Doctrine 1.2 version. You can read about what is new in Doctrine 1.2 here.

Admin Generator Delete

The admin generator batch delete was changed to fetch the records and issue the delete() method to each one individually instead of issuing a single DQL query to delete them all. The reason is so that events for deleting each individual record are invoked.

Override Doctrine Plugin Schema

You can override the model included in a plugins YAML schema simply by defining that same model in your local schema. For example, to add an "email" column to sfDoctrineGuardPlugin's sfGuardUser model, add the following to config/doctrine/schema.yml:

sfGuardUser:
  columns:
    email:
      type: string(255)

The package option is a feature of Doctrine and is used for the schemas of symfony plugins. This does not mean the package feature can be used independently to package your models. It must be used directly and only with symfony plugins.

Query logging

The Doctrine integration logs queries run using sfEventDispatcher rather than by accessing the logger object directly. Additionally, the subject of these events is either the connection or statement that is running the query. Logging is done by the new sfDoctrineConnectionProfiler class, which can be accessed via a sfDoctrineDatabase object.

Plugins

If you use the enableAllPluginsExcept() method to manage enabled plugins in your ProjectConfiguration class, be warned that we now sort the plugins by name to ensure consistency across different platforms.

Widgets

The sfWidgetFormInput class is now abstract. Text input fields are now created with the sfWidgetFormInputText class. This change was made to ease introspection of form classes.

Mailer

Symfony 1.3 has a new mailer factory. When creating a new application, the factories.yml has sensible defaults for the test and dev environments. But if you upgrade an existing project, you might want to update your factories.yml with the following configuration for these environments:

mailer:
  param:
    delivery_strategy: none

With the previous configuration, emails won't be sent. Of course, they will still be logged, and the mailer tester will still work in your functional tests.

If you'd rather want to receive all emails to a single address, you can use the single_address delivery strategy (in the dev environment for instance):

dev:
  mailer:
    param:
      delivery_strategy: single_address
      delivery_address:  foo@example.com

If your project uses an older version of Swiftmailer, you must remove it.

YAML

sfYAML is now more compatible with the 1.2 spec. Here are the changes you might need to do in your configuration files:

The project:upgrade task tells you where you use old syntax but does not fix them (to avoid loosing comments for instance). You must fix them by hand.

If you don't want to check all your YAML files, you can force the YAML parser to use the 1.1 YAML specification by using the sfYaml::setSpecVersion() method:

sfYaml::setSpecVersion('1.1');

Propel

The custom Propel builder classes used in previous versions of symfony have been replaced with new Propel 1.4 behavior classes. To take advantage of this enhancement your project's propel.ini file must be updated.

Remove the old builder classes:

; builder settings
propel.builder.peer.class              = plugins.sfPropelPlugin.lib.builder.SfPeerBuilder
propel.builder.object.class            = plugins.sfPropelPlugin.lib.builder.SfObjectBuilder
propel.builder.objectstub.class        = plugins.sfPropelPlugin.lib.builder.SfExtensionObjectBuilder
propel.builder.peerstub.class          = plugins.sfPropelPlugin.lib.builder.SfExtensionPeerBuilder
propel.builder.objectmultiextend.class = plugins.sfPropelPlugin.lib.builder.SfMultiExtendObjectBuilder
propel.builder.mapbuilder.class        = plugins.sfPropelPlugin.lib.builder.SfMapBuilderBuilder

And add the new behavior classes:

; behaviors
propel.behavior.default                        = symfony,symfony_i18n
propel.behavior.symfony.class                  = plugins.sfPropelPlugin.lib.behavior.SfPropelBehaviorSymfony
propel.behavior.symfony_i18n.class             = plugins.sfPropelPlugin.lib.behavior.SfPropelBehaviorI18n
propel.behavior.symfony_i18n_translation.class = plugins.sfPropelPlugin.lib.behavior.SfPropelBehaviorI18nTranslation
propel.behavior.symfony_behaviors.class        = plugins.sfPropelPlugin.lib.behavior.SfPropelBehaviorSymfonyBehaviors
propel.behavior.symfony_timestampable.class    = plugins.sfPropelPlugin.lib.behavior.SfPropelBehaviorTimestampable

The project:upgrade task attempts to make this change for you, but may be unable to if you've make local changes to propel.ini.

The BaseFormFilterPropel class was incorrectly generated in lib/filter/base in symfony 1.2. This has been corrected in symfony 1.3; the class is now be generated in lib/filter. The project:upgrade task will move this file for you.

Tests

The unit test bootstrap file, test/bootstrap/unit.php, has been enhanced to better handle autoloading of project class files. The following lines must be added to this script:

$autoload = sfSimpleAutoload::getInstance(sfConfig::get('sf_cache_dir').'/project_autoload.cache');
$autoload->loadConfiguration(sfFinder::type('file')->name('autoload.yml')->in(array(
  sfConfig::get('sf_symfony_lib_dir').'/config/config',
  sfConfig::get('sf_config_dir'),
)));
$autoload->register();

The project:upgrade task attempts to make this change for you, but may be unable to if you've make local changes to test/bootstrap/unit.php.

Questions & Feedback

If you find a typo or an error, please register and open a ticket.

If you need support or have a technical question, please post to the official user mailing-list.

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.