Updated to KH 3.3.5

This commit is contained in:
Deon George 2016-05-01 21:36:37 +10:00
parent 08bd2a2810
commit 453f97324f
4 changed files with 132 additions and 26 deletions

View File

@ -56,6 +56,13 @@ spl_autoload_register(array('Kohana', 'auto_load'));
*/ */
ini_set('unserialize_callback_func', 'spl_autoload_call'); ini_set('unserialize_callback_func', 'spl_autoload_call');
/**
* Set the mb_substitute_character to "none"
*
* @link http://www.php.net/manual/function.mb-substitute-character.php
*/
mb_substitute_character('none');
// -- Configuration and initialization ----------------------------------------- // -- Configuration and initialization -----------------------------------------
/** /**
@ -63,6 +70,12 @@ ini_set('unserialize_callback_func', 'spl_autoload_call');
*/ */
I18n::lang('en-us'); I18n::lang('en-us');
if (isset($_SERVER['SERVER_PROTOCOL']))
{
// Replace the default protocol.
HTTP::$protocol = $_SERVER['SERVER_PROTOCOL'];
}
/** /**
* Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied. * Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied.
* *
@ -73,7 +86,7 @@ I18n::lang('en-us');
/** /**
* Set the environment status by the domain. * Set the environment status by the domain.
*/ */
Kohana::$environment = (! isset($_SERVER['SERVER_NAME']) OR (in_array($_SERVER['SERVER_NAME'],$SERVER_NAMES))) ? Kohana::PRODUCTION : Kohana::DEVELOPMENT; Kohana::$environment = Kohana::PRODUCTION;
if (isset($_SERVER['KOHANA_ENV'])) if (isset($_SERVER['KOHANA_ENV']))
{ {
@ -97,8 +110,10 @@ if (isset($_SERVER['KOHANA_ENV']))
*/ */
Kohana::init(array( Kohana::init(array(
'base_url' => '/', 'base_url' => '/',
'caching' => TRUE, 'caching' => Kohana::$environment === Kohana::PRODUCTION,
'index_file' => '', 'profile' => Kohana::$environment !== Kohana::PRODUCTION,
'index_file' => FALSE,
'cache_life' => 600,
)); ));
/** /**
@ -130,10 +145,19 @@ Kohana::modules(array(
'orm' => SMDPATH.'orm', // Object Relationship Mapping 'orm' => SMDPATH.'orm', // Object Relationship Mapping
'pagination' => SMDPATH.'pagination', // Kohana Pagination module for Kohana 3 PHP Framework 'pagination' => SMDPATH.'pagination', // Kohana Pagination module for Kohana 3 PHP Framework
// 'unittest' => SMDPATH.'unittest', // Unit testing // 'unittest' => SMDPATH.'unittest', // Unit testing
// 'userguide' => SMDPATH.'userguide', // User guide and API documentation 'userguide' => SMDPATH.'userguide', // User guide and API documentation
'xml' => SMDPATH.'xml', // XML module for Kohana 3 PHP Framework 'xml' => SMDPATH.'xml', // XML module for Kohana 3 PHP Framework
)); ));
/**
* Cookie Salt
* @see http://kohanaframework.org/3.3/guide/kohana/cookies
*
* If you have not defined a cookie salt in your Cookie class then
* uncomment the line below and define a preferrably long salt.
*/
// Cookie::$salt = NULL;
/** /**
* Load our modules defined in the DB * Load our modules defined in the DB
*/ */

View File

@ -1,21 +1,38 @@
<?php defined('SYSPATH') or die('No direct access allowed.'); <?php defined('SYSPATH') or die('No direct access allowed.');
/** /**
* This class overrides Kohana's ORM * This class extends Kohana's [ORM] class to create defaults
* *
* This file contains enhancements for Kohana, that should be considered upstream and maybe havent been yet. * This file contains enhancements for Kohana, that should be considered upstream and maybe havent been yet.
* It also contains some functionality for OSB, which cannot be covered in ORM_OSB. * It also contains some functionality for OSB, which cannot be covered in ORM_OSB.
* *
* @package OSB * @package OSB
* @category Modifications * @category Helpers
* @author Deon George * @author Deon George
* @copyright (c) 2009-2013 Open Source Billing * @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html * @license http://dev.osbill.net/license.html
*/ */
abstract class ORM extends lnApp_ORM { abstract class ORM extends lnApp_ORM {
/**
* @var string Database to connect to
*/
protected $_db = 'default';
// Tables that do not have a site_id column // Tables that do not have a site_id column
public static $no_site_id_tables = array('setup','country','currency','language','tax'); public static $no_site_id_tables = array('setup','country','currency','language','tax');
// Rules to assist with site ID and getting next record ID for inserts.
public function rules() {
return array(
'id'=>array(
array('ORM::get_next_id',array(':model',':field')),
),
'site_id'=>array(
array('ORM::set_site_id',array(':model',':field')),
),
);
}
/** /**
* Add our OSB site_id to each SELECT query * Add our OSB site_id to each SELECT query
* @see parent::__build() * @see parent::__build()
@ -25,42 +42,36 @@ abstract class ORM extends lnApp_ORM {
if (! in_array($this->_table_name,ORM::$no_site_id_tables)) if (! in_array($this->_table_name,ORM::$no_site_id_tables))
$this->where($this->_object_name.'.site_id','=',Company::instance()->site()); $this->where($this->_object_name.'.site_id','=',Company::instance()->site());
// Ensure we Cache our queries
// @todo: Disabled as it is not working as expected
/*
$caching = FALSE;
foreach ($this->_db_pending as $method)
if ($method['name'] == 'cached') {
$caching = TRUE;
break;
}
if (! $caching)
$this->cached(Kohana::$config->load('cache.orm.'.$this->_table_name));
*/
return parent::_build($type); return parent::_build($type);
} }
/** /**
* Function help to find records that are active * Function help to find records that are active
*/ */
protected function _where_active() { final protected function _where_active() {
return $this->where('status','=',TRUE); return $this->where('status','=',TRUE);
} }
/** /**
* Determine if the account is authoised by the user * Determine if the account is authoised by the user
*/ */
// @todo This function shouldnt be here.
public function authorised(Model $o=NULL,Model_Account $ao=NULL,$aid='account_id') { public function authorised(Model $o=NULL,Model_Account $ao=NULL,$aid='account_id') {
if (is_null($o)) if (is_null($o))
$o = $this; $o = $this;
if (is_null($ao)) if (is_null($ao))
$ao = Auth::instance()->get_user(); $ao = Auth::instance()->get_user();
return in_array($o->{$aid},$ao->RTM->customers($ao->RTM)); return in_array($o->{$aid},$ao->RTM->customers($ao->RTM));
} }
public function config($key) {
$mc = Config::instance()->module_config($this->_object_name);
return empty($mc[$key]) ? '' : $mc[$key];
}
/** /**
* Override KH's ORM count_relations() function, to include our site_id in the query. * Override KH's ORM count_relations() function, to include our site_id in the query.
* *
@ -99,16 +110,70 @@ abstract class ORM extends lnApp_ORM {
} }
/** /**
* Function help to find records that are active * Get Next record id
*
* @param array Validate object
* @param string Primary Key
*/ */
public function list_active() { final public static function get_next_id($model,$field) {
return $this->_where_active()->find_all(); if (! is_null($model->$field))
return TRUE;
$model->_changed[$field] = $field;
$ido = ORM::factory('Module')
->where('name','=',$model->_table_name)
->find();
if (! $ido->loaded())
throw new Kohana_Exception('Problem getting record_id for :table',array(':table'=>$model->_table_name));
$model->$field = $ido->record_id->next_id($ido->id);
return TRUE;
} }
public function where_active() { public function keyget($column,$key=NULL) {
if (is_null($key) OR ! is_array($this->$column))
return $this->$column;
else
return array_key_exists($key,$this->$column) ? $this->{$column}[$key] : NULL;
}
/**
* Return the module record for this ORM object
*/
final public function mid() {
return ORM::factory('Module',array('name'=>$this->_table_name));
}
/**
* 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;
}
/**
* Function help to find records that are active
*/
final public function list_active($active=TRUE) {
$x=($active ? $this->_where_active() : $this);
return $x->find_all();
}
final public function where_active() {
return $this->_where_active(); return $this->_where_active();
} }
// @todo This function shouldnt be here.
public function where_authorised(Model_Account $ao=NULL,$aid='account_id') { public function where_authorised(Model_Account $ao=NULL,$aid='account_id') {
if (is_null($ao)) if (is_null($ao))
$ao = Auth::instance()->get_user(); $ao = Auth::instance()->get_user();

View File

@ -0,0 +1,17 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* OSB Configuration - Site URLs
*
* @package OSB
* @category Configuration
* @author Deon George
* @copyright (c) 2010-2016 Open Source Billing
* @license http://dev.leenooks.net/license.html
*/
return array(
'trusted_hosts' => array(
),
);
?>

@ -1 +1 @@
Subproject commit 5ffa395307a3b26f901dde5f3064c48a15979f0d Subproject commit 53873600c1b517628ed3a108c2d9316cf3be89b2