2008-11-13 10:38:28 +00:00
<? php defined ( "SYSPATH" ) or die ( "No direct script access." );
/**
* Gallery - a web based photo album viewer and editor
2010-03-03 10:15:34 -08:00
* Copyright (C) 2000-2010 Bharat Mediratta
2008-11-13 10:38:28 +00:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
/**
* This is the API for handling modules.
*
* Note: by design, this class does not do any permission checking.
*/
2008-11-22 06:01:08 +00:00
class module_Core {
2009-05-26 05:28:59 +00:00
public static $active = array ();
2009-01-19 05:16:55 +00:00
public static $modules = array ();
2009-05-14 03:56:29 +00:00
public static $var_cache = null ;
2009-06-09 20:32:37 -07:00
public static $available = array ();
2008-12-12 07:42:26 +00:00
2008-12-21 21:52:49 +00:00
/**
* Set the version of the corresponding Module_Model
* @param string $module_name
* @param integer $version
*/
2009-01-14 04:12:02 +00:00
static function set_version ( $module_name , $version ) {
2010-11-28 11:27:25 -08:00
$module = module :: get ( $module_name );
2009-11-25 13:22:24 -08:00
if ( ! $module -> loaded ()) {
2008-11-13 10:38:28 +00:00
$module -> name = $module_name ;
2009-05-27 16:15:00 -07:00
$module -> active = $module_name == "gallery" ; // only gallery is active by default
2008-11-13 10:38:28 +00:00
}
2009-06-09 21:26:28 -07:00
$module -> version = $version ;
2008-11-13 10:38:28 +00:00
$module -> save ();
2009-11-25 13:22:24 -08:00
Kohana_Log :: add ( "debug" , " $module_name : version is now $version " );
2008-11-13 10:38:28 +00:00
}
2008-12-21 21:52:49 +00:00
/**
* Load the corresponding Module_Model
* @param string $module_name
*/
2009-01-14 04:12:02 +00:00
static function get ( $module_name ) {
2009-10-18 09:23:59 -07:00
if ( empty ( self :: $modules [ $module_name ])) {
2009-12-22 13:32:02 -08:00
return ORM :: factory ( "module" ) -> where ( "name" , "=" , $module_name ) -> find ();
2009-10-18 09:23:59 -07:00
}
return self :: $modules [ $module_name ];
}
/**
* Get the information about a module
* @returns ArrayObject containing the module information from the module.info file or false if
* not found
*/
static function info ( $module_name ) {
2010-11-28 11:27:25 -08:00
$module_list = module :: available ();
2009-10-18 09:23:59 -07:00
return isset ( $module_list -> $module_name ) ? $module_list -> $module_name : false ;
2008-11-13 10:38:28 +00:00
}
2008-11-27 09:45:26 +00:00
2008-12-21 21:52:49 +00:00
/**
* Check to see if a module is installed
* @param string $module_name
*/
2009-01-14 04:12:02 +00:00
static function is_installed ( $module_name ) {
2009-05-26 05:28:59 +00:00
return array_key_exists ( $module_name , self :: $modules );
2008-11-18 16:26:36 +00:00
}
2008-11-21 20:13:28 +00:00
2008-12-21 21:52:49 +00:00
/**
2009-05-26 05:28:59 +00:00
* Check to see if a module is active
* @param string $module_name
2008-12-21 21:52:49 +00:00
*/
2009-05-26 05:28:59 +00:00
static function is_active ( $module_name ) {
return array_key_exists ( $module_name , self :: $modules ) &&
self :: $modules [ $module_name ] -> active ;
2008-11-21 20:13:28 +00:00
}
2008-11-28 19:37:01 +00:00
2008-12-21 21:52:49 +00:00
/**
2009-05-26 05:28:59 +00:00
* Return the list of available modules, including uninstalled modules.
2008-12-21 21:52:49 +00:00
*/
2009-01-14 04:12:02 +00:00
static function available () {
2009-06-09 20:32:37 -07:00
if ( empty ( self :: $available )) {
$modules = new ArrayObject ( array (), ArrayObject :: ARRAY_AS_PROPS );
2009-10-04 10:04:35 -07:00
foreach ( glob ( MODPATH . "*/module.info" ) as $file ) {
$module_name = basename ( dirname ( $file ));
2009-10-18 09:23:59 -07:00
$modules -> $module_name =
new ArrayObject ( parse_ini_file ( $file ), ArrayObject :: ARRAY_AS_PROPS );
2009-10-04 10:04:35 -07:00
$m =& $modules -> $module_name ;
2010-11-28 11:27:25 -08:00
$m -> installed = module :: is_installed ( $module_name );
$m -> active = module :: is_active ( $module_name );
2009-10-04 10:04:35 -07:00
$m -> code_version = $m -> version ;
2010-11-28 11:27:25 -08:00
$m -> version = module :: get_version ( $module_name );
2010-01-24 15:40:56 -08:00
$m -> locked = false ;
2010-09-08 20:59:40 -07:00
if ( $m -> active && $m -> version != $m -> code_version ) {
site_status :: warning ( t ( "Some of your modules are out of date. <a href= \" %upgrader_url \" >Upgrade now!</a>" , array ( "upgrader_url" => url :: site ( "upgrader" ))), "upgrade_now" );
}
2009-06-09 20:32:37 -07:00
}
2008-11-28 21:22:34 +00:00
2009-06-09 20:32:37 -07:00
// Lock certain modules
$modules -> gallery -> locked = true ;
2010-11-28 11:27:25 -08:00
$identity_module = module :: get_var ( "gallery" , "identity_provider" , "user" );
2009-10-17 10:36:50 -07:00
$modules -> $identity_module -> locked = true ;
2009-06-09 20:32:37 -07:00
$modules -> ksort ();
self :: $available = $modules ;
}
2008-12-22 04:31:04 +00:00
2009-06-09 20:32:37 -07:00
return self :: $available ;
2008-11-28 21:22:34 +00:00
}
2008-12-21 21:52:49 +00:00
/**
2009-05-26 05:28:59 +00:00
* Return a list of all the active modules in no particular order.
2008-12-21 21:52:49 +00:00
*/
2009-05-26 05:28:59 +00:00
static function active () {
return self :: $active ;
2009-05-26 06:01:04 +00:00
}
2009-05-26 05:28:59 +00:00
2010-01-21 12:57:45 -08:00
/**
2010-01-22 12:30:17 -08:00
* Check that the module can be activated. (i.e. all the prerequistes exist)
2010-01-21 12:57:45 -08:00
* @param string $module_name
2010-01-21 20:33:26 -08:00
* @return array an array of warning or error messages to be displayed
2010-01-21 12:57:45 -08:00
*/
2010-01-22 12:30:17 -08:00
static function can_activate ( $module_name ) {
2010-01-21 12:57:45 -08:00
module :: _add_to_path ( $module_name );
$messages = array ();
$installer_class = " { $module_name } _installer" ;
2010-01-22 12:30:17 -08:00
if ( method_exists ( $installer_class , "can_activate" )) {
$messages = call_user_func ( array ( $installer_class , "can_activate" ));
2010-01-21 12:57:45 -08:00
}
2010-01-21 20:33:26 -08:00
// Remove it from the active path
2010-01-21 12:57:45 -08:00
module :: _remove_from_path ( $module_name );
return $messages ;
}
/**
2010-09-07 22:13:30 -07:00
* Allow modules to indicate the impact of deactivating the specified module
2010-01-21 12:57:45 -08:00
* @param string $module_name
2010-01-21 20:33:26 -08:00
* @return array an array of warning or error messages to be displayed
2010-01-21 12:57:45 -08:00
*/
static function can_deactivate ( $module_name ) {
$data = ( object ) array ( "module" => $module_name , "messages" => array ());
module :: event ( "pre_deactivate" , $data );
return $data -> messages ;
}
2009-05-26 05:28:59 +00:00
/**
* Install a module. This will call <module>_installer::install(), which is responsible for
2009-06-23 12:00:49 -07:00
* creating database tables, setting module variables and calling module::set_version().
2009-05-26 05:28:59 +00:00
* Note that after installing, the module must be activated before it is available for use.
* @param string $module_name
*/
static function install ( $module_name ) {
2010-01-21 12:57:45 -08:00
module :: _add_to_path ( $module_name );
2008-12-12 08:41:48 +00:00
2009-05-26 05:28:59 +00:00
$installer_class = " { $module_name } _installer" ;
2008-12-12 08:41:48 +00:00
if ( method_exists ( $installer_class , "install" )) {
call_user_func_array ( array ( $installer_class , "install" ), array ());
2009-09-05 13:39:30 -07:00
} else {
module :: set_version ( $module_name , 1 );
2008-12-12 08:41:48 +00:00
}
2010-08-06 10:41:38 -07:00
// Set the weight of the new module, which controls the order in which the modules are
// loaded. By default, new modules are installed at the end of the priority list. Since the
// id field is monotonically increasing, the easiest way to guarantee that is to set the weight
// the same as the id. We don't know that until we save it for the first time
$module = ORM :: factory ( "module" ) -> where ( "name" , "=" , $module_name ) -> find ();
if ( $module -> loaded ()) {
$module -> weight = $module -> id ;
$module -> save ();
}
2009-05-28 21:18:46 -07:00
module :: load_modules ();
2008-12-12 08:41:48 +00:00
2009-05-26 05:28:59 +00:00
// Now the module is installed but inactive, so don't leave it in the active path
2010-01-21 12:57:45 -08:00
module :: _remove_from_path ( $module_name );
2009-05-26 05:28:59 +00:00
2009-04-12 06:41:43 +00:00
log :: success (
"module" , t ( "Installed module %module_name" , array ( "module_name" => $module_name )));
2008-12-12 08:41:48 +00:00
}
2010-01-21 12:57:45 -08:00
private static function _add_to_path ( $module_name ) {
$config = Kohana_Config :: instance ();
$kohana_modules = $config -> get ( "core.modules" );
array_unshift ( $kohana_modules , MODPATH . $module_name );
$config -> set ( "core.modules" , $kohana_modules );
// Rebuild the include path so the module installer can benefit from auto loading
Kohana :: include_paths ( true );
}
private static function _remove_from_path ( $module_name ) {
$config = Kohana_Config :: instance ();
$kohana_modules = $config -> get ( "core.modules" );
if (( $key = array_search ( MODPATH . $module_name , $kohana_modules )) !== false ) {
unset ( $kohana_modules [ $key ]);
$kohana_modules = array_values ( $kohana_modules ); // reindex
}
$config -> set ( "core.modules" , $kohana_modules );
Kohana :: include_paths ( true );
}
2009-06-23 12:00:49 -07:00
/**
* Upgrade a module. This will call <module>_installer::upgrade(), which is responsible for
* modifying database tables, changing module variables and calling module::set_version().
* Note that after upgrading, the module must be activated before it is available for use.
* @param string $module_name
*/
static function upgrade ( $module_name ) {
$version_before = module :: get_version ( $module_name );
$installer_class = " { $module_name } _installer" ;
2010-09-08 20:36:22 -07:00
$available = module :: available ();
2009-06-23 12:00:49 -07:00
if ( method_exists ( $installer_class , "upgrade" )) {
call_user_func_array ( array ( $installer_class , "upgrade" ), array ( $version_before ));
2009-09-05 13:39:30 -07:00
} else {
if ( isset ( $available -> $module_name -> code_version )) {
module :: set_version ( $module_name , $available -> $module_name -> code_version );
} else {
throw new Exception ( "@todo UNKNOWN_MODULE" );
}
2009-06-23 12:00:49 -07:00
}
2009-10-26 09:35:41 -07:00
module :: load_modules ();
2009-06-23 12:00:49 -07:00
$version_after = module :: get_version ( $module_name );
if ( $version_before != $version_after ) {
log :: success (
"module" , t ( "Upgraded module %module_name from %version_before to %version_after" ,
array ( "module_name" => $module_name ,
"version_before" => $version_before ,
"version_after" => $version_after )));
}
2010-09-08 20:36:22 -07:00
if ( $version_after != $available -> $module_name -> code_version ) {
throw new Exception ( "@todo MODULE_FAILED_TO_UPGRADE" );
}
2009-06-23 12:00:49 -07:00
}
2008-12-21 21:52:49 +00:00
/**
2009-05-26 05:28:59 +00:00
* Activate an installed module. This will call <module>_installer::activate() which should take
* any steps to make sure that the module is ready for use. This will also activate any
* existing graphics rules for this module.
* @param string $module_name
*/
static function activate ( $module_name ) {
2010-01-21 12:57:45 -08:00
module :: _add_to_path ( $module_name );
2009-05-26 05:28:59 +00:00
$installer_class = " { $module_name } _installer" ;
if ( method_exists ( $installer_class , "activate" )) {
call_user_func_array ( array ( $installer_class , "activate" ), array ());
}
2010-11-28 11:27:25 -08:00
$module = module :: get ( $module_name );
2009-11-25 13:22:24 -08:00
if ( $module -> loaded ()) {
2009-05-26 05:28:59 +00:00
$module -> active = true ;
$module -> save ();
}
2009-05-28 21:18:46 -07:00
module :: load_modules ();
2009-05-26 05:28:59 +00:00
graphics :: activate_rules ( $module_name );
2009-09-30 17:30:01 -07:00
2009-11-12 09:29:17 -08:00
block_manager :: activate_blocks ( $module_name );
2009-09-30 17:30:01 -07:00
2009-05-26 05:28:59 +00:00
log :: success (
"module" , t ( "Activated module %module_name" , array ( "module_name" => $module_name )));
}
/**
2009-05-28 17:46:17 -07:00
* Deactivate an installed module. This will call <module>_installer::deactivate() which should
* take any cleanup steps to make sure that the module isn't visible in any way. Note that the
* module remains available in Kohana's cascading file system until the end of the request!
2009-05-26 05:28:59 +00:00
* @param string $module_name
*/
static function deactivate ( $module_name ) {
$installer_class = " { $module_name } _installer" ;
if ( method_exists ( $installer_class , "deactivate" )) {
call_user_func_array ( array ( $installer_class , "deactivate" ), array ());
}
2009-01-09 18:33:48 +00:00
2010-11-28 11:27:25 -08:00
$module = module :: get ( $module_name );
2009-11-25 13:22:24 -08:00
if ( $module -> loaded ()) {
2009-05-26 05:28:59 +00:00
$module -> active = false ;
$module -> save ();
}
2009-05-28 21:18:46 -07:00
module :: load_modules ();
2009-05-26 05:28:59 +00:00
graphics :: deactivate_rules ( $module_name );
2009-09-30 17:30:01 -07:00
2009-11-12 09:29:17 -08:00
block_manager :: deactivate_blocks ( $module_name );
2009-09-30 17:30:01 -07:00
2009-05-26 05:28:59 +00:00
log :: success (
"module" , t ( "Deactivated module %module_name" , array ( "module_name" => $module_name )));
}
/**
* Uninstall a deactivated module. This will call <module>_installer::uninstall() which should
* take whatever steps necessary to make sure that all traces of a module are gone.
* @param string $module_name
2008-12-21 21:52:49 +00:00
*/
2009-01-14 04:12:02 +00:00
static function uninstall ( $module_name ) {
2008-12-12 08:41:48 +00:00
$installer_class = " { $module_name } _installer" ;
2009-05-26 05:28:59 +00:00
if ( method_exists ( $installer_class , "uninstall" )) {
2009-05-26 06:01:04 +00:00
call_user_func ( array ( $installer_class , "uninstall" ));
2009-05-26 05:28:59 +00:00
}
2009-10-22 17:05:00 -07:00
graphics :: remove_rules ( $module_name );
2010-11-28 11:27:25 -08:00
$module = module :: get ( $module_name );
2009-11-25 13:22:24 -08:00
if ( $module -> loaded ()) {
2009-05-26 05:28:59 +00:00
$module -> delete ();
}
2009-05-28 21:18:46 -07:00
module :: load_modules ();
2009-05-26 05:28:59 +00:00
// We could delete the module vars here too, but it's nice to leave them around
// in case the module gets reinstalled.
2009-04-12 06:41:43 +00:00
log :: success (
"module" , t ( "Uninstalled module %module_name" , array ( "module_name" => $module_name )));
2008-12-12 08:41:48 +00:00
}
2008-12-21 21:52:49 +00:00
/**
* Load the active modules. This is called at bootstrap time.
*/
2009-01-14 04:12:02 +00:00
static function load_modules () {
2009-05-26 05:28:59 +00:00
self :: $modules = array ();
self :: $active = array ();
2009-05-28 17:46:17 -07:00
$kohana_modules = array ();
2010-08-06 10:41:38 -07:00
// In version 32 we introduced a weight column so we can specify the module order
// If we try to use that blindly, we'll break earlier versions before they can even
// run the upgrader.
$modules = module :: get_version ( "gallery" ) < 32 ?
ORM :: factory ( "module" ) -> find_all () :
ORM :: factory ( "module" ) -> order_by ( "weight" ) -> find_all ();
foreach ( $modules as $module ) {
2009-03-16 08:05:07 +00:00
self :: $modules [ $module -> name ] = $module ;
2009-05-28 21:00:06 -07:00
if ( ! $module -> active ) {
continue ;
}
if ( $module -> name == "gallery" ) {
$gallery = $module ;
} else {
2009-05-26 05:28:59 +00:00
self :: $active [] = $module ;
2009-10-04 10:04:35 -07:00
$kohana_modules [] = MODPATH . $module -> name ;
2009-05-26 05:28:59 +00:00
}
2008-12-04 07:44:28 +00:00
}
2009-05-28 21:00:06 -07:00
self :: $active [] = $gallery ; // put gallery last in the module list to match core.modules
2009-11-25 13:22:24 -08:00
$config = Kohana_Config :: instance ();
$config -> set (
"core.modules" , array_merge ( $kohana_modules , $config -> get ( "core.modules" )));
2008-11-28 21:22:34 +00:00
}
2008-12-10 19:44:58 +00:00
2008-12-21 21:52:49 +00:00
/**
* Run a specific event on all active modules.
* @param string $name the event name
* @param mixed $data data to pass to each event handler
*/
2009-05-17 04:37:00 +00:00
static function event ( $name , & $data = null ) {
$args = func_get_args ();
array_shift ( $args );
2009-05-16 16:46:08 +00:00
$function = str_replace ( "." , "_" , $name );
2009-09-29 08:50:53 -07:00
if ( method_exists ( "gallery_event" , $function )) {
switch ( count ( $args )) {
case 0 :
gallery_event :: $function ();
break ;
case 1 :
gallery_event :: $function ( $args [ 0 ]);
break ;
case 2 :
gallery_event :: $function ( $args [ 0 ], $args [ 1 ]);
break ;
2009-09-29 09:10:41 -07:00
case 3 :
gallery_event :: $function ( $args [ 0 ], $args [ 1 ], $args [ 2 ]);
break ;
case 4 : // Context menu events have 4 arguments so lets optimize them
gallery_event :: $function ( $args [ 0 ], $args [ 1 ], $args [ 2 ], $args [ 3 ]);
break ;
2009-09-29 08:50:53 -07:00
default :
call_user_func_array ( array ( "gallery_event" , $function ), $args );
}
}
2009-08-03 21:45:54 -07:00
foreach ( self :: $active as $module ) {
2009-09-29 08:50:53 -07:00
if ( $module -> name == "gallery" ) {
continue ;
}
2008-12-21 21:52:49 +00:00
$class = " { $module -> name } _event" ;
if ( method_exists ( $class , $function )) {
2009-01-08 02:46:09 +00:00
call_user_func_array ( array ( $class , $function ), $args );
2008-12-21 21:52:49 +00:00
}
}
2009-11-28 23:25:07 -08:00
// Give the admin theme a chance to respond, if we're in admin mode.
if ( theme :: $is_admin ) {
$class = theme :: $admin_theme_name . "_event" ;
if ( method_exists ( $class , $function )) {
call_user_func_array ( array ( $class , $function ), $args );
}
}
// Give the site theme a chance to respond as well. It gets a chance even in admin mode, as
// long as the theme has an admin subdir.
$class = theme :: $site_theme_name . "_event" ;
if ( method_exists ( $class , $function )) {
call_user_func_array ( array ( $class , $function ), $args );
}
2008-12-21 21:52:49 +00:00
}
/**
* Get a variable from this module
* @param string $module_name
* @param string $name
* @param string $default_value
* @return the value
*/
2009-01-14 04:12:02 +00:00
static function get_var ( $module_name , $name , $default_value = null ) {
2010-09-29 20:47:43 -07:00
// We cache vars so we can load them all at once for performance.
2009-05-14 03:56:29 +00:00
if ( empty ( self :: $var_cache )) {
2010-09-29 20:47:43 -07:00
self :: $var_cache = Cache :: instance () -> get ( "var_cache" );
if ( empty ( self :: $var_cache )) {
// Cache doesn't exist, create it now.
2009-11-29 02:48:42 -08:00
foreach ( db :: build ()
2009-05-14 03:56:29 +00:00
-> select ( "module_name" , "name" , "value" )
-> from ( "vars" )
2009-11-29 02:48:42 -08:00
-> order_by ( "module_name" )
-> order_by ( "name" )
-> execute () as $row ) {
2010-01-31 16:07:41 -08:00
// Mute the "Creating default object from empty value" warning below
@ self :: $var_cache -> { $row -> module_name } -> { $row -> name } = $row -> value ;
2009-05-14 03:56:29 +00:00
}
2010-09-29 20:47:43 -07:00
Cache :: instance () -> set ( "var_cache" , self :: $var_cache , array ( "vars" ));
2009-05-14 03:56:29 +00:00
}
2009-03-07 04:44:16 +00:00
}
2009-05-14 03:56:29 +00:00
if ( isset ( self :: $var_cache -> $module_name -> $name )) {
return self :: $var_cache -> $module_name -> $name ;
} else {
return $default_value ;
}
2008-12-10 19:44:58 +00:00
}
2008-12-21 21:52:49 +00:00
/**
* Store a variable for this module
* @param string $module_name
* @param string $name
* @param string $value
*/
2009-01-14 04:12:02 +00:00
static function set_var ( $module_name , $name , $value ) {
2008-12-11 16:06:22 +00:00
$var = ORM :: factory ( "var" )
2009-11-26 12:09:04 -08:00
-> where ( "module_name" , "=" , $module_name )
-> where ( "name" , "=" , $name )
2008-12-10 19:44:58 +00:00
-> find ();
2009-11-25 13:22:24 -08:00
if ( ! $var -> loaded ()) {
2008-12-23 04:14:07 +00:00
$var -> module_name = $module_name ;
2008-12-11 16:06:22 +00:00
$var -> name = $name ;
2008-12-10 19:44:58 +00:00
}
2008-12-11 16:06:22 +00:00
$var -> value = $value ;
2009-03-16 08:05:07 +00:00
$var -> save ();
2009-05-14 03:56:29 +00:00
2010-09-29 20:47:43 -07:00
Cache :: instance () -> delete ( "var_cache" );
2009-05-14 03:56:29 +00:00
self :: $var_cache = null ;
2009-03-11 00:27:17 +00:00
}
2008-12-26 01:29:33 +00:00
/**
2009-01-08 02:46:09 +00:00
* Increment the value of a variable for this module
2009-12-17 21:16:51 -08:00
*
* Note: Frequently updating counters is very inefficient because it invalidates the cache value
* which has to be rebuilt every time we make a change.
*
* @todo Get rid of this and find an alternate approach for all callers (currently only Akismet)
*
* @deprecated
2009-01-08 02:46:09 +00:00
* @param string $module_name
* @param string $name
* @param string $increment (optional, default is 1)
*/
2009-01-14 04:12:02 +00:00
static function incr_var ( $module_name , $name , $increment = 1 ) {
2009-12-17 21:16:51 -08:00
db :: build ()
-> update ( "vars" )
2010-12-28 23:10:05 -08:00
-> set ( "value" , db :: expr ( "`value` + $increment " ))
2009-12-17 21:16:51 -08:00
-> where ( "module_name" , "=" , $module_name )
-> where ( "name" , "=" , $name )
-> execute ();
2009-05-14 03:56:29 +00:00
2010-09-29 20:47:43 -07:00
Cache :: instance () -> delete ( "var_cache" );
2009-05-14 03:56:29 +00:00
self :: $var_cache = null ;
2009-01-08 02:46:09 +00:00
}
/**
2008-12-26 01:29:33 +00:00
* Remove a variable for this module.
* @param string $module_name
* @param string $name
*/
2009-01-14 04:12:02 +00:00
static function clear_var ( $module_name , $name ) {
2010-11-08 11:45:14 -08:00
db :: build ()
-> delete ( "vars" )
2009-11-26 12:09:04 -08:00
-> where ( "module_name" , "=" , $module_name )
-> where ( "name" , "=" , $name )
2010-11-08 11:45:14 -08:00
-> execute ();
Cache :: instance () -> delete ( "var_cache" );
self :: $var_cache = null ;
}
/**
* Remove all variables for this module.
* @param string $module_name
*/
static function clear_all_vars ( $module_name ) {
db :: build ()
-> delete ( "vars" )
-> where ( "module_name" , "=" , $module_name )
-> execute ();
2009-05-14 03:56:29 +00:00
2010-09-29 20:47:43 -07:00
Cache :: instance () -> delete ( "var_cache" );
2009-05-14 03:56:29 +00:00
self :: $var_cache = null ;
2008-12-26 01:29:33 +00:00
}
2009-05-26 05:28:59 +00:00
/**
* Return the version of the installed module.
* @param string $module_name
*/
static function get_version ( $module_name ) {
2010-11-28 11:27:25 -08:00
return module :: get ( $module_name ) -> version ;
2009-05-26 05:28:59 +00:00
}
2008-11-13 10:38:28 +00:00
}