Author: david
Date: Wed Aug 15 16:53:16 2012
New Revision: 12116
Log:
Add migration script to add new fixture i18n values to database
Modified:
trunk/data/fixtures/settings.yml
trunk/lib/task/migrate/QubitMigrate.class.php
trunk/lib/task/migrate/arUpgrader120.class.php
Modified: trunk/data/fixtures/settings.yml
==============================================================================
--- trunk/data/fixtures/settings.yml Wed Aug 15 15:06:10 2012 (r12115)
+++ trunk/data/fixtures/settings.yml Wed Aug 15 16:53:16 2012 (r12116)
@@ -3,7 +3,7 @@
name: version
editable: 0
deleteable: 0
- value: 91
+ value: 92
QubitSetting_2:
name: upload_dir
editable: 0
Modified: trunk/lib/task/migrate/QubitMigrate.class.php
==============================================================================
--- trunk/lib/task/migrate/QubitMigrate.class.php Wed Aug 15 15:06:10
2012 (r12115)
+++ trunk/lib/task/migrate/QubitMigrate.class.php Wed Aug 15 16:53:16
2012 (r12116)
@@ -729,4 +729,94 @@
$connection->commit();
}
+
+ public static function addNewFixtureI18ns()
+ {
+ $conn = Propel::getConnection();
+
+ $fixtures = array();
+
+ foreach
(sfFinder::type('file')->name('*.yml')->in(sfConfig::get('sf_data_dir').'/fixtures/')
as $yaml)
+ {
+ foreach (sfYaml::load($yaml) as $classname => $data)
+ {
+ $fixtures[$classname] = $data;
+ }
+ }
+
+ foreach ($fixtures as $classname => $row)
+ {
+ // Don't overwrite static page text and make sure there's an I18n table
+ if ('QubitStaticPage' == $classname || !class_exists($classname.'I18n'))
+ {
+ continue;
+ }
+
+ $table = constant($classname.'I18n::TABLE_NAME');
+
+ switch ($classname)
+ {
+ case 'QubitMenu':
+ $updateCol = 'label';
+
+ break;
+
+ case 'QubitSetting':
+ $updateCol = 'value';
+
+ break;
+
+ default:
+ $updateCol = 'name';
+ }
+
+ $query = "INSERT INTO $table ($updateCol, id, culture) VALUES (?, ?,
?);";
+ $insertStmt = $conn->prepare($query);
+
+ $query = "SELECT culture FROM $table WHERE id = ?";
+ $selectStmt = $conn->prepare($query);
+
+ foreach ($row as $key => $columns)
+ {
+ // Build array of existing cultures, so we don't stomp user values
+ $selectStmt->execute(array(
+ $columns['id']));
+
+ while ($c = $selectStmt->fetchColumn())
+ {
+ $existingCultures[] = $c;
+ }
+
+ foreach ($columns as $column => $values)
+ {
+ if (!is_array($values) || !isset($columns['id']))
+ {
+ continue;
+ }
+
+ foreach ($values as $culture => $value)
+ {
+ if (in_array($culture, $existingCultures))
+ {
+ continue;
+ }
+
+ // Insert new culture values
+ try
+ {
+ $insertStmt->execute(array(
+ $value,
+ $columns['id'],
+ $culture));
+ }
+ catch (PDOException $e)
+ {
+ // Ignore insert errors
+ continue;
+ }
+ }
+ }
+ }
+ }
+ }
}
Modified: trunk/lib/task/migrate/arUpgrader120.class.php
==============================================================================
--- trunk/lib/task/migrate/arUpgrader120.class.php Wed Aug 15 15:06:10
2012 (r12115)
+++ trunk/lib/task/migrate/arUpgrader120.class.php Wed Aug 15 16:53:16
2012 (r12116)
@@ -417,6 +417,12 @@
break;
+ // Update translations from fixtures
+ case 91:
+ QubitMigrate::addNewFixtureI18ns();
+
+ break;
+
// Return false if no upgrade available
default:
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.