PageRenderTime 24ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/xoops_trust_path/modules/d3forum/onupdate.php

http://xoopscube-modules.googlecode.com/
PHP | 117 lines | 87 code | 20 blank | 10 comment | 24 complexity | 033a07cc4ae73e5e745873655da93409 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. eval( ' function xoops_module_update_'.$mydirname.'( $module ) { return d3forum_onupdate_base( $module , "'.$mydirname.'" ) ; } ' ) ;
  3. if( ! function_exists( 'd3forum_onupdate_base' ) ) {
  4. function d3forum_onupdate_base( $module , $mydirname )
  5. {
  6. // transations on module update
  7. global $msgs ; // TODO :-D
  8. // for Cube 2.1
  9. if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
  10. $root =& XCube_Root::getSingleton();
  11. $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'd3forum_message_append_onupdate' ) ;
  12. $msgs = array() ;
  13. } else {
  14. if( ! is_array( $msgs ) ) $msgs = array() ;
  15. }
  16. $db =& Database::getInstance() ;
  17. $mid = $module->getVar('mid') ;
  18. // TABLES (write here ALTER TABLE etc. if necessary)
  19. // configs (Though I know it is not a recommended way...)
  20. $check_sql = "SHOW COLUMNS FROM ".$db->prefix("config")." LIKE 'conf_title'" ;
  21. if( ( $result = $db->query( $check_sql ) ) && ( $myrow = $db->fetchArray( $result ) ) && @$myrow['Type'] == 'varchar(30)' ) {
  22. $db->queryF( "ALTER TABLE ".$db->prefix("config")." MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''" ) ;
  23. }
  24. // 0.1x -> 0.2x
  25. $check_sql = "SELECT cat_unique_path FROM ".$db->prefix($mydirname."_categories") ;
  26. if( ! $db->query( $check_sql ) ) {
  27. $db->queryF( "ALTER TABLE ".$db->prefix($mydirname."_categories")." ADD cat_unique_path text NOT NULL default '' AFTER cat_path_in_tree" ) ;
  28. $db->queryF( "ALTER TABLE ".$db->prefix($mydirname."_forums")." ADD forum_external_link_format varchar(255) NOT NULL default '' AFTER cat_id" ) ;
  29. $db->queryF( "ALTER TABLE ".$db->prefix($mydirname."_topics")." ADD topic_external_link_id int(10) unsigned NOT NULL default 0 AFTER forum_id, ADD KEY (`topic_external_link_id`)" ) ;
  30. $db->queryF( "ALTER TABLE ".$db->prefix($mydirname."_posts")." ADD path_in_tree text NOT NULL default '' AFTER order_in_tree , ADD unique_path text NOT NULL default '' AFTER order_in_tree" ) ;
  31. }
  32. // 0.3x -> 0.4x
  33. $check_sql = "SELECT subject_waiting FROM ".$db->prefix($mydirname."_posts") ; if( ! $db->query( $check_sql ) ) {
  34. $db->queryF( "ALTER TABLE ".$db->prefix($mydirname."_posts")." ADD subject_waiting varchar(255) NOT NULL default '' AFTER `subject`, ADD post_text_waiting text NOT NULL AFTER `post_text`, ADD uid_hidden mediumint(8) unsigned NOT NULL default 0 AFTER `uid`, DROP hide_uid" ) ;
  35. }
  36. // 0.4x/0.6x -> 0.7x
  37. $check_sql = "SHOW COLUMNS FROM ".$db->prefix($mydirname."_topics")." LIKE 'topic_external_link_id'" ;
  38. if( ( $result = $db->query( $check_sql ) ) && ( $myrow = $db->fetchArray( $result ) ) && substr( @$myrow['Type'] , 0 , 3 ) == 'int' ) {
  39. $db->queryF( "ALTER TABLE ".$db->prefix($mydirname."_topics")." MODIFY topic_external_link_id varchar(255) NOT NULL default ''" ) ;
  40. }
  41. $check_sql = "SELECT COUNT(*) FROM ".$db->prefix($mydirname."_post_histories") ;
  42. if( ! $db->query( $check_sql ) ) {
  43. $db->queryF( "CREATE TABLE ".$db->prefix($mydirname."_post_histories")." ( history_id int(10) unsigned NOT NULL auto_increment, post_id int(10) unsigned NOT NULL default 0, history_time int(10) NOT NULL default 0, data text, PRIMARY KEY (history_id), KEY (post_id) ) TYPE=MyISAM" ) ;
  44. }
  45. // TEMPLATES (all templates have been already removed by modulesadmin)
  46. $tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
  47. $tpl_path = dirname(__FILE__).'/templates' ;
  48. if( $handler = @opendir( $tpl_path . '/' ) ) {
  49. while( ( $file = readdir( $handler ) ) !== false ) {
  50. if( substr( $file , 0 , 1 ) == '.' ) continue ;
  51. $file_path = $tpl_path . '/' . $file ;
  52. if( is_file( $file_path ) ) {
  53. $mtime = intval( @filemtime( $file_path ) ) ;
  54. $tplfile =& $tplfile_handler->create() ;
  55. $tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
  56. $tplfile->setVar( 'tpl_refid' , $mid ) ;
  57. $tplfile->setVar( 'tpl_tplset' , 'default' ) ;
  58. $tplfile->setVar( 'tpl_file' , $mydirname . '_' . $file ) ;
  59. $tplfile->setVar( 'tpl_desc' , '' , true ) ;
  60. $tplfile->setVar( 'tpl_module' , $mydirname ) ;
  61. $tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
  62. $tplfile->setVar( 'tpl_lastimported' , 0 ) ;
  63. $tplfile->setVar( 'tpl_type' , 'module' ) ;
  64. if( ! $tplfile_handler->insert( $tplfile ) ) {
  65. $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>';
  66. } else {
  67. $tplid = $tplfile->getVar( 'tpl_id' ) ;
  68. $msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)';
  69. // generate compiled file
  70. include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
  71. include_once XOOPS_ROOT_PATH.'/class/template.php' ;
  72. if( ! xoops_template_touch( $tplid ) ) {
  73. $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span>';
  74. } else {
  75. $msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span>';
  76. }
  77. }
  78. }
  79. }
  80. closedir( $handler ) ;
  81. }
  82. include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
  83. include_once XOOPS_ROOT_PATH.'/class/template.php' ;
  84. xoops_template_clear_module_cache( $mid ) ;
  85. return true ;
  86. }
  87. function d3forum_message_append_onupdate( &$module_obj , &$log )
  88. {
  89. if( is_array( @$GLOBALS['msgs'] ) ) {
  90. foreach( $GLOBALS['msgs'] as $message ) {
  91. $log->add( strip_tags( $message ) ) ;
  92. }
  93. }
  94. // use mLog->addWarning() or mLog->addError() if necessary
  95. }
  96. }
  97. ?>