/** * Method to create import filespace if needed * * @param object $import Models\Import * @return boolean */ private function _createImportFilespace(Models\Import $import) { // upload path $uploadPath = $import->fileSpacePath(); // if we dont have a filespace, create it if (!is_dir($uploadPath)) { \Filesystem::makeDirectory($uploadPath, 0775); } // all set return true; }
/** * Method auto detect adapter based on mime type * * @access private * @param ResourcesImportInterface Object * @return void */ private function autoDetectAdapter(\Components\Resources\Models\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); // 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('Resource Import: No adapter found to count import data.')); } }
/** * 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; }