Author: david
Date: Wed Aug 24 13:34:07 2011
New Revision: 9579

Log:
Fix logic for moving assets from old path to new.  Remove 'uploads' directory 
from path in database - rely on sf_upload_dir setting instead.

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

Modified: trunk/lib/task/migrate/QubitMigrate110.class.php
==============================================================================
--- trunk/lib/task/migrate/QubitMigrate110.class.php    Wed Aug 24 09:51:53 
2011        (r9578)
+++ trunk/lib/task/migrate/QubitMigrate110.class.php    Wed Aug 24 13:34:07 
2011        (r9579)
@@ -601,9 +601,9 @@
   protected function updatePathToAssets()
   {
     // Create "uploads/r" subdirectory
-    if (!file_exists(sfConfig::get('sf_web_dir').'uploads/r'))
+    if (!file_exists(sfConfig::get('sf_upload_dir').'/r'))
     {
-      mkdir(sfConfig::get('sf_web_dir').'uploads/r');
+      mkdir(sfConfig::get('sf_upload_dir').'/r');
     }
 
     foreach ($this->data['QubitDigitalObject'] as $key => &$item)
@@ -613,28 +613,39 @@
         continue;
       }
 
-      // Get the related information object 
+      // 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 
+      // 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']))
+      // Get repository
+      if (isset($infoObject['repository_id']))
       {
-        continue;
+        $repo = $this->getRowByKeyOrId('QubitRepository', 
$infoObject['repository_id']);
+      }
+      else
+      {
+        $repo = 'null';
       }
 
-      // Get repository
-      $repo = $this->getRowByKeyOrId('QubitRepository', 
$infoObject['repository_id']);
+      // Make repository directory
+      if (!file_exists(sfConfig::get('sf_upload_dir').'/r/'.$repo['slug']))
+      {
+        if (!mkdir(sfConfig::get('sf_upload_dir').'/r/'.$repo['slug']))
+        {
+          continue;
+        }
+      }
 
-      // Update digital object and derivatives
+      // Update digital object and derivatives paths
       foreach ($this->data['QubitDigitalObject'] as $key2 => &$item2)
       {
         if ($key == $key2 || (isset($item2['parent_id']) && $key == 
$item2['parent_id']))
@@ -646,16 +657,21 @@
             continue;
           }
 
-          // Move assets
-          $newpath = str_replace('uploads', 'uploads/r/'.$repo['slug'], 
$item2['path'].$item2['name']);
+          // Move entire info object directory (e.g. 'uploads/3/1/318/' to 
+          // 'uploads/r/repo-name/3/1/318')
+          $old = substr($item2['path'], 0, 10); // e.g. '/uploads/3'
+          $new = str_replace('uploads', 'r/'.$repo['slug'], $old);
 
-          if 
(!rename(sfConfig::get('sf_web_dir').$item2['path'].$item2['name'], 
sfConfig::get('sf_web_dir').$newpath))
+          if (file_exists(sfConfig::get('sf_web_dir').$old))
           {
-            continue; // If rename fails, don't update path
+            if (!rename(sfConfig::get('sf_web_dir').$old, 
sfConfig::get('sf_upload_dir').$new))
+            {
+              continue; // If rename fails, don't update path
+            }
           }
 
-          // Update path
-          $item2['path'] = $newpath;
+          // Update path in yaml file
+          $item2['path'] = str_replace('uploads', 'r/'.$repo['slug'], 
$item2['path']);
         }
       }
     }

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