Wednesday, February 9, 2011

Symfony Upgrade from 1.0 to 1.3

The upgrade from symfony 1.0 projects to 1.2 requires that projects first be upgraded to version 1.1, then 1.2 and finally 1.4. Before beginning the process ensure that the multiple version configuration has been completed. The following instructions will only serve as the base for the upgrade. For full details of the upgrade process and the changes there in visit the following pages:

http://www.symfony-project.org/installation/1_1/upgrade
http://www.symfony-project.org/installation/1_2/upgrade
http://www.symfony-project.org/tutorial/1_4/en/upgrade

1. Change directory into the root of project to upgrade
2. Copy the symfony skeleton file from the 1.1 symfony library
cp /opt/symfony/symfony11/lib/task/generator/skeleton/project/symfony

3. Copy the project skeleton file from the 1.1 symfony library
cp /opt/symfony/symfony11/lib/task/generator/skeleton/project/config/ProjectConfiguration.class.php config/

4. Edit the config/ProjectConfiguration.class.php file and ensure that the require_once points to the valid path and that the configuration and includes from the older config.php are set.

ini_set(‘include_path’, ‘/usr/lib/phplib/libs:’ . ini_get(‘include_path’));
define(‘__DEBUG__’, 0);
define(‘CONFIGPATH’, dirname(__FILE__) . ‘/config.xml’);
define(‘CONFIGTYPE’, ‘XML’);
require_once(‘/opt/symfony/symfony11/lib/autoload/sfCoreAutoload.class.php’);


5. Run the upgrade script
./symfony project:upgrade1.1

6. Once the upgrade script has completed remove any depreciated configuration files (logging, i8n, etc)
read the output, migrate the config file then remove files

7. All of the batch scripts in the project will have to be updated have the following header information in place of the existing.

require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);
sfContext::createInstance($configuration);
$databaseManager = new sfDatabaseManager($configuration);
$databaseManager->loadConfiguration();


8. Access the application and ensure that it is in a basic working state (it easier to do this after each upgrade than waiting until the end)
1) Flash attributes
change
$sf_flash->has('good')
to
$sf_user->hasFlash('good')

change
$this->setFlash('error_msg', 'Sorry');
to
$this->getUser()->setFlash('error_msg', 'Sorry');

change
$sf_flash->get('error_msg')
to
$sf_user->getFlash('error_msg');

Problem 1)
[sfException]
Call to undefined method WebController::getContext

Solved: Turn off customized webcontroller  for now
Project/apps/app/config/factories.yml

all:
# controller:
# class: WebController


9. Edit the config/ProjectConfiguration.class.php file updating the symfony include to point to the 1.2 version.

require_once(‘/opt/symfony/symfony12/lib/autoload/sfCoreAutoload.class.php’);


10. Run the symfony 1.2 upgrade
symfony12 project:upgrade1.2

11. Upgrade the databases.yml into the new format
Old Format

all:
propel:
class: sfPropelDatabase
param:
dsn: mysql://username:password@localhost/example

New Format

dev:
propel:
param:
classname: DebugPDO

test:
propel:
param:
classname: DebugPDO

all:
propel:
class: sfPropelDatabase
param:
dsn: mysql:dbname=example;host=localhost
username: username
password: password
encoding: utf8
persistent: true
pooling: true
classname: PropelPDO


12. Rebuild the propel module by running the following

symfony12 propel:build-model


Problem 2)
build-propel.xml:479:1: Table 'xxxxx' does not have a primary key defined. Propel requires all tables to have a primary key.
build-propel.xml:465:22: Execution of the target buildfile failed. Aborting.

Solved: add primaryKey="true"
Project/config/admerch.schema.xml

13. If your application makes use database sessions update your factories.ymlas such
storage:
class: sfPDOSessionStorage
param:
session_name: session
db_table: session
db_id_col: sess_id
db_data_col: sess_data
db_time_col: sess_time
database: example

14. It is strongly recommended to disable any specialized classes, other than the user object, in the factories.yml file.

