/xoops_trust_path/modules/coupons/include/onupdate.php
PHP | 89 lines | 65 code | 18 blank | 6 comment | 14 complexity | 590f99e919ef068599f73eb333d2d3a0 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
- <?php
-
- eval( ' function xoops_module_update_'.$mydirname.'( $module ) { return coupons_onupdate_base( $module , "'.$mydirname.'" ) ; } ' ) ;
-
-
- if( ! function_exists( 'coupons_onupdate_base' ) ) {
-
- function coupons_onupdate_base( $module , $mydirname )
- {
- // transations on module update
-
- global $msgs ; // TODO :-D
-
- // for Cube 2.1
- if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
- $root =& XCube_Root::getSingleton();
- $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'coupons_message_append_onupdate' ) ;
- $msgs = array() ;
- } else {
- if( ! is_array( $msgs ) ) $msgs = array() ;
- }
-
- $db =& Database::getInstance() ;
- $mid = $module->getVar('mid') ;
-
-
-
- //DB TABLES (write here ALTER TABLE etc. if necessary)
-
-
-
- // TEMPLATES (all templates have been already removed by modulesadmin)
- $tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
- $tpl_path = dirname(dirname(__FILE__)).'/templates' ;
- if( $handler = @opendir( $tpl_path . '/' ) ) {
- while( ( $file = readdir( $handler ) ) !== false ) {
- if( substr( $file , 0 , 1 ) == '.' ) continue ;
- $file_path = $tpl_path . '/' . $file ;
- if( is_file( $file_path ) && in_array( strrchr( $file , '.' ) , array( '.html' , '.css' , '.js' ) ) ) {
- $mtime = intval( @filemtime( $file_path ) ) ;
- $tplfile =& $tplfile_handler->create() ;
- $tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
- $tplfile->setVar( 'tpl_refid' , $mid ) ;
- $tplfile->setVar( 'tpl_tplset' , 'default' ) ;
- $tplfile->setVar( 'tpl_file' , $mydirname . '_' . $file ) ;
- $tplfile->setVar( 'tpl_desc' , '' , true ) ;
- $tplfile->setVar( 'tpl_module' , $mydirname ) ;
- $tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
- $tplfile->setVar( 'tpl_lastimported' , 0 ) ;
- $tplfile->setVar( 'tpl_type' , 'module' ) ;
- if( ! $tplfile_handler->insert( $tplfile ) ) {
- $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>';
- } else {
- $tplid = $tplfile->getVar( 'tpl_id' ) ;
- $msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)';
- // generate compiled file
- include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
- include_once XOOPS_ROOT_PATH.'/class/template.php' ;
- if( ! xoops_template_touch( $tplid ) ) {
- $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span>';
- } else {
- $msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span>';
- }
- }
- }
- }
- closedir( $handler ) ;
- }
- include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
- include_once XOOPS_ROOT_PATH.'/class/template.php' ;
- xoops_template_clear_module_cache( $mid ) ;
-
- return true ;
- }
-
- function coupons_message_append_onupdate( &$module_obj , &$log )
- {
- if( is_array( @$GLOBALS['msgs'] ) ) {
- foreach( $GLOBALS['msgs'] as $message ) {
- $log->add( strip_tags( $message ) ) ;
- }
- }
-
- // use mLog->addWarning() or mLog->addError() if necessary
- }
-
- }
-
- ?>