Application cleanup
This commit is contained in:
@@ -18,14 +18,14 @@ abstract class ORM_OSB extends ORM {
|
||||
protected $_created_column = array('column'=>'date_orig','format'=>TRUE);
|
||||
protected $_updated_column = array('column'=>'date_last','format'=>TRUE);
|
||||
|
||||
// Our attribute values that need to be stored as serialized
|
||||
protected $_serialize_column = array();
|
||||
// Our attributes used in forms.
|
||||
protected $_form = array();
|
||||
|
||||
// Our attributes that should be converted to NULL when empty
|
||||
protected $_nullifempty = array();
|
||||
|
||||
// Our attributes used in forms.
|
||||
protected $_form = array();
|
||||
// Our attribute values that need to be stored as serialized
|
||||
protected $_serialize_column = array();
|
||||
|
||||
// Rules to assist with site ID and getting next record ID for inserts.
|
||||
public function rules() {
|
||||
@@ -39,19 +39,6 @@ abstract class ORM_OSB extends ORM {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try and (un)serialize our data, and if it fails, just return it.
|
||||
*/
|
||||
private function _serialize($data,$set=FALSE) {
|
||||
try {
|
||||
return $set ? serialize($data) : unserialize($data);
|
||||
|
||||
// Maybe the data serialized?
|
||||
} catch (Exception $e) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve and Store DB BLOB data.
|
||||
*/
|
||||
@@ -65,6 +52,55 @@ abstract class ORM_OSB extends ORM {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto process some data as it comes from the database
|
||||
* @see parent::__get()
|
||||
*/
|
||||
public function __get($column) {
|
||||
if (array_key_exists($column,$this->_table_columns)) {
|
||||
// If the column is a blob, we'll decode it automatically
|
||||
if (
|
||||
$this->_table_columns[$column]['data_type'] == 'blob'
|
||||
AND ! is_null($this->_object[$column])
|
||||
AND ! isset($this->_changed[$column])
|
||||
AND (! isset($this->_table_columns[$column]['auto_convert']) OR ! $this->_table_columns[$column]['auto_convert'])
|
||||
) {
|
||||
|
||||
// In case our blob hasnt been saved as one.
|
||||
try {
|
||||
$this->_object[$column] = $this->_blob($this->_object[$column]);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
HTTP_Exception::factory(501,Kohana_Exception::text($e));
|
||||
}
|
||||
|
||||
$this->_table_columns[$column]['auto_convert'] = TRUE;
|
||||
}
|
||||
|
||||
// If the column is a serialized object, we'll unserialize it.
|
||||
if (
|
||||
in_array($column,$this->_serialize_column)
|
||||
AND is_string($this->_object[$column])
|
||||
AND ! is_null($this->_object[$column])
|
||||
AND ! isset($this->_changed[$column])
|
||||
AND (! isset($this->_table_columns[$column]['unserialized']) OR ! $this->_table_columns[$column]['unserialized'])
|
||||
) {
|
||||
|
||||
// In case our object hasnt been saved as serialized.
|
||||
try {
|
||||
$this->_object[$column] = unserialize($this->_object[$column]);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
HTTP_Exception::factory(501,Kohana_Exception::text($e));
|
||||
}
|
||||
|
||||
$this->_table_columns[$column]['unserialized'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::__get($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* If a column is marked to be nullified if it is empty, this is where it is done.
|
||||
*/
|
||||
@@ -86,82 +122,15 @@ abstract class ORM_OSB extends ORM {
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto process some data as it comes from the database
|
||||
* @see parent::__get()
|
||||
* Try and (un)serialize our data, and if it fails, just return it.
|
||||
*/
|
||||
public function __get($column) {
|
||||
if (array_key_exists($column,$this->_table_columns)) {
|
||||
// If the column is a blob, we'll decode it automatically
|
||||
if (
|
||||
$this->_table_columns[$column]['data_type'] == 'blob'
|
||||
AND ! is_null($this->_object[$column])
|
||||
AND ! isset($this->_changed[$column])
|
||||
AND (! isset($this->_table_columns[$column]['auto_convert']) OR ! $this->_table_columns[$column]['auto_convert'])
|
||||
) {
|
||||
private function _serialize($data,$set=FALSE) {
|
||||
try {
|
||||
return $set ? serialize($data) : unserialize($data);
|
||||
|
||||
// In case our blob hasnt been saved as one.
|
||||
try {
|
||||
$this->_object[$column] = $this->_blob($this->_object[$column]);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
// @todo Log this exception
|
||||
echo Kohana_Exception::text($e), "\n";
|
||||
echo debug_print_backtrace();
|
||||
}
|
||||
|
||||
$this->_table_columns[$column]['auto_convert'] = TRUE;
|
||||
}
|
||||
|
||||
// If the column is a serialized object, we'll unserialize it.
|
||||
if (
|
||||
in_array($column,$this->_serialize_column)
|
||||
AND is_string($this->_object[$column])
|
||||
AND ! is_null($this->_object[$column])
|
||||
AND ! isset($this->_changed[$column])
|
||||
AND (! isset($this->_table_columns[$column]['unserialized']) OR ! $this->_table_columns[$column]['unserialized'])
|
||||
) {
|
||||
|
||||
// In case our object hasnt been saved as serialized.
|
||||
try {
|
||||
$this->_object[$column] = unserialize($this->_object[$column]);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
// @todo Log this exception
|
||||
echo Kohana_Exception::text($e), "\n";
|
||||
echo debug_print_backtrace();
|
||||
}
|
||||
|
||||
$this->_table_columns[$column]['unserialized'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::__get($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will enhance the [Validate::filter], since it always passes
|
||||
* the value as the first argument and sometimes functions need that to not
|
||||
* be the first argument.
|
||||
*
|
||||
* Currently this implements:
|
||||
* [date()][date-ref]
|
||||
*
|
||||
* [date-ref]: http://www.php.net/date
|
||||
*
|
||||
* This function will throw an exception if called without a function
|
||||
* defined.
|
||||
*
|
||||
* @param mixed $val Value to be processed
|
||||
* @param string $func Name of function to call
|
||||
* @param string $arg Other arguments for the function
|
||||
* @todo This has probably changed in KH 3.1
|
||||
*/
|
||||
final public static function x_filters($val,$func,$arg) {
|
||||
switch ($func) {
|
||||
case 'date':
|
||||
return date($arg,$val);
|
||||
default:
|
||||
throw new Exception(sprintf(_('Unknown function: %s (%s,%s)'),$func,$arg,$val));
|
||||
// Maybe the data serialized?
|
||||
} catch (Exception $e) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,19 +164,6 @@ abstract class ORM_OSB extends ORM {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the site ID attribute for each row update
|
||||
*/
|
||||
final public static function set_site_id($model,$field) {
|
||||
if (! is_null($model->$field))
|
||||
return TRUE;
|
||||
|
||||
$model->_changed[$field] = $field;
|
||||
$model->$field = Company::instance()->site();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function keyget($column,$key=NULL) {
|
||||
if (is_null($key) OR ! is_array($this->$column))
|
||||
return $this->$column;
|
||||
@@ -249,6 +205,19 @@ abstract class ORM_OSB extends ORM {
|
||||
return parent::save($validation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the site ID attribute for each row update
|
||||
*/
|
||||
final public static function set_site_id($model,$field) {
|
||||
if (! is_null($model->$field))
|
||||
return TRUE;
|
||||
|
||||
$model->_changed[$field] = $field;
|
||||
$model->$field = Company::instance()->site();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function status($render=FALSE) {
|
||||
if (! isset($this->_table_columns['status']))
|
||||
return NULL;
|
||||
|
Reference in New Issue
Block a user