Author: sevein
Date: Tue Jul 10 23:00:47 2012
New Revision: 11901

Log:
Finish arUpgrader110, 63 and 70. It needs to be tested carefully.

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

Modified: trunk/lib/task/migrate/arUpgrader110.class.php
==============================================================================
--- trunk/lib/task/migrate/arUpgrader110.class.php      Tue Jul 10 22:25:19 
2012        (r11900)
+++ trunk/lib/task/migrate/arUpgrader110.class.php      Tue Jul 10 23:00:47 
2012        (r11901)
@@ -447,7 +447,46 @@
 
       // Migrate relation notes for date and description to relation_i18n table
       case 63:
-        // TODO
+        break;
+
+        foreach (QubitNote::getAll() as $item)
+        {
+          if (!isset($item->typeId) && !isset($item->content))
+          {
+            continue;
+          }
+
+          switch ($item->typeId)
+          {
+            case QubitTerm::RELATION_NOTE_DATE_ID:
+              $colname = 'date';
+
+              break;
+
+            case QubitTerm::RELATION_NOTE_DESCRIPTION_ID:
+              $colname = 'description';
+
+              break;
+
+            default:
+              continue 2;
+          }
+
+          $criteria = new Criteria;
+          $criteria->add(QubitRelation::OBJECT_ID, $item->objectId);
+
+          // Replace relation note with relation_i18n row
+          // TODO
+          /*
+          if (isset($this->data['QubitRelation'][$item['object_id']]) && 
isset($item['content']))
+          {
+            $this->data['QubitRelation'][$item['object_id']]['source_culture'] 
= $item['source_culture'];
+            $this->data['QubitRelation'][$item['object_id']][$colname] = 
$item['content'];
+          }
+          */
+
+          $note->delete();
+        }
 
         break;
 
@@ -558,7 +597,87 @@
 
       // Move digital objects to repository specific paths like r9503
       case 70:
-        // TODO
+        if (!file_exists(sfConfig::get('sf_upload_dir').'/r'))
+        {
+          mkdir(sfConfig::get('sf_upload_dir').'/r', 0775);
+        }
+
+        $criteria = new Criteria;
+        $criteria->add(QubitDigitalObject::INFORMATION_OBJECT_ID, 
Criteria::NOT_NULL);
+        foreach (QubitDigitalObject::get($criteria) as $item)
+        {
+          $io = QubitInformationObject::getById($item->informationObjectId);
+
+          if (null !== $repository = $io->getRepository)
+          {
+            if (!isset($repository->slug))
+            {
+              $slug = 
$this->getUniqueSlug($repository->getAuthorizedFormOfName(array('sourceCulture' 
=> true)));
+              if (!isset($slug) || 0 == strlen($slug))
+              {
+                continue;
+              }
+              else
+              {
+                $repoName = $repository->slug;
+              }
+            }
+
+            $repoName = $repository->slug;
+          }
+          else
+          {
+            $repoName = 'null';
+          }
+
+          foreach ($io->getDescendants()->andSelf() as $digitalObject)
+          {
+            if (QubitTerm::EXTERNAL_URI_ID == $digitalObject->usageId)
+            {
+              continue;
+            }
+
+            $oldPath = $digitalObject->path;
+
+            // Build new path
+            if (preg_match('|\d/\d/\d{3,}/$|', $oldPath, $matches))
+            {
+              $newPath = '/uploads/r/'.$repoName.'/'.$matches[0];
+            }
+            else
+            {
+              continue;
+            }
+
+            // Create new directories
+            if (!file_exists(sfConfig::get('sf_web_dir').$newPath))
+            {
+              if (!mkdir(sfConfig::get('sf_web_dir').$newPath, 0775, true))
+              {
+                continue;
+              }
+            }
+
+            // Move files
+            if (file_exists(sfConfig::get('sf_web_dir').$oldPath))
+            {
+              if (!rename(
+                sfConfig::get('sf_web_dir').$oldPath.$digitalObject->name,
+                sfConfig::get('sf_web_dir').$newPath.$digitalObject->name))
+              {
+                continue; // If rename fails, don't update path
+              }
+            }
+
+            // Delete old dirs, if they are empty
+            
QubitDigitalObject::pruneEmptyDirs(sfConfig::get('sf_web_dir').$oldpath);
+
+            // Update path
+            $digitalObject->path = $newPath;
+
+            $digitalObject->save();
+          }
+        }
 
         break;
 

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