From 453f97324f7710ad1f4d02d0428856c38a523df8 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 1 May 2016 21:36:37 +1000 Subject: [PATCH] Updated to KH 3.3.5 --- application/bootstrap.php | 32 +++++++++-- application/classes/ORM.php | 107 +++++++++++++++++++++++++++++------- application/config/url.php | 17 ++++++ includes/kohana | 2 +- 4 files changed, 132 insertions(+), 26 deletions(-) create mode 100644 application/config/url.php diff --git a/application/bootstrap.php b/application/bootstrap.php index e06af2f9..2b81d4e3 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -56,6 +56,13 @@ spl_autoload_register(array('Kohana', 'auto_load')); */ 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 ----------------------------------------- /** @@ -63,6 +70,12 @@ ini_set('unserialize_callback_func', 'spl_autoload_call'); */ 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. * @@ -73,7 +86,7 @@ I18n::lang('en-us'); /** * 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'])) { @@ -97,8 +110,10 @@ if (isset($_SERVER['KOHANA_ENV'])) */ Kohana::init(array( 'base_url' => '/', - 'caching' => TRUE, - 'index_file' => '', + 'caching' => Kohana::$environment === Kohana::PRODUCTION, + 'profile' => Kohana::$environment !== Kohana::PRODUCTION, + 'index_file' => FALSE, + 'cache_life' => 600, )); /** @@ -130,10 +145,19 @@ Kohana::modules(array( 'orm' => SMDPATH.'orm', // Object Relationship Mapping 'pagination' => SMDPATH.'pagination', // Kohana Pagination module for Kohana 3 PHP Framework // '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 )); +/** + * 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 */ diff --git a/application/classes/ORM.php b/application/classes/ORM.php index a9d12416..6e8d31e3 100644 --- a/application/classes/ORM.php +++ b/application/classes/ORM.php @@ -1,21 +1,38 @@ 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 * @see parent::__build() @@ -25,42 +42,36 @@ abstract class ORM extends lnApp_ORM { if (! in_array($this->_table_name,ORM::$no_site_id_tables)) $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); } /** * Function help to find records that are active */ - protected function _where_active() { + final protected function _where_active() { return $this->where('status','=',TRUE); } /** * 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') { if (is_null($o)) $o = $this; + if (is_null($ao)) $ao = Auth::instance()->get_user(); 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. * @@ -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() { - return $this->_where_active()->find_all(); + final public static function get_next_id($model,$field) { + 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(); } + // @todo This function shouldnt be here. public function where_authorised(Model_Account $ao=NULL,$aid='account_id') { if (is_null($ao)) $ao = Auth::instance()->get_user(); diff --git a/application/config/url.php b/application/config/url.php new file mode 100644 index 00000000..487dad39 --- /dev/null +++ b/application/config/url.php @@ -0,0 +1,17 @@ + array( + ), +); +?> diff --git a/includes/kohana b/includes/kohana index 5ffa3953..53873600 160000 --- a/includes/kohana +++ b/includes/kohana @@ -1 +1 @@ -Subproject commit 5ffa395307a3b26f901dde5f3064c48a15979f0d +Subproject commit 53873600c1b517628ed3a108c2d9316cf3be89b2