Author: david
Date: Tue Jun 12 14:53:00 2012
New Revision: 11767

Log:
Add path prefix parameter

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

Modified: trunk/lib/task/digitalObjectLoadTask.class.php
==============================================================================
--- trunk/lib/task/digitalObjectLoadTask.class.php      Tue Jun 12 00:02:55 
2012        (r11766)
+++ trunk/lib/task/digitalObjectLoadTask.class.php      Tue Jun 12 14:53:00 
2012        (r11767)
@@ -43,6 +43,7 @@
       new sfCommandOption('application', null, 
sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
       new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 
'The environment', 'cli'),
       new sfCommandOption('connection', null, 
sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'),
+      new sfCommandOption('path', 'p', sfCommandOption::PARAMETER_OPTIONAL, 
'Path prefix for digital objects', null),
     ));
 
     $this->namespace = 'digitalobject';
@@ -62,6 +63,8 @@
     $databaseManager = new sfDatabaseManager($this->configuration);
     $conn = $databaseManager->getDatabase('propel')->getConnection();
 
+    array_push($options, $conn);
+
     sfConfig::set('app_upload_dir', self::getUploadDir($conn));
 
     if (false === $fh = fopen($arguments['filename'], 'rb'))
@@ -112,7 +115,7 @@
 
       if (!is_array($item))
       {
-        self::addDigitalObject($informationObject, $item, $conn);
+        self::addDigitalObject($informationObject, $item, $options);
       }
       else
       {
@@ -125,8 +128,8 @@
           $informationObject->parent = QubitInformationObject::getById($key);
           $informationObject->title = basename($item[$i]);
           $informationObject->save($conn);
-          
-          self::addDigitalObject($informationObject, $item[$i], $conn);
+
+          self::addDigitalObject($informationObject, $item[$i], $options);
         }
       }
     }
@@ -134,17 +137,22 @@
     $this->logSection('Successfully Loaded '.self::$count.' digital objects.');
   }
 
-  protected function addDigitalObject($informationObject, $filepath, $conn)
+  protected function addDigitalObject($informationObject, $path, $options = 
array())
   {
+    if (isset($options['path']))
+    {
+      $path = $options['path'].$path;
+    }
+
     // read file contents
-    if (false === $content = file_get_contents($filepath))
+    if (false === $content = file_get_contents($path))
     {
-      $this->log("Couldn't read file '$filepath'");
+      $this->log("Couldn't read file '$path'");
 
       return;
     }
 
-    $filename = basename($filepath);
+    $filename = basename($path);
     $this->log("Loading '$filename'");
 
     // Create digital object

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