Added Add Node capability

This commit is contained in:
Deon George
2014-10-28 16:33:15 +11:00
parent 83a2c85a25
commit 80c8971a46
11 changed files with 218 additions and 7 deletions

View File

@@ -0,0 +1,4 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class Database_Query_Builder_Insert extends lnApp_Database_Query_Builder_Insert {}
?>

View File

@@ -27,6 +27,7 @@ abstract class ORM_TSM extends ORM {
protected $_formated = FALSE;
protected $_formats = array();
protected $_custom_cols = array();
protected $_tsm = array();
/**
@@ -55,10 +56,31 @@ abstract class ORM_TSM extends ORM {
// Get a substited column name - need for DB2/DSMADMC schema differences
if (isset($this->_tsm[$this->_db_group]['translate']) AND array_key_exists($column,$this->_tsm[$this->_db_group]['translate']))
return is_null($c=$this->_tsm[$this->_db_group]['translate'][$column]) ? NULL : parent::__get($c);
else
return parent::__get($column);
}
public function __set($column,$value) {
if (in_array($column,$this->_custom_cols)) {
// See if the data really changed
if (! isset($this->_object[$column]) OR $value !== $this->_object[$column]) {
$this->_table_columns[$column]['data_type'] = 'custom';
$this->_object[$column] = $value;
// Data has changed
$this->_changed[$column] = $column;
// Object is no longer saved or valid
$this->_saved = $this->_valid = FALSE;
}
} else
parent::__set($column,$value);
}
public function find() {
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
@@ -170,5 +192,12 @@ abstract class ORM_TSM extends ORM {
return array_key_exists($type,$x) ? $x[$type] : $x;
}
public function values(array $values,array $expected=NULL) {
foreach (array_intersect(array_keys($values),$this->_custom_cols) as $col)
$this->_table_columns[$col]['data_type'] = 'custom';
return parent::values($values,$expected);
}
}
?>

View File

@@ -0,0 +1,77 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class extends Kohana's [ORM] class to create defaults for TSM.
*
* @package TSM Database Module
* @category Query
* @author Deon George
* @copyright (c) 2010-2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class lnApp_Database_Query_Builder_Insert extends Kohana_Database_Query_Builder_Insert {
private $_commands = array(
'NODES'=>array(
'OPTION_SET'=>'CLOPTSET',
'DOMAIN_NAME'=>'DOMAIN',
),
);
public function compile($db = NULL) {
if ( ! is_object($db)) {
// Get the database instance
$db = Database::instance($db);
}
switch ($this->_table) {
case 'NODES':
$query = sprintf('REGISTER NODE %s %s %s',$this->pop_value('NODE_NAME'),$this->pop_value('PASSWORD'),$this->insert_values());
break;
default:
throw HTTP_Exception::factory(501,'Not setup for table :table',array(':table'=>$this->_table));
}
return $query;
}
private function get_keyalt($key) {
return isset($this->_commands[$this->_table][$key]) ? $this->_commands[$this->_table][$key] : $key;
}
private function get_key($key) {
return array_search($key,$this->_columns);
}
// @todo Values always go in as an array - should see if we can stop that
private function get_value($key) {
return (is_numeric($x=$this->get_key($key))) ? $this->_values[0][$x] : '';
}
private function insert_values() {
$result = '';
foreach ($this->_columns as $k=>$v) {
if ($result)
$result .= ' ';
$result .= sprintf('%s=\'%s\'',$this->get_keyalt($v),$this->get_value($v));
}
return $result;
}
private function pop_value($key) {
$result = NULL;
$x = $this->get_key($key);
$result = $this->get_value($key);
unset($this->_columns[$x]);
unset($this->_values[0][$x]);
return $result;
}
}
?>

View File

@@ -48,9 +48,6 @@ abstract class lnApp_Database_TSM extends Database {
public function set_charset($charset) {}
public function list_tables($like = NULL) {}
// Required methods
abstract protected function execute($sql);
/**
* Return the caching defined in the current configuration.
*
@@ -90,7 +87,7 @@ abstract class lnApp_Database_TSM extends Database {
if (isset($benchmark))
Profiler::delete($benchmark);
SystemMessage::TSM('error',sprintf('%s (%s)',$this->execute_stdout,$this->execute_stderr),$sql);
SystemMessage::TSM('danger',sprintf('%s (%s)',$this->execute_stdout,$this->execute_stderr),$sql);
}
if (isset($benchmark))
@@ -103,7 +100,7 @@ abstract class lnApp_Database_TSM extends Database {
// Return an iterator of results
return new Database_TSM_Result($result, $sql, $as_object, $params);
elseif ($type === Database::INSERT)
throw new Kohana_Exception('Database INSERTS are not supported');
return new Database_TSM_Result($result, $sql, $as_object, $params);
elseif ($type === Database::SHOW)
return new Database_TSM_Show($result, $sql, $as_object, $params);
elseif ($type === Database::SET)

View File

@@ -61,6 +61,13 @@ abstract class lnApp_Model_NODE extends ORM_TSM {
),
);
protected $_custom_cols = array(
'EMAILADDRESS',
'FORCEPWRESET',
'PASSWORD',
'USERID',
);
/**
* Get all the ACTIVITIY LOG for this NODE
*/
@@ -105,6 +112,7 @@ abstract class lnApp_Model_NODE extends ORM_TSM {
}
Log::instance()->add(LOG::DEBUG,'EXIT :method',array(':method'=>__METHOD__));
return $result;
}