Author: david
Date: Tue Jan 10 12:42:56 2012
New Revision: 10618

Log:
Get ISAAR import writing actors

Modified:
   trunk/lib/task/csvIsaarImportTask.class.php
   trunk/plugins/sfIsaarPlugin/lib/qtIsaarCsv.class.php

Modified: trunk/lib/task/csvIsaarImportTask.class.php
==============================================================================
--- trunk/lib/task/csvIsaarImportTask.class.php Tue Jan 10 12:36:57 2012        
(r10617)
+++ trunk/lib/task/csvIsaarImportTask.class.php Tue Jan 10 12:42:56 2012        
(r10618)
@@ -31,31 +31,6 @@
   protected static
     $count = 0;
 
-  protected
-    $columns = array(
-      'authorizedFormOfName',
-      'datesOfExistence',
-      'descriptionIdentifier',
-      'entityType',
-      'functions',
-      'generalContext',
-      'history',
-      'identifier',
-      'institutionIdentifier',
-      'internalStructures',
-      'languages',
-      'legalStatus',
-      'maintenanceNotes',
-      'mandates',
-      'otherNames',
-      'parallelNames',
-      'places',
-      'rules',
-      'scripts',
-      'sources',
-      'standardizedNames'
-    );
-
   /**
    * @see sfTask
    */
@@ -66,6 +41,9 @@
     ));
 
     $this->addOptions(array(
+      // http://trac.symfony-project.org/ticket/8352
+      new sfCommandOption('application', null, 
sfCommandOption::PARAMETER_REQUIRED, 'The application name', true),
+      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 
'The environment', 'cli'),
       new sfCommandOption('rows-until-update', null, 
sfCommandOption::PARAMETER_OPTIONAL, 'Output total rows imported every n rows.')
     ));
 
@@ -103,16 +81,38 @@
       QubitTaxonomy::MATERIAL_TYPE_ID  => 'materialTypes'
     ));
 
-    //$isaarCsv = new qtIsaarCsv;
-
     // First row is header
     $header = fgetcsv($fh);
 
     // camelCase header values
     $header = array_map(array('QubitFlatFileImport', 'camelize'), $header);
 
-    var_dump($header);
-    die();
+    $importColumns = array_intersect($header, qtIsaarCsv::$NAMES);
+
+    while ($row = fgetcsv($fh))
+    {
+      $isaarCsv = new qtIsaarCsv(new QubitActor);
+
+      foreach (array_combine($header, $row) as $name => $value)
+      {
+        if (in_array($name, qtIsaarCsv::$NAMES))
+        {
+          $isaarCsv->__set($name, $value);
+        }
+      }
+
+      $isaarCsv->save();
+
+      $this->count++;
+
+// FOR DEBUGGING stop after TWO rows
+      if (1 < $this->count)
+      {
+        break;
+      }
+    }
+
+    fclose($fh);
   }
 
   protected function loadTaxonomyTerms($taxonomies)

Modified: trunk/plugins/sfIsaarPlugin/lib/qtIsaarCsv.class.php
==============================================================================
--- trunk/plugins/sfIsaarPlugin/lib/qtIsaarCsv.class.php        Tue Jan 10 
12:36:57 2012        (r10617)
+++ trunk/plugins/sfIsaarPlugin/lib/qtIsaarCsv.class.php        Tue Jan 10 
12:42:56 2012        (r10618)
@@ -27,46 +27,61 @@
  */
 class qtIsaarCsv extends sfIsaarPlugin
 {
-  public function __get($name)
-  {
-  }
+  protected
+    $resource,
+    $isaar;
+
+  public static
+    $NAMES = array(
+      'authorizedFormOfName',
+      'datesOfExistence',
+      'descriptionIdentifier',
+      //'entityType',
+      'functions',
+      'generalContext',
+      'history',
+      'identifier',
+      'institutionIdentifier',
+      'internalStructures',
+      'languages',
+      'legalStatus',
+      'maintenanceNotes',
+      'mandates',
+      //'otherNames',
+      //'parallelNames',
+      'places',
+      'rules',
+      'scripts',
+      'sources',
+      //'standardizedNames'
+    );
 
-  public function __set($name, $value)
+  public function __construct($resource)
   {
+    $this->resource = $resource;
+    $this->isaar = new sfIsaarPlugin($this->resource);
   }
 
-  /**
-   * Parse $csv and create new ISAAR actor objects
-   *
-   * @param string csv  path to a CSV file
-   *
-   * @return int number of rows parsed
-   */
-  public static function parse($csv)
+  public function __get($name)
   {
-    $count = 0;
-
-    if (false === ($fh = fopen($csv, 'r'))
+    if (in_array($name, self::$NAMES))
     {
-      throw sfException("Couldn't read file $csv.");
+      return $this->resource->__get($name);
     }
+  }
 
-    $headers = fgetcsv($fh);
-
-    while ($row = $fgetcsv($fh))
+  public function __set($name, $value)
+  {
+    if (in_array($name, self::$NAMES))
     {
-      $isaarCsv = new sfIsaarCsvPlugin(new QubitActor);
-
-      foreach ($row as $i => $item)
-      {
-        $isaarCsv->__set($headers[$i], $item);
-      }
-
-      $isaarCsv->save();
-
-      $count++;
+      $this->resource->__set($name, $value);
     }
 
-    return $count;
+    return $this;
+  }
+
+  public function save($connection = null)
+  {
+    $this->resource->save($connection);
   }
 }

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