Author: david
Date: Mon Aug 22 16:25:40 2011
New Revision: 9561

Log:
Attempt to update asset paths to include repository pk using the migration task.

Modified:
   trunk/data/fixtures/settings.yml
   trunk/lib/task/migrate/QubitMigrate.class.php
   trunk/lib/task/migrate/QubitMigrate110.class.php

Modified: trunk/data/fixtures/settings.yml
==============================================================================
--- trunk/data/fixtures/settings.yml    Fri Aug 19 16:06:39 2011        (r9560)
+++ trunk/data/fixtures/settings.yml    Mon Aug 22 16:25:40 2011        (r9561)
@@ -3,7 +3,7 @@
     name: version
     editable: 0
     deleteable: 0
-    value: 69
+    value: 70 
   QubitSetting_2:
     name: upload_dir
     editable: 0

Modified: trunk/lib/task/migrate/QubitMigrate.class.php
==============================================================================
--- trunk/lib/task/migrate/QubitMigrate.class.php       Fri Aug 19 16:06:39 
2011        (r9560)
+++ trunk/lib/task/migrate/QubitMigrate.class.php       Mon Aug 22 16:25:40 
2011        (r9561)
@@ -139,6 +139,32 @@
     return $this;
   }
 
+  /**
+   * Try to match a row when the search key may be the row key or the object id
+   * - as is often the case with foreign key relations in $this->data
+   *
+   * @param string classname name of Qubit class (e.g. QubitInformationObject)
+   * @param string keyOrId row key or 'id' column value
+   * @return array the found row, or NULL for no match
+   */
+  public function getRowByKeyOrId($classname, $keyOrId)
+  {
+    $row = null;
+
+    if (isset($this->data[$classname][$keyOrId]))
+    {
+      $row = $this->data[$classname][$keyOrId];
+      $row['_key'] = $keyOrId;
+    }
+    else if ($key = $this->getRowKey($this->data[$classname], 'id', $keyOrId))
+    {
+      $row = $this->data[$classname][$key];
+      $row['_key'] = $key;
+    }
+
+    return $row;
+  }
+
   /*
    * ------------------
    * STATIC METHODS

Modified: trunk/lib/task/migrate/QubitMigrate110.class.php
==============================================================================
--- trunk/lib/task/migrate/QubitMigrate110.class.php    Fri Aug 19 16:06:39 
2011        (r9560)
+++ trunk/lib/task/migrate/QubitMigrate110.class.php    Mon Aug 22 16:25:40 
2011        (r9561)
@@ -70,6 +70,9 @@
 
       case 68:
         $this->addThemesMenu();
+
+      case 69:
+        $this->updatePathToAssets();
     }
 
     // Delete "stub" objects
@@ -587,6 +590,58 @@
   }
 
   /**
+   * Move digital objects to repository specific paths like
+   * http://code.google.com/p/qubit-toolkit/source/detail?r=9503
+   *
+   * @return QubitMigrate110 SELF
+   */
+  protected function updatePathToAssets()
+  {
+    foreach ($this->data['QubitDigitalObject'] as $key => &$item)
+    {
+      if (!isset($item['information_object_id']))
+      {
+        continue;
+      }
+
+      // Get the related information object 
+      $infoObject = $this->getRowByKeyOrId('QubitInformationObject', 
$item['information_object_id']);
+      if (null === $infoObject)
+      {
+        continue;
+      }
+
+      // Recursively check info object ancestors for repository foreign key 
+      while (!isset($infoObject['repository_id']) && 
isset($infoObject['parent_id']))
+      {
+        $infoObject = $this->getRowByKeyOrId('QubitInformationObject', 
$infoObject['parent_id']);
+      }
+
+      if (!isset($infoObject['repository_id']))
+      {
+        continue;
+      }
+
+      // Get repository
+      $repo = $this->getRowByKeyOrId('QubitRepository', 
$infoObject['repository_id']);
+
+      // Update path
+      $item['path'] = str_replace('uploads', 'uploads/repo/'.$repo['_key'], 
$item['path']);
+
+      // Update derivative paths
+      foreach ($this->data['QubitDigitalObject'] as $key2 => &$item2)
+      {
+        if (isset($item2['parent_id']) && $key == $item2['parent_id'])
+        {
+          $item2['path'] = str_replace('uploads', 
'uploads/repo/'.$repo['_key'], $item2['path']);
+        }
+      }
+    }
+
+    return $this;
+  }
+
+  /**
    * Slugs are inserted when some resources are inserted, but slugs are dumped
    * separately when data is dumped. So loading slug data will try to insert
    * duplicate slugs. To work around this, turn slugs into resource properties

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