XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
onuninstall.php
Go to the documentation of this file.
1 <?php
2 // start hack by Trabis
3 if (!class_exists('ProtectorRegistry')) exit('Registry not found');
4 
6 $mydirname = $registry->getEntry('mydirname');
7 $mydirpath = $registry->getEntry('mydirpath');
8 $language = $registry->getEntry('language');
9 // end hack by Trabis
10 
11 eval( ' function xoops_module_uninstall_'.$mydirname.'( $module ) { return protector_onuninstall_base( $module , "'.$mydirname.'" ) ; } ' ) ;
12 
13 
14 if( ! function_exists( 'protector_onuninstall_base' ) ) {
15 
16 function protector_onuninstall_base( $module , $mydirname )
17 {
18  // transations on module uninstall
19 
20  global $ret ; // TODO :-D
21 
22  // for Cube 2.1
23  if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
24  $root =& XCube_Root::getSingleton();
25  $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleUninstall.' . ucfirst($mydirname) . '.Success' , 'protector_message_append_onuninstall' ) ;
26  $ret = array() ;
27  } else {
28  if( ! is_array( $ret ) ) $ret = array() ;
29  }
30 
32  $mid = $module->getVar('mid') ;
33 
34  // TABLES (loading mysql.sql)
35  $sql_file_path = dirname(__FILE__).'/sql/mysql.sql' ;
36  $prefix_mod = $db->prefix() . '_' . $mydirname ;
37  if( file_exists( $sql_file_path ) ) {
38  $ret[] = "SQL file found at <b>".htmlspecialchars($sql_file_path)."</b>.<br /> Deleting tables...<br />";
39  $sql_lines = file( $sql_file_path ) ;
40  foreach( $sql_lines as $sql_line ) {
41  if( preg_match( '/^CREATE TABLE \`?([a-zA-Z0-9_-]+)\`? /i' , $sql_line , $regs ) ) {
42  $sql = 'DROP TABLE '.addslashes($prefix_mod.'_'.$regs[1]);
43  if (!$db->query($sql)) {
44  $ret[] = '<span style="color:#ff0000;">ERROR: Could not drop table <b>'.htmlspecialchars($prefix_mod.'_'.$regs[1]).'<b>.</span><br />';
45  } else {
46  $ret[] = 'Table <b>'.htmlspecialchars($prefix_mod.'_'.$regs[1]).'</b> dropped.<br />';
47  }
48  }
49  }
50  }
51 
52  // TEMPLATES (Not necessary because modulesadmin removes all templates)
53  /* $tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
54  $templates =& $tplfile_handler->find( null , 'module' , $mid ) ;
55  $tcount = count( $templates ) ;
56  if( $tcount > 0 ) {
57  $ret[] = 'Deleting templates...' ;
58  for( $i = 0 ; $i < $tcount ; $i ++ ) {
59  if( ! $tplfile_handler->delete( $templates[$i] ) ) {
60  $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 />';
61  } else {
62  $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 />';
63  }
64  }
65  }
66  unset($templates); */
67 
68 
69  return true ;
70 }
71 
72 function protector_message_append_onuninstall( &$module_obj , &$log )
73 {
74  if( is_array( @$GLOBALS['ret'] ) ) {
75  foreach( $GLOBALS['ret'] as $message ) {
76  $log->add( strip_tags( $message ) ) ;
77  }
78  }
79 
80  // use mLog->addWarning() or mLog->addError() if necessary
81 }
82 
83 }
84 
85 ?>