/** * Import dialog action */ public function assign() { $csvfile = $this->_jbrequest->getFile('csvfile', JBRequestHelper::ADMIN_FORM_KEY); $request = $this->_jbrequest->getAdminForm(); $importType = isset($request['import-type']) ? $request['import-type'] : null; if (empty($request['separator'])) { $request['separator'] = $this->_defaultParams['separator']; } if (empty($request['enclosure'])) { $request['enclosure'] = $this->_defaultParams['enclosure']; } // validate upload file try { $userfile = $this->app->validator->create('file', array('extension' => array('csv')))->clean($csvfile); } catch (AppException $e) { $this->app->jbnotify->notice(JText::_('JBZOO_UNABLE_TO_UPLOAD_FILE') . ' (' . $e . ')'); $this->setRedirect($this->app->jbrouter->admin(array('task' => $importType))); return; } // upload file $file = $this->_jbimport->getTmpFilename(); if (JFile::upload($userfile['tmp_name'], $file)) { // prepare session data $this->_config->setGroup('import.' . $importType, $request); $request['file'] = $file; // save to session $this->_jbsession->setGroup($request, 'import'); // prepare data $this->info = $this->_jbimport->getInfo($file, $request); $this->_jbsession->set('count', $this->info['count'], 'import'); // render pseudo template if ($importType == 'items') { // some vars for template $this->controls = $this->_jbimport->itemsControls($this->info); $this->prevParams = $this->_config->getGroup('import.last.items', $this->_jbuser->getParam('lastImport-items')); $this->renderView('items'); } else { if ($importType == 'categories') { // some vars for template $this->controls = $this->_jbimport->categoriesControls($this->info); $this->prevParams = $this->_config->getGroup('import.last.categories', $this->_jbuser->getParam('lastImport-categories')); $this->renderView('categories'); } else { jexit('Unknown import type!'); // TODO replace to exception } } } else { $this->app->error->raiseNotice(0, JText::_('JBZOO_CHECK_TEMP_PERMISIONS')); $this->setRedirect($this->baseurl . '&task=index'); return; } }
/** * Check CSV-file (isExists & isEmpty) * @return array */ protected function _getCsvInfo() { $csvFile = \JPath::clean($this->_config->get('source')); if (!\JFile::exists($csvFile)) { $this->_('CSV file not found: "' . $csvFile . '"', 'error', 1); } // Get CSV-file info $fileInfo = $this->_jbimport->getInfo($csvFile, array('header' => $this->_config->find('csv.header', 1), 'separator' => $this->_config->find('csv.separator', ','), 'enclosure' => $this->_config->find('csv.enclosure', '"'))); if ($fileInfo['count'] <= 0) { $this->_('Rows not found in CSV-file', 'Error', 1); } if ($fileInfo['columns'] <= 0) { $this->_('Columns not found in CSV-file', 'Error', 1); } $fileInfo['path'] = $csvFile; return $fileInfo; }