Author: david
Date: Thu Dec  8 16:02:49 2011
New Revision: 10385

Log:
Handle Archivematica DIP filenames (UUID + filename + '.jpg')

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

Modified: trunk/lib/task/archivematicaDipImportTask.class.php
==============================================================================
--- trunk/lib/task/archivematicaDipImportTask.class.php Thu Dec  8 15:18:56 
2011        (r10384)
+++ trunk/lib/task/archivematicaDipImportTask.class.php Thu Dec  8 16:02:49 
2011        (r10385)
@@ -83,12 +83,39 @@
 
     $this->logSection("Link digital objects from {$arguments['filename']}...");
 
-    // Build hash on information_object.id, with array value if information
+    // If DIP folder is specified then digital objects will be in the
+    // "objects" subfolder
+    if (file_exists(rtrim($arguments['path'], '/').'/objects'))
+    {
+      $arguments['path'] = rtrim($arguments['path'], '/').'/objects';
+    }
+
+    // Create a lookup table to match original file name (foo.TIF) with DIP
+    // filename (979c4458-21f3-11e1-a4bd-001d09282b9d-foo.jpg)
+    $this->createFilenameLookup($arguments['path']);
+
+    // Build hash on information_object key, with array value if information
     // object has multiple digital objects attached 
     while ($row = fgetcsv($fh, 1000))
     {
       $filepath = rtrim($arguments['path'], '/').'/'.$row[1];
 
+      // Check if filename has been changed by Archivematica
+      if (!file_exists($filepath))
+      {
+        // Substitute original image (TIFF) name with new DIP (JPEG) name
+        $filename = basename($filepath);
+
+        if (isset($this->filenames[strtolower($filename)]))
+        {
+          $filepath = str_replace($filename, 
$this->filenames[strtolower($filename)], $filepath);
+        }
+        else
+        {
+          continue;
+        }
+      }
+
       if (!isset($digitalObjects[$row[0]]))
       {
         $digitalObjects[$row[0]] = $filepath;
@@ -178,4 +205,30 @@
 
     return $uploadDir;
   }
+
+  /**
+   * Create a lookup table to match original file name (foo.TIF) with DIP
+   * filename (979c4458-21f3-11e1-a4bd-001d09282b9d-foo.jpg)
+   */
+  protected function createFilenameLookup($path)
+  {
+    if (!($files = scandir($path)))
+    {
+      throw new sfException("Couldn't read path '$path'");
+    }
+
+    foreach ($files as $file)
+    {
+      // Format should be UUID (37 hex chars or hyphen) + filename + '.jpg'
+      $pattern = '/[0-9a-f-]{37}(.+)\.jpg/';
+
+      if (is_dir($file) || !preg_match($pattern, strtolower($file), $matches))
+      {
+        continue;
+      }
+
+      // Key is original TIFF name
+      $this->filenames[$matches[1].'.tif'] = $file;
+    }
+  }
 }

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