Minor improvements to blobs
This commit is contained in:
parent
6672913460
commit
407eed04c9
@ -46,21 +46,14 @@ class Model_Setup extends ORMOSB {
|
|||||||
if (! $mo->loaded())
|
if (! $mo->loaded())
|
||||||
throw new Kohana_Exception('Unknown module :name',array(':name'=>$key));
|
throw new Kohana_Exception('Unknown module :name',array(':name'=>$key));
|
||||||
|
|
||||||
static $mc = array();
|
|
||||||
|
|
||||||
if (! $mc)
|
|
||||||
$mc = $this->blob($this->module_config);
|
|
||||||
|
|
||||||
// If $value is NULL, we are a getter
|
// If $value is NULL, we are a getter
|
||||||
if ($value === NULL)
|
if ($value === NULL)
|
||||||
return empty($mc[$mo->id]) ? array() : $mc[$mo->id];
|
return empty($this->module_config[$mo->id]) ? array() : $this->module_config[$mo->id];
|
||||||
|
|
||||||
// Store new value
|
// Store new value
|
||||||
$mc[$mo->id] = $value;
|
$this->module_config[$mo->id] = $value;
|
||||||
$this->module_config = $this->blob($mc,TRUE);
|
|
||||||
$this->save();
|
|
||||||
|
|
||||||
return $this->saved();
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,17 +63,12 @@ class Model_Setup extends ORMOSB {
|
|||||||
* @param $value Values to store. If NULL, retrieves the value stored, otherwise stores value.
|
* @param $value Values to store. If NULL, retrieves the value stored, otherwise stores value.
|
||||||
*/
|
*/
|
||||||
public function site_details($key,array $value=NULL) {
|
public function site_details($key,array $value=NULL) {
|
||||||
static $sc = array();
|
|
||||||
|
|
||||||
if (! $sc AND $this->site_details)
|
|
||||||
$sc = $this->blob($this->site_details);
|
|
||||||
|
|
||||||
if (! in_array($key,array('name','address1','address2','city','state','pcode','phone','fax','email')))
|
if (! in_array($key,array('name','address1','address2','city','state','pcode','phone','fax','email')))
|
||||||
throw new Kohana_Exception('Unknown Site Configuration Key :key',array(':key'=>$key));
|
throw new Kohana_Exception('Unknown Site Configuration Key :key',array(':key'=>$key));
|
||||||
|
|
||||||
// If $value is NULL, we are a getter
|
// If $value is NULL, we are a getter
|
||||||
if ($value === NULL)
|
if ($value === NULL)
|
||||||
return empty($sc[$key]) ? '' : $sc[$key];
|
return empty($this->site_details[$key]) ? '' : $this->site_details[$key];
|
||||||
|
|
||||||
// Store new value
|
// Store new value
|
||||||
$sc[$key] = $value;
|
$sc[$key] = $value;
|
||||||
|
@ -104,6 +104,17 @@ abstract class ORMOSB extends ORM {
|
|||||||
$model->$field = serialize($value);
|
$model->$field = serialize($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function __get($column) {
|
||||||
|
// If the column is a blob, we'll decode it automatically
|
||||||
|
if (array_key_exists($column,$this->_object) AND $this->_table_columns[$column]['data_type'] == 'blob' AND (! isset($this->_table_columns[$column]['auto_convert']) OR ! $this->_table_columns[$column]['auto_convert'])) {
|
||||||
|
|
||||||
|
$this->_object[$column] = $this->blob($this->_object[$column]);
|
||||||
|
$this->_table_columns[$column]['auto_convert'] = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::__get($column);
|
||||||
|
}
|
||||||
|
|
||||||
public function save(Validation $validation = NULL) {
|
public function save(Validation $validation = NULL) {
|
||||||
// Find any fields that have changed, and that are blobs, and encode them.
|
// Find any fields that have changed, and that are blobs, and encode them.
|
||||||
if ($this->_changed)
|
if ($this->_changed)
|
||||||
@ -121,7 +132,7 @@ abstract class ORMOSB extends ORM {
|
|||||||
/**
|
/**
|
||||||
* Retrieve and Store DB BLOB data.
|
* Retrieve and Store DB BLOB data.
|
||||||
*/
|
*/
|
||||||
protected function blob($data,$set=FALSE) {
|
private function blob($data,$set=FALSE) {
|
||||||
return $set ? gzcompress(serialize($data)) : unserialize(gzuncompress($data));
|
return $set ? gzcompress(serialize($data)) : unserialize(gzuncompress($data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,6 @@ class Email_Template {
|
|||||||
|
|
||||||
if ($result) {
|
if ($result) {
|
||||||
// Store our email log.
|
// Store our email log.
|
||||||
$data = gzcompress(serialize($this->email_data['variables']));
|
|
||||||
$elo = ORM::factory('email_log');
|
$elo = ORM::factory('email_log');
|
||||||
|
|
||||||
foreach ($sa as $id) {
|
foreach ($sa as $id) {
|
||||||
@ -162,7 +161,7 @@ class Email_Template {
|
|||||||
$elo->account_id = $id;
|
$elo->account_id = $id;
|
||||||
$elo->email = implode(',',array_keys($this->to));
|
$elo->email = implode(',',array_keys($this->to));
|
||||||
$elo->email_template_translate_id = $this->etto->id;
|
$elo->email_template_translate_id = $this->etto->id;
|
||||||
$elo->data = $data;
|
$elo->data = $this->email_data['variables'];
|
||||||
$elo->save();
|
$elo->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
* @license http://dev.osbill.net/license.html
|
* @license http://dev.osbill.net/license.html
|
||||||
*/
|
*/
|
||||||
class Model_Email_Log extends ORMOSB {
|
class Model_Email_Log extends ORMOSB {
|
||||||
|
// Email Log doesnt use the update column
|
||||||
|
protected $_updated_column = FALSE;
|
||||||
|
|
||||||
protected $_belongs_to = array(
|
protected $_belongs_to = array(
|
||||||
'account'=>array('far_key'=>'id'),
|
'account'=>array('far_key'=>'id'),
|
||||||
'email_template_translate'=>array('far_key'=>'id'),
|
'email_template_translate'=>array('far_key'=>'id'),
|
||||||
@ -27,10 +30,10 @@ class Model_Email_Log extends ORMOSB {
|
|||||||
);
|
);
|
||||||
|
|
||||||
public function translate_resolve($column) {
|
public function translate_resolve($column) {
|
||||||
if (! $this->data OR ! ($r = $this->email_template_translate->variables($column)))
|
if (! $this->data OR ! ($this->email_template_translate->variables($column)))
|
||||||
return $this->email_template_translate->display($column);
|
return $this->email_template_translate->display($column);
|
||||||
else
|
else
|
||||||
return $this->email_template_translate->resolve(unserialize(gzuncompress($this->data)),$column);
|
return $this->email_template_translate->resolve($this->data,$column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -69,8 +69,8 @@ class Controller_User_Invoice extends Controller_TemplateDefault_User {
|
|||||||
/**
|
/**
|
||||||
* Download an invoice
|
* Download an invoice
|
||||||
*/
|
*/
|
||||||
public function action_download($id) {
|
public function action_download() {
|
||||||
$io = ORM::factory('invoice',$id);
|
$io = ORM::factory('invoice',$this->request->param('id'));
|
||||||
|
|
||||||
$this->response->body(Invoice::instance($io)->pdf()->Output(sprintf('%s.pdf',$io->refnum()),'D'));
|
$this->response->body(Invoice::instance($io)->pdf()->Output(sprintf('%s.pdf',$io->refnum()),'D'));
|
||||||
$this->response->headers(array('Content-Type' => 'application/pdf'));
|
$this->response->headers(array('Content-Type' => 'application/pdf'));
|
||||||
|
@ -21,33 +21,24 @@ class Controller_Task_Service extends Controller_Task {
|
|||||||
* List all services by their default checkout method
|
* List all services by their default checkout method
|
||||||
*/
|
*/
|
||||||
public function action_gettraffic() {
|
public function action_gettraffic() {
|
||||||
foreach ($this->_traffic_suppliers(TRUE) as $aso) {
|
foreach ($this->_traffic_suppliers(TRUE) as $aso)
|
||||||
$traffic = Service_Traffic_ADSL::instance($aso->name);
|
$traffic = Service_Traffic_ADSL::instance($aso->name)->update_traffic();
|
||||||
|
|
||||||
$traffic->update_traffic();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Charges for excess traffic usage
|
* Charges for excess traffic usage
|
||||||
*/
|
*/
|
||||||
public function action_chargetraffic() {
|
public function action_chargetraffic() {
|
||||||
foreach ($this->_traffic_suppliers(TRUE) as $aso) {
|
foreach ($this->_traffic_suppliers(TRUE) as $aso)
|
||||||
$traffic = Service_Traffic_ADSL::instance($aso->name);
|
$traffic = Service_Traffic_ADSL::instance($aso->name)->charge_excess_traffic();
|
||||||
|
|
||||||
$traffic->charge_excess_traffic();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send alerts to users when they exceed their traffic allowance
|
* Send alerts to users when they exceed their traffic allowance
|
||||||
*/
|
*/
|
||||||
public function action_alerttraffic() {
|
public function action_alerttraffic() {
|
||||||
foreach ($this->_traffic_suppliers(TRUE) as $aso) {
|
foreach ($this->_traffic_suppliers(TRUE) as $aso)
|
||||||
$traffic = Service_Traffic_ADSL::instance($aso->name);
|
$traffic = Service_Traffic_ADSL::instance($aso->name)->alert_traffic();
|
||||||
|
|
||||||
$traffic->alert_traffic();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
Reference in New Issue
Block a user