XPressME Integration Kit

Trac

source: trunk/include/onupdate.php @ 96

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

途中経過でインストール、アップデートできなくなってしまっていたバグ修正
イベント通知の部分をFix、(ゲストのモジュールアクセス権限がないと通知できないのは直らない)
ブロックのキャッシュを見直し、キャッシュがない場合と、ブロックオプションが変更された場合にリフレッシュする機能を追加
ブロックキャッシュの更新にてポスト削除時のイベントをDB削除前にとっていたバグを修正。

File size: 7.7 KB
Line 
1<?php
2$mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
3
4eval( ' function xoops_module_update_'.$mydirname.'( $module ) { return xpress_onupdate_base( $module , "'.$mydirname.'" ) ; } ' ) ;
5
6
7if( ! function_exists( 'xpress_onupdate_base' ) ) :
8function xpress_onupdate_base( $module , $mydirname )
9{
10        // transations on module update
11
12        global $msgs ; // TODO :-D
13
14        // for Cube 2.1
15        if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
16                $root =& XCube_Root::getSingleton();
17                $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'xpress_message_append_onupdate' ) ;
18                $msgs = array() ;
19        } else {
20                if( ! is_array( $msgs ) ) $msgs = array() ;
21        }
22
23        $db =& Database::getInstance() ;
24        $mid = $module->getVar('mid') ;
25
26//XPress TABLE UPGRADE
27        global $wpdb,$wp_rewrite, $wp_queries, $table_prefix, $wp_db_version, $wp_roles,$wp_query;
28        define('WP_INSTALLING', true);
29        $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
30        $path = $mydirpath . '/';
31        if (file_exists($path . 'wp-load.php')) {
32                require_once $path . 'wp-load.php';
33        } else {
34                require_once $path . 'wp-config.php';
35        }
36        require_once($mydirpath . '/wp-admin/upgrade-functions.php');
37
38        if ( get_db_version($mydirname) != $wp_db_version ){
39                if( function_exists( 'wp_upgrade' ) )   {       
40                        wp_upgrade();
41                } else {
42                        wp_cache_flush();
43                        make_db_current_silent();
44                        upgrade_all();
45                        wp_cache_flush();
46                }                               
47        }
48
49        /* activate the tag plugin */
50        $plugin_current = "xpressme/xpressme.php";
51        update_option('active_plugins', array($plugin_current));
52        include_once(dirname(__FILE__) . '/../wp-content/plugins/'.$plugin_current);
53        do_action('activate_'.$plugin_current);
54       
55//      update_option("blog_charset", wp_blog_charset());
56        $xpress_version = $module->modinfo['version'];
57       
58        if (! enhanced_table_check($mydirname,'views')){
59                $xp_prefix = $mydirname;
60                if ($xp_prefix == 'wordpress'){
61                        $xp_prefix = 'wp';
62                }
63               
64                $charset_collate = '';
65                if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
66                        if ( ! empty($wpdb->charset) )
67                        $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
68                        if ( ! empty($wpdb->collate) )
69                        $charset_collate .= " COLLATE $wpdb->collate";
70                }
71                $views_table = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_views' ;
72                $views_queries ="CREATE TABLE $views_table (
73                post_id bigint(20) unsigned NOT NULL default '0',
74                post_views bigint(20) unsigned NOT NULL default '0',
75                KEY post_id (post_id)
76                )$charset_collate;";
77
78                dbDelta($views_queries);
79        }
80       
81        if (! enhanced_table_check($mydirname,'d3forum_link')){
82                $xp_prefix = $mydirname;
83                if ($xp_prefix == 'wordpress'){
84                        $xp_prefix = 'wp';
85                }
86               
87                $charset_collate = '';
88                if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
89                        if ( ! empty($wpdb->charset) )
90                        $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
91                        if ( ! empty($wpdb->collate) )
92                        $charset_collate .= " COLLATE $wpdb->collate";
93                }
94       
95                $d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ;
96                $queries ="CREATE TABLE $d3forum_link (
97                        comment_ID bigint(20) unsigned NOT NULL default '0',
98                        post_id int(10) unsigned NOT NULL default '0' ,
99                        wp_post_ID bigint(20) unsigned NOT NULL default '0',
100                        KEY post_id (post_id)
101                        )$charset_collate;";
102                dbDelta($queries);
103        }
104
105        if (! enhanced_table_check($mydirname,'group_role')){
106                $xp_prefix = $mydirname;
107                if ($xp_prefix == 'wordpress'){
108                        $xp_prefix = 'wp';
109                }
110               
111                $charset_collate = '';
112                if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
113                        if ( ! empty($wpdb->charset) )
114                        $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
115                        if ( ! empty($wpdb->collate) )
116                        $charset_collate .= " COLLATE $wpdb->collate";
117                }
118       
119                $group_role = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_group_role' ;
120                $views_queries ="CREATE TABLE $group_role (
121                        groupid smallint(5) unsigned NOT NULL default '0',
122                        name varchar(50)  NOT NULL default '' ,
123                        description text  NOT NULL default '',
124                        group_type varchar(10)  NOT NULL default '' ,
125                        role varchar(20)  NOT NULL default '' ,
126                        login_all smallint(5) unsigned NOT NULL default '0' ,
127                        KEY groupid (groupid)
128                        )$charset_collate;";
129                dbDelta($views_queries);
130                $sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')";
131                $wpdb->query($sql);
132
133        }
134       
135        // TEMPLATES (all templates have been already removed by modulesadmin)
136
137        $tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
138        $tpl_path = dirname( dirname( __FILE__ ) ).'/templates/source' ;
139        if( $handler = @opendir( $tpl_path . '/' ) ) {
140                while( ( $file = readdir( $handler ) ) !== false ) {
141                        if( substr( $file , 0 , 1 ) == '.' ) continue ;
142                        $file_path = $tpl_path . '/' . $file ;
143                        if( is_file( $file_path ) ) {
144                                $mtime = intval( @filemtime( $file_path ) ) ;
145                                $tplfile =& $tplfile_handler->create() ;
146                                $tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
147                                $tplfile->setVar( 'tpl_refid' , $mid ) ;
148                                $tplfile->setVar( 'tpl_tplset' , 'default' ) ;
149                                $tplfile->setVar( 'tpl_file' , $mydirname . '_' . $file ) ;
150                                $tplfile->setVar( 'tpl_desc' , '' , true ) ;
151                                $tplfile->setVar( 'tpl_module' , $mydirname ) ;
152                                $tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
153                                $tplfile->setVar( 'tpl_lastimported' , 0 ) ;
154                                $tplfile->setVar( 'tpl_type' , 'block' ) ;
155                                if( ! $tplfile_handler->insert( $tplfile ) ) {
156                                        $msgs[] = '<span style="color:#flockf0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>';
157                                } else {
158                                        $tplid = $tplfile->getVar( 'tpl_id' ) ;
159                                        $msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)';
160                                        // generate compiled file
161                                        include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
162                                        include_once XOOPS_ROOT_PATH.'/class/template.php' ;
163                                        if( ! xoops_template_touch( $tplid ) ) {
164                                                $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span>';
165                                        } else {
166                                                $msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span>';
167                                        }
168                                }
169                        }
170                }
171                closedir( $handler ) ;
172        }
173        include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
174        include_once XOOPS_ROOT_PATH.'/class/template.php' ;
175        xoops_template_clear_module_cache( $mid ) ;
176
177       
178        return true ;
179}
180endif;
181
182if( ! function_exists( 'xpress_message_append_onupdate' ) ) :
183function xpress_message_append_onupdate( &$module_obj , &$log )
184{
185        if( is_array( @$GLOBALS['msgs'] ) ) {
186                foreach( $GLOBALS['msgs'] as $message ) {
187                        $log->add( strip_tags( $message ) ) ;
188                }
189        }
190
191        // use mLog->addWarning() or mLog->addError() if necessary
192}
193endif;
194
195if( ! function_exists( 'get_db_version' ) ) :
196function get_db_version($mydirname){
197                global $xoopsModule;
198                $wp_prefix = $mydirname;
199                if ($wp_prefix == 'wordpress'){
200                        $wp_prefix = 'wp';
201                }
202                $xoopsDB =& Database::getInstance();
203                $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options');
204
205                $sql = "SELECT option_value FROM $db_xpress_option WHERE option_name = 'db_version'";
206                $res = $xoopsDB->query($sql, 0, 0);
207                if ($res === false){
208                        return false;
209                } else {
210                        $row = $xoopsDB->fetchArray($res);
211                        return $row['option_value'];
212                }
213}
214endif;
215
216
217if( ! function_exists( 'enhanced_table_check' ) ) :
218function enhanced_table_check($mydirname,$table_name){
219                global $xoopsModule;
220               
221                $xoopsDB =& Database::getInstance();
222                if ($mydirname == 'wordpress'){
223                        $xpress_prefix=  $xoopsDB->prefix('wp_');
224                } else {
225                        $xpress_prefix=  $xoopsDB->prefix($mydirname . '_');
226                }
227                $db_enhanced = $xpress_prefix . $table_name;
228
229                $sql = "show tables like '$db_enhanced'";
230                $res = $xoopsDB->query($sql, 0, 0);
231                if ($res === false){
232                        return false;
233                } else {
234                        if ($xoopsDB->getRowsNum($res)  > 0)
235                                return true;
236                        else
237                                return false;
238                }
239}
240endif;
241
242?>
Note: See TracBrowser for help on using the repository browser.