Author: sevein
Date: Thu Jan  5 22:54:02 2012
New Revision: 10580

Log:
Import objectUUID and add it as a property in archivemaicaDipImportTask

Modified:
   trunk/lib/task/archivematicaDipImportTask.class.php

Modified: trunk/lib/task/archivematicaDipImportTask.class.php
==============================================================================
--- trunk/lib/task/archivematicaDipImportTask.class.php Thu Jan  5 17:11:52 
2012        (r10579)
+++ trunk/lib/task/archivematicaDipImportTask.class.php Thu Jan  5 22:54:02 
2012        (r10580)
@@ -60,7 +60,7 @@
 
 The import script expects that Archivematica will have modified the file name 
so:
 a) The original TIFF image has been converted to a JPEG and now has a ".jpg" 
extension
-b) A UUID has been pre-pended to the filename
+b) A UUID has been pre-pended to the filename (i.e.: 
"815da5cf-f49f-41f5-aa5d-c40d9d4dec3c-MARBLES.jpg")
 
 Note: Filenames must be unique (without UUID) within "path" to avoid colliding 
on import.
 EOF;
@@ -146,17 +146,28 @@
       if (!is_array($item))
       {
         self::addDigitalObject($informationObject, $item, $conn);
+
+        if (null !== $objectUUID = $this->getUUID(basename($item)))
+        {
+          $informationObject->addProperty('objectUUID', $objectUUID);
+        }
       }
       else
       {
         // If more than one digital object linked to this information object
-        for ($i=0; $i < count($item); $i++)
+        for ($i = 0; $i < count($item); $i++)
         {
           // Create new information objects, to maintain one-to-one
           // relationship with digital objects
           $informationObject = new QubitInformationObject;
           $informationObject->parent = QubitInformationObject::getById($key);
           $informationObject->title = basename($item[$i]);
+
+          if (null !== $objectUUID = $this->getUUID(basename($item)))
+          {
+            $informationObject->addProperty('objectUUID', $objectUUID);
+          }
+
           $informationObject->save($conn);
 
           self::addDigitalObject($informationObject, $item[$i], $conn);
@@ -227,7 +238,7 @@
     foreach ($files as $file)
     {
       // Format should be UUID (37 hex chars or hyphen) + filename + '.jpg'
-      $pattern = '/[0-9a-f-]{37}(.+)\.jpg/';
+      $pattern = '/^[0-9a-f-]{37}(.+)\.jpg$/';
 
       if (is_dir($file) || !preg_match($pattern, strtolower($file), $matches))
       {
@@ -238,4 +249,11 @@
       $this->filenames[$matches[1].'.tif'] = $file;
     }
   }
+
+  protected function getUUID($subject)
+  {
+    
preg_match('/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/', 
$subject, $matches);
+
+    return @$matches[0];
+  }
 }

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