Development

HowToPatchTablesForI18nFromGeneratedSchema

You must first sign up to be able to contribute.

How to patch tables for I18n from a reverse-engineered database

If you've ever wanted to construct tables using I18n, but didn't want to fiddle around with YAML and reverse-engineer the database to visualize it, then you can now patch your visually-generated database (either using !DBDesigner4 or whichever tool you're using) using a simple Pake task.

Generally, the cycle of generating the proper model is syncing the visual database with the server, reverse-engineering it using Propel (symfony propel-build-schema), building the model (symfony propel-build-model) and clearing the cache (symfony cc). While this is all fine and dandy if you're not using I18n, there's a show stopper - you can modify the generated schema.yml file to use I18n features, but all of those settings get wiped as soon as you restart the visual-db syncing (since the YAML gets overwritten).

The solution is to have an intermediate step in the cycle - the patch-db-i18n. Basically it's just a Pake task that takes the generated schema.yml and applies the transformation necessary for the tables to have I18n capability.

To use this Pake task, copy the appended file to your PEAR data directory: $PEAR/data/symfony/tasks. This will make the file available in the framework for you to use the Pake task. The modified cycle is now:

  1. sync your visual database to the database server
  2. reverse-engineer the database: symfony propel-build-schema
  3. run the database patch: symfony patch-db-i18n <application> [<suffix> [<column>]]
  4. rebuild the model: symfony propel-build-model
  5. clear the cache: symfony cc

That's it. Your database should now be I18n enabled. There are a few gotchas, though...

Example:

symfony patch-db-i18n myapp _trans lang_id

This will match any pair named (*, *_trans) and apply I18n _attributes to them and use the lang_id column in the child tables (ie, *_trans) for the isCulture column.

Parameters

The parameters for the Pake task are:

  • <application> - the name of an application in your project (it uses it to provide sfContext)
  • <suffix> - the appended string used to identify parent/child I18n tables (only suffixes are supported, if none given, defaults to "_i18n")
  • <column> - the culture-enabled column used to identify the culture/language (must be VARCHAR(7), a primary key and required, if no value given, defaults to "culture")

GOTCHAS

  1. You must use a relational database with references. One of the most common fatal errors when generating the model is the result of missing relational references. To assure maximum reliability, use relational references and (if using MySQL) use InnoDB as the storage engine.
  2. You cannot use table name pairs other than * and *suffix, which is a limitation of the parametrized Pake task.

As a Plugin

There is also a modified version of sfPakePatchDbI18n.php that enables you to install it as a plugin into your Symfony framework, and you don't have to specify an application to run this patch, simply run it like symfony patch-db-i18n [<suffix> [<column>]].

Example:

symfony patch-db-i18n _trans lang_id

To use this plugin, unpack the appended file sfPakePathDbI18n.tar.gz into your plugins dir and use it as the example above.

symfony 1.1

This plugin worked only in symfony 1.0.

I transformed that pluggin into a task of symfony 1.1.

Installation

Put the file doPatchDbI18nTask.class.php to lib/task/doPatchDbI18nTask.class.php

To run

symfony propel:build-schema
symfony mp:patch-db-i18n
symfony propel:build-model

Attachments