diff --git a/tasks/MigrateTranslatableTask.php b/tasks/MigrateTranslatableTask.php index 988123d9e..ee6d33839 100644 --- a/tasks/MigrateTranslatableTask.php +++ b/tasks/MigrateTranslatableTask.php @@ -1,5 +1,38 @@ Limitations + * + * - Information from the {@link Versioned} extension (e.g. in "SiteTree_versions" table) + * will be discarded for translated records. + * - Custom translatable fields on your own {@link Page} class or subclasses thereof won't + * be migrated into the translation. + * - 2.1-style subtags of a language (e.g. "en") will be automatically disambiguated to their full + * locale value (e.g. "en_US"), by the lookup defined in {@link i18n::get_locale_from_lang()}. + * - Doesn't detect published translations when the script is run twice on the same data set + * + *

Usage

+ * + * PLEASE BACK UP YOUR DATABASE BEFORE RUNNING THIS SCRIPT. + * + * Warning: Please run dev/build on your 2.2 database to update the schema before running this task. + * The dev/build command will rename tables like "SiteTree_lang" to "_obsolete_SiteTree_lang". + * + *

Commandline

+ * Requires "sake" tool (see http://doc.silverstripe.com/?id=sake) + * + * sake dev/tasks/MigrateTranslatableTask + * + * + *

Browser

+ * + * http://mydomain.com/dev/tasks/MigrateTranslatableTask + * + * * @package sapphire * @subpackage tasks */ @@ -16,34 +49,82 @@ class MigrateTranslatableTask extends BuildTask { function run($request) { $ids = array(); - //$_REQUEST['showqueries'] = 1; + echo "#################################\n"; + echo "# Adding translation groups to existing records" . "\n"; + echo "#################################\n"; + $allSiteTreeIDs = DB::query('SELECT "ID" FROM "SiteTree"')->column(); + if($allSiteTreeIDs) foreach($allSiteTreeIDs as $id) { + $original = DataObject::get_by_id('SiteTree', $id); + $existingGroupID = $original->getTranslationGroup(); + if(!$existingGroupID) $original->addTranslationGroup($original->ID); + $original->destroy(); + unset($original); + } + + DataObject::flush_and_destroy_cache(); + + echo sprintf("Created translation groups for %d records\n", count($allSiteTreeIDs)); + foreach(array('Stage', 'Live') as $stage) { - echo "

Migrating stage $stage

"; - echo "'; } - echo 'Done!'; + echo "\n\n#################################\n"; + echo "Done!\n"; } }