public function test_register_withOldData() { $miner = new LispMiner(self::$cfg); $cfg = array('server' => 'db-srv', 'database' => 'test', 'username' => 'db_user', 'password' => 'secret1', 'type' => 'MySQLConnection'); $result = $miner->register($cfg); $this->assertEquals(22, strlen($result), 'ID should 22 chars'); return $result; }
function save() { global $option; // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); $id = JRequest::getVar('id', array(0), 'method', 'array'); $name = JRequest::getVar('name', '', 'post', 'string'); $db_type = JRequest::getVar('type', '', 'post', 'string'); $db_conf = JRequest::getVar('db', '', 'post', 'string', JREQUEST_ALLOWRAW); $matrix_name = JRequest::getVar('matrix', '', 'post', 'string'); $dataDictionary = JRequest::getVar('dataDictionary', '', 'post', 'string', JREQUEST_ALLOWRAW); $this->setRedirect("index.php?option={$option}&controller=registerlmserver&id[]={$id[0]}"); try { $model =& $this->getModel('lmservers'); $server = $model->getLmserver($id[0]); $db_conf = json_decode($db_conf, true); $db_conf['type'] = $db_type; $miner = new LispMiner(array('url' => $server->url)); $server_id = $miner->register($db_conf); // Import Data Dictionary $miner->importDataDictionary($dataDictionary, $server_id); $db =& JFactory::getDBO(); $table =& JTable::getInstance('source', 'Table'); $table->name = $name; $table->url = $server->url; $table->type = 'LISPMINER'; $table->method = 'POST'; $table->params = json_encode(array('miner_id' => $server_id, 'matrix' => $matrix_name)); $table->dictionaryquery = ''; //$table->dictionaryquery = if (!$table->check()) { throw new Exception($table->getError()); } if (!$table->store()) { throw new Exception($table->getError()); } $table->checkin(); $this->setRedirect("index.php?option={$option}&controller=sources"); $this->setMessage(JText::_('Server sucessfully registered.')); } catch (Exception $ex) { JFactory::getApplication()->enqueueMessage(JText::_('ERROR REGISTERING SERVER') . "<br />" . $ex->getMessage(), 'error'); // try to remove registered miner as it is in invalid state. if (isset($server_id) && isset($miner)) { try { $miner->unregister($server_id); } catch (Exception $innerException) { JFactory::getApplication()->enqueueMessage(JText::_('ERROR REMOVING REGISTERING SERVER') . "<br />" . $innerException->getMessage(), 'error'); } } } }
function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); $app = JFactory::getApplication(); $id = JRequest::getVar('id', array(0), 'method', 'array'); $name = JRequest::getVar('name', '', 'post', 'string'); $db_type = JRequest::getVar('type', '', 'post', 'string'); $db_conf = JRequest::getVar('db', '', 'post', 'string', JREQUEST_ALLOWRAW); $matrix_name = JRequest::getVar('matrix', '', 'post', 'string'); $dataDictionary = JRequest::getVar('dataDictionary', '', 'post', 'string', JREQUEST_ALLOWRAW); $this->setRedirect("index.php?option={$this->com_kbi}&controller=registerlmserver&id[]={$id[0]}"); try { $model = $this->getModel('lmservers'); $sources = $this->getModel('sources'); $server = $model->getLmserver($id[0]); $session = JFactory::getSession(); $db_conf = json_decode($db_conf, true); $db_conf['type'] = $db_type; $miner = new LispMiner(array('url' => $server->url)); $miner->setUser($session->get('user', null, 'sewebar')); $server_id = $miner->register($db_conf); // Import Data Dictionary $miner->importDataDictionary($dataDictionary, $server_id); $data = array('name' => $name, 'url' => $server->url, 'type' => 'LISPMINER', 'method' => 'POST', 'params' => json_encode(array('miner_id' => $server_id, 'matrix' => $matrix_name)), 'dictionaryquery' => ''); $sources->save($data); $this->setRedirect("index.php?option={$this->com_kbi}&controller=sources"); $this->setMessage(JText::_('Server sucessfully registered.')); } catch (Exception $ex) { $app->enqueueMessage(JText::_('ERROR REGISTERING SERVER') . "<br />" . $ex->getMessage(), 'error'); // try to remove registered miner as it is in invalid state. if (isset($server_id) && isset($miner)) { try { $miner->unregister($server_id); } catch (Exception $innerException) { $app->enqueueMessage(JText::_('ERROR REMOVING REGISTERING SERVER') . "<br />" . $innerException->getMessage(), 'error'); } } } }