Author: david
Date: Wed Dec  7 17:37:59 2011
New Revision: 10373

Log:
Migrate digital objects when repository has no slug yet (not finishe)

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

Modified: trunk/lib/task/migrate/QubitMigrate110.class.php
==============================================================================
--- trunk/lib/task/migrate/QubitMigrate110.class.php    Wed Dec  7 15:39:00 
2011        (r10372)
+++ trunk/lib/task/migrate/QubitMigrate110.class.php    Wed Dec  7 17:37:59 
2011        (r10373)
@@ -643,10 +643,13 @@
 
     foreach ($this->data['QubitDigitalObject'] as $key => &$item)
     {
+      var_dump($key);
+
       if (!isset($item['information_object_id']))
       {
         continue;
       }
+var_dump('BBBBB');
 
       // Get the related information object
       $infoObject = $this->getRowByKeyOrId('QubitInformationObject', 
$item['information_object_id']);
@@ -655,12 +658,14 @@
         continue;
       }
 
+var_dump('CCCCC');
       // 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']);
       }
 
+var_dump('DDDDD');
       // Get repository
       if (isset($infoObject['repository_id']))
       {
@@ -668,7 +673,7 @@
 
         if (!isset($repo['slug']))
         {
-          continue;
+          $repo['slug'] = 
$this->getUniqueSlug($repo['authorized_form_of_name']);
         }
 
         $repoName = $repo['slug'];
@@ -678,6 +683,8 @@
         $repoName = 'null';
       }
 
+var_dump($repoName);
+
       // Update digital object and derivatives paths
       foreach ($this->data['QubitDigitalObject'] as $key2 => &$item2)
       {
@@ -1128,4 +1135,27 @@
 
     return $this;
   }
-}
+
+  function getUniqueSlug($string)
+  {
+    $slug = $root = QubitSlug::slugify($string);
+
+    for ($i = 0; $i < 100; $i++)
+    {
+      foreach ($this->data['QubitRepository'] as $item)
+      {
+        if (isset($item['slug'] == $slug))
+        {
+          $slug = $root.'-'.($i + 1);
+
+          break;
+        }
+      }
+
+      // If $slug hasn't been incremented this pass
+      if ($slug == $root || $slug == $root.'-'.$i)
+      {
+        return $slug
+      }
+    }
+  }

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