예제 #1
0
 /**
  * Count Import data
  *
  * @access public
  * @return int
  */
 public function count(\Components\Resources\Models\Import $import)
 {
     // instantiate iterator
     $xmlIterator = new \Components\Resources\Import\Iterators\Xml($import->getDatapath(), $this->key);
     // count records
     $this->data_count = iterator_count($xmlIterator);
     // return count
     return $this->data_count;
 }
예제 #2
0
 /**
  * Process Import data
  *
  * @access public
  * @param  Closure Object
  */
 public function process(\Components\Resources\Models\Import $import, array $callbacks, $dryRun)
 {
     // create new xml reader
     $iterator = new \Components\Resources\Import\Iterators\Csv($import->getDatapath(), $this->delimiter);
     // get the import params
     $options = new \Hubzero\Config\Registry($import->get('params'));
     // get the mode
     $mode = $import->get('mode', 'UPDATE');
     // loop through each item
     foreach ($iterator as $index => $record) {
         // make sure we have a record
         if ($record === null) {
             continue;
         }
         // do we have a post parse callback ?
         $record = $this->map($record, $callbacks['postparse'], $dryRun);
         // convert to resource objects
         $resource = new \Components\Resources\Models\Import\Record($record, $options->toArray(), $mode);
         // do we have a post map callback ?
         $resource = $this->map($resource, $callbacks['postmap'], $dryRun);
         // run resource check & store
         $resource->check()->store($dryRun);
         // do we have a post convert callback ?
         $resource = $this->map($resource, $callbacks['postconvert'], $dryRun);
         // add to data array
         array_push($this->data, $resource);
         // mark record processed
         $import->runs('current')->processed(1);
     }
     return $this->data;
 }