Problem 3)
500 | Internal Server Error | sfDatabaseException
Database "example" does not exist.
1.at () in SF_SYMFONY_LIB_DIR/database/sfDatabaseManager.class.php line 109 ...
2.at sfDatabaseManager->getDatabase('inpulse_ad')
in SF_ROOT_DIR/cache/cm/dev/config/config_factories.yml.php line 111 ...
3. at require('/root/workspace/admerch/cache/cm/dev/config/config_factories.yml.php')
in SF_SYMFONY_LIB_DIR/util/sfContext.class.php line 149 ...
4. at sfContext->loadFactories()
in SF_SYMFONY_LIB_DIR/util/sfContext.class.php line 76 ...
5.at sfContext->initialize(object('cmConfiguration'))
in SF_SYMFONY_LIB_DIR/util/sfContext.class.php line 59 ...

Solved.
/admerch/apps/cm/config/factories.yml
replace

storage:
class: sfPDOSessionStorage
param:
session_name: session
db_table: session
db_id_col: sess_id
db_data_col: sess_data
db_time_col: sess_time
database: example

use default session

storage:
class: sfSessionStorage
param:
session_name: symfony


15. The underlying propel connection has changed from creole to PDO. Any peer classes that directly hydrate data objects will have to be updated to use the PDO API. Please visit: http://www.symfony-project.org/installation/1_2/upgrade for the complete information.

Locate /admerch/config/propel.ini
change

propel.database = mysql
propel.database.createUrl = mysql://username:password@localhost/
propel.database.url = mysql://username:password@localhost/example

Replace with the following

propel.database = mysql
propel.database.driver = mysql
propel.database.url = mysql:dbname=example;host=localhost
propel.database.user = username
propel.database.password = password
propel.database.encoding = utf8


need to rebuild the object model:

symfony12 propel:build-model


Problem 4)
Error importing addon/propel/builder/SfPeerBuilder.php
Execution of target "om" failed for the following reason: /opt/symfony/symfony12/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/build-propel.xml:465:22: Execution of the target buildfile failed. Aborting.
[phing] /opt/symfony/symfony12/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/build-propel.xml:465:22: Execution of the target buildfile failed. Aborting.


Solved
http://blog.vacs.fr/index.php?post/2009/02/08/Symfony-cryptic-error%3A-Error-importing-plugins/sfPropelPlugin/lib/propel/builder/SfPeerBuilder.php

http://oldforum.symfony-project.org/index.php/m/59416/
missing addon/propel/builder/SfPeerBuilder.php file

propel.builder.peer.class = addon.propel.builder.SfPeerBuilder
propel.builder.object.class = addon.propel.builder.SfObjectBuilder



create a new symfony12 project

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


Problem 5)
500 | Internal Server Error | PropelException
Unable to find adapter for datasource [example].

Solved.
ProjectName/config/example.schema.xml

database name="example"

ProjectName/config/database.yml

all:
example:
class: sfPropelDatabase
param:
dsn: mysql:dbname=example;host=hostname
username: username
password: password
encoding: utf8
persistent: true
pooling: true
classname: PropelPDO



16. Edit the config/ProjectConfiguration.class.php file updating the symfony include to point to the 1.3 version.

require_once(‘/opt/symfony/symfony13/lib/autoload/sfCoreAutoload.class.php’);


17. Before switching your project to 1.3 run the following in your project directory
validate project

symfony13 project:validate


http://www.symfony-project.org/tutorial/1_4/en/deprecated
This will identify any areas of your project that need to be modified due to removal of old features. As a note it’s pretty good at finding things but a full test of the application will be needed to validate the upgrade.

18. Upgrading from 1.2 to 1.3 is as simple as executing the following in your project directory

symfony13 project:upgrade1.3
symfony13 propel:build --all-classes


Problem 6)
run symfony13 propel:build --all-classes
Cannot fetch TableMap for undefined table: location

19. Before switching your project to 1.4 run the following in your project directory

symfony14 project:validate

This will identify any areas of your project that need to be modified due to removal of old features. As a note it’s pretty good at finding things but a full test of the application will be needed to validate the upgrade.

20.Once the project successfully validates under 1.4 run the following to complete the upgrade.

symfony14 project:upgrade1.4

No comments:

Post a Comment