Example #1
0
 /**
  * Process Import data
  *
  * @param   object  $import     Import record
  * @param   array   $callbacks  Array of Callbacks
  * @param   bool    $dryRun     Dry Run mode?
  * @return  object
  */
 public function process(Import $import, array $callbacks, $dryRun)
 {
     // create new iterator
     $iterator = new Reader($import->getDatapath(), $this->delimiter);
     // get the import params
     $options = new Parameter($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;
         }
         // Make sure we didn't get an empty row
         $data = array_map('trim', (array) $record);
         if (!array_filter($data)) {
             continue;
         }
         // do we have a post parse callback ?
         $record = $this->map($record, $callbacks['postparse'], $dryRun);
         // convert to resource objects
         $entry = $import->getRecord($record, $options->toArray(), $mode);
         // do we have a post map callback ?
         $entry = $this->map($entry, $callbacks['postmap'], $dryRun);
         // run resource check & store
         $entry->check()->store($dryRun);
         // do we have a post convert callback ?
         $entry = $this->map($entry, $callbacks['postconvert'], $dryRun);
         // add to data array
         array_push($this->data, $entry);
         // mark record processed
         $import->currentRun()->processed(1);
     }
     return $this->data;
 }
Example #2
0
 /**
  * Process Import data
  *
  * @param   object  $import     Import record
  * @param   array   $callbacks  Array of Callbacks
  * @param   bool    $dryRun     Dry Run mode?
  * @return  object
  */
 public function process(Import $import, array $callbacks, $dryRun)
 {
     // create new xml reader
     $iterator = new Reader($import->getDataPath(), $this->key);
     // get the import params
     $options = new Parameter($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 objects
         $entry = $import->getRecord($record, $options->toArray(), $mode);
         // do we have a post map callback ?
         $entry = $this->map($entry, $callbacks['postmap'], $dryRun);
         // run check & store
         $entry->check()->store($dryRun);
         // do we have a post convert callback ?
         $entry = $this->map($entry, $callbacks['postconvert'], $dryRun);
         // add to data array
         array_push($this->data, $entry);
         // mark record processed
         $import->runs('current')->processed(1);
     }
     return $this->data;
 }