Пример #1
0
 /**
  * Store changes to this database entry
  *
  * @param   boolean  $check  Perform data validation check?
  * @return  boolean  False if error, True on success
  */
 public function store($check = true)
 {
     $this->set('type', 'members');
     /*if ($this->_fields)
     		{
     			$this->set('field_map', json_encode($this->_fields));
     		}*/
     return parent::store($check);
 }
Пример #2
0
 /**
  * Get a list or count of imports
  *
  * @param   string   $rtrn     What data to return
  * @param   array    $filters  Filters to apply to data retrieval
  * @param   boolean  $boolean  Clear cached data?
  * @return  mixed
  */
 public function imports($rtrn = 'list', $filters = array(), $clear = false)
 {
     $model = Import::all();
     if (isset($filters['state']) && $filters['state']) {
         if (!is_array($filters['state'])) {
             $filters['state'] = array($filters['state']);
         }
         $filters['state'] = array_map('intval', $filters['state']);
         $model->whereIn('state', $filters['state']);
     }
     if (!isset($filters['type'])) {
         $filters['type'] = $this->type;
     }
     if (isset($filters['type']) && $filters['type']) {
         $model->whereEquals('type', $filters['type']);
     }
     if (isset($filters['created_by']) && $filters['created_by'] >= 0) {
         $model->whereEquals('created_by', $filters['created_by']);
     }
     if (strtolower($rtrn) == 'count') {
         return $model->total();
     }
     return $model->ordered()->paginated()->rows();
 }
Пример #3
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;
 }
Пример #4
0
 /**
  * Method auto detect adapter based on mime type
  *
  * @param   object  $import
  * @return  void
  */
 private function autoDetectAdapter(Import $import)
 {
     // make sure we dont already have an adapter
     if ($this->adapter) {
         return;
     }
     // get path to data file
     $dataPath = $import->getDataPath();
     // get the mime type of file
     $file = finfo_open(FILEINFO_MIME_TYPE);
     $mime = finfo_file($file, $dataPath);
     if ($mime == 'text/plain') {
         $mime = pathinfo($dataPath, PATHINFO_EXTENSION);
     }
     // anonymous function to see if we can use any
     $respondsTo = function ($class) use($mime) {
         return $class::accepts($mime);
     };
     // set the adapter if we found one
     $responded = array_filter($this->adapters, $respondsTo);
     if ($adapter = array_shift($responded)) {
         $this->setAdapter(new $adapter());
     }
     // do we still not have adapter
     if (!$this->adapter) {
         throw new \Exception(\Lang::txt('Content Import: No adapter found to count import data.'));
     }
 }
Пример #5
0
 /**
  * Method to create import filespace if needed
  *
  * @param   object  $import  \Hubzero\Content\Import\Model\Import
  * @return  boolean
  */
 private function _createImportFilespace(\Hubzero\Content\Import\Model\Import $import)
 {
     // Upload path
     $uploadPath = $import->fileSpacePath();
     // If we dont have a filespace, create it
     if (!is_dir($uploadPath)) {
         if (!Filesystem::makeDirectory($uploadPath)) {
             $this->setError(Lang::txt('Failed to create target upload path "%s".', $uploadPath));
             return false;
         }
     }
     return true;
 }
Пример #6
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;
 }
Пример #7
0
 /**
  * Store changes to this database entry
  *
  * @return  boolean  False if error, True on success
  */
 public function save()
 {
     $this->set('type', 'members');
     return parent::save();
 }