Exemple #1
0
 /**
  * @return AppData
  */
 public function setParams($key, $value)
 {
     $params = $this->getParams();
     $params->set($key, $value);
     $params = $this->app->jbarray->mapRecursive(function ($value) {
         if (is_array($value) || $value instanceof AppData) {
             $value = (array) $value;
         }
         return $value;
     }, $params);
     $this->_session->set('params', (array) $params, 'migration');
 }
Exemple #2
0
 /**
  * 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;
     }
 }
Exemple #3
0
 /**
  * @return bool
  */
 protected function _postImport()
 {
     $addedIds = (array) $this->_jbsession->get('ids', 'import-ids');
     $addedIds = array_filter($addedIds);
     $mode = $this->_jbsession->get('lose', 'import');
     if ($mode == 0) {
         $this->_('No post precessing', 'Info');
     } else {
         $this->_('Total items imported: ' . count($addedIds), 'Info');
     }
     $this->_jbsession->set('ids', $addedIds, 'import-ids');
     @$this->_jbimport->itemsPostProcess();
     return true;
 }
Exemple #4
0
 /**
  * Execute test by name
  * @param string $testName
  * @return array
  */
 public function execTest($testName)
 {
     $actionName = '_test' . str_replace('_', '', $testName);
     if ($testName == 'engine_init') {
         $this->_jbsession->clearGroup($this->_sessionGroup);
     }
     if (method_exists($this, $actionName)) {
         //run tests
         $values = array();
         for ($j = 0; $j < self::TEST_COUNT; $j++) {
             $st = microtime(true);
             $result = call_user_func(array($this, $actionName));
             $fin = microtime(true);
             if (is_null($result)) {
                 $values[] = $fin - $st;
             } else {
                 $values[] = $result;
             }
             if (self::TEST_COUNT > 1) {
                 sleep(1);
                 // without very hard test!
             }
         }
         if (strpos($testName, 'version') === 0 || $testName == 'system_loadavg') {
             // hack
             reset($values);
             $value = current($values);
         } else {
             $value = array_sum($values) / count($values);
         }
         $this->_jbsession->set($testName, $value, $this->_sessionGroup);
         // set output format
         return array('value' => $this->toFormat($value, $testName), 'alert' => $this->isAlert($value, $testName));
     }
     return array();
 }