예제 #1
0
 /**
  * Get progress of import task
  * 
  * @return  string  JSON encoded total and position
  */
 public function progressTask()
 {
     // get request vars
     $id = Request::getInt('id', 0);
     // create import model object
     $import = new Models\Import($id);
     // get the lastest run
     $run = $import->runs('current');
     // build array of data to return
     $data = array('processed' => (int) $run->get('processed'), 'total' => (int) $run->get('count'));
     // return progress update
     echo json_encode($data);
     exit;
 }
예제 #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;
 }