XPressME Integration Kit

Trac

source: trunk/include/onuninstall.php @ 188

Last change on this file since 188 was 188, checked in by toemon, 15 years ago

#111 XPressMEモジュールをアンインストールしても、プラグインが作成したデータベーステーブルが残ってしまうバグ修正
xoops_version.php から $modversiontables?の記述を外し
onuninstall でdb_prefixからテーブルを見つけてDROPするようにした。
またxoops_version.php から $modversiontables?の記述を外したことにより、wordpressのテーブル構成が変わっても気にしないですむようになった。
但しXOOPSのモジュールインフォメーションにはSQLテーブルの情報がでない

File size: 2.7 KB
Line 
1<?php
2$mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
3
4eval( ' function xoops_module_uninstall_'.$mydirname.'( $module ) { return xpress_onuninstall_base( $module , "'.$mydirname.'" ) ; } ' ) ;
5
6
7if( ! function_exists( 'xpress_onuninstall_base' ) ) {
8
9function xpress_onuninstall_base( $module , $mydirname )
10{
11        // transations on module uninstall
12
13        global $ret ; // TODO :-D
14
15        // for Cube 2.1
16        if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
17                $root =& XCube_Root::getSingleton();
18                $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleUninstall.' . ucfirst($mydirname) . '.Success' , 'xpress_message_append_onuninstall' ) ;
19                $ret = array() ;
20        } else {
21                if( ! is_array( $ret ) ) $ret = array() ;
22        }
23
24        $db =& Database::getInstance() ;
25        $mid = $module->getVar('mid') ;
26       
27        $xp_prefix = $mydirname;
28        if ($xp_prefix == 'wordpress'){
29                $xp_prefix = 'wp';
30        }
31       
32        $xoops_prefix = $db->prefix();
33
34        if (empty($xoops_prefix) || empty($xp_prefix)) {
35                $ret[] = '<span style="color:#ff0000;">ERROR: Empty Prefix.</span><br />';
36                return false;
37        }
38       
39        $prefix_mod = $xoops_prefix  . '_' . $xp_prefix;
40        $sql = "SHOW TABLES LIKE '$prefix_mod%'";
41        if ($result = $db->query($sql)) {
42                while ($table = $db->fetchRow($result)){
43                        $drop_sql = 'DROP TABLE '. $table[0] ;
44                        if (!$db->queryF($drop_sql)) {
45                                $ret[] = '<span style="color:#ff0000;">ERROR: Could not drop table <b>'.htmlspecialchars($table[0]).'<b>.</span><br />';
46                        } else {
47                                $ret[] = 'Table <b>'.htmlspecialchars($table[0]).'</b> dropped.<br />';
48                        }
49                }
50        } else {
51                $ret[] = '<span style="color:#ff0000;">ERROR: Table not found of prefix <b>'.htmlspecialchars($prefix_mod).'<b> .</span><br />';
52                return false;
53        }
54
55
56        // TEMPLATES (Not necessary because modulesadmin removes all templates)
57        /* $tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
58        $templates =& $tplfile_handler->find( null , 'module' , $mid ) ;
59        $tcount = count( $templates ) ;
60        if( $tcount > 0 ) {
61                $ret[] = 'Deleting templates...' ;
62                for( $i = 0 ; $i < $tcount ; $i ++ ) {
63                        if( ! $tplfile_handler->delete( $templates[$i] ) ) {
64                                $ret[] = '<span style="color:#ff0000;">ERROR: Could not delete template '.$templates[$i]->getVar('tpl_file','s').' from the database. Template ID: <b>'.$templates[$i]->getVar('tpl_id','s').'</b></span><br />';
65                        } else {
66                                $ret[] = 'Template <b>'.$templates[$i]->getVar('tpl_file','s').'</b> deleted from the database. Template ID: <b>'.$templates[$i]->getVar('tpl_id','s').'</b><br />';
67                        }
68                }
69        }
70        unset($templates); */
71
72
73        return true ;
74}
75
76function xpress_message_append_onuninstall( &$module_obj , &$log )
77{
78        if( is_array( @$GLOBALS['ret'] ) ) {
79                foreach( $GLOBALS['ret'] as $message ) {
80                        $log->add( strip_tags( $message ) ) ;
81                }
82        }
83
84        // use mLog->addWarning() or mLog->addError() if necessary
85}
86
87}
88
89?>
Note: See TracBrowser for help on using the repository browser.