Author: david
Date: Thu Aug 16 17:03:13 2012
New Revision: 12125

Log:
Use english text instead of primary key as source key when adding new i18n 
values

Modified:
   trunk/lib/task/migrate/QubitMigrate.class.php

Modified: trunk/lib/task/migrate/QubitMigrate.class.php
==============================================================================
--- trunk/lib/task/migrate/QubitMigrate.class.php       Thu Aug 16 16:47:48 
2012        (r12124)
+++ trunk/lib/task/migrate/QubitMigrate.class.php       Thu Aug 16 17:03:13 
2012        (r12125)
@@ -757,43 +757,56 @@
       switch ($classname)
       {
         case 'QubitMenu':
-          $updateCol = 'label';
+          $colname = 'label';
 
           break;
 
         case 'QubitSetting':
-          $updateCol = 'value';
+          $colname = 'value';
 
           break;
 
         default:
-          $updateCol = 'name';
+          $colname = 'name';
       }
 
-      $query = "INSERT INTO $table ($updateCol, id, culture) VALUES (?, ?, 
?);";
+      $query = "INSERT INTO $table ($colname, id, culture) VALUES (?, ?, ?);";
       $insertStmt = $conn->prepare($query);
 
-      $query = "SELECT culture FROM $table WHERE id = ?";
+      $query = "SELECT target.culture, source.id FROM $table source
+        JOIN $table target ON source.id = target.id
+        WHERE source.culture = 'en'
+          AND target.culture <> 'en'
+          AND source.$colname = ?";
       $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']));
+        $id = null;
+        $existingCultures = array();
 
-        while ($c = $selectStmt->fetchColumn())
+        if (!is_array($columns[$colname]) || !isset($columns['id']))
         {
-          $existingCultures[] = $c;
+          continue;
         }
 
-        foreach ($columns as $column => $values)
+        // Build array of existing cultures, so we don't stomp user values
+        $selectStmt->execute(array(
+          $columns[$colname]['en']));
+
+        while ($item = $selectStmt->fetch(PDO::FETCH_OBJ))
         {
-          if (!is_array($values) || !isset($columns['id']))
+          $existingCultures[] = $item->culture;
+
+          if (!isset($id))
           {
-            continue;
+            $id = $item->id;
           }
+        }
 
+        // Get primary key for insert
+        foreach ($columns as $column => $values)
+        {
           foreach ($values as $culture => $value)
           {
             if (in_array($culture, $existingCultures))
@@ -806,7 +819,7 @@
             {
               $insertStmt->execute(array(
                 $value,
-                $columns['id'],
+                $id,
                 $culture));
             }
             catch (PDOException $e)

-- 
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.

Reply via email to