XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/include/onupdate.php @ 762

Last change on this file since 762 was 749, checked in by toemon, 13 years ago

Database::getInstance()を使わずに、global $xoopsDB を使用する。(xoops3対策)

File size: 11.2 KB
RevLine 
[1]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
[128]12        global $msgs ; // TODO :-D
[1]13        // for Cube 2.1
14        if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
15                $root =& XCube_Root::getSingleton();
16                $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'xpress_message_append_onupdate' ) ;
[384]17                $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Fail', 'xpress_message_append_onupdate' ) ;
[128]18                $msgs = array() ;
[1]19        } else {
[128]20                if( ! is_array( $msgs ) ) $msgs = array() ;
[1]21        }
22
23        $mid = $module->getVar('mid') ;
[384]24       
[1]25
[384]26
[208]27//XPressME Update
28        global $wpdb,$wp_rewrite, $wp_queries, $table_prefix, $wp_db_version, $wp_roles,$wp_query;
[252]29        global $xoops_db;
[208]30        $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
31        $path = $mydirpath . '/';
[384]32
33// permission and wordpress files check
34        require_once ($path . 'include/pre_check.php');
35        if(! xp_permission_check($mydirname, $mydirpath)){
36                $msgs = $GLOBALS["err_log"];
37                return false;
38        }
39
[277]40//Site_url and home of an optional table are repaired.
41        $site_url= XOOPS_URL."/modules/".$mydirname;
42        xpress_put_siteurl($mydirname,$site_url);
[474]43        $home = get_xpress_option($mydirname,'home');
44        $home_check = 'home option is right';
45        if (strcmp($site_url,$home) !== 0 ){
46                if (!@fclose(@fopen($home . '/xoops_version.php', "r"))){
47                        xpress_put_home($mydirname,$site_url);
48                        $home_check = 'Change home option $home to $site_url';
49                }
50        }
51        $msgs[] = $home_check;
[208]52// XPressME orignal table update
[277]53        $t_mess = xpress_table_make($module , $mydirname);
54        $msgs = array_merge($msgs,$t_mess);
[1]55
[187]56// make templates
[102]57        include_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/xpress_templates_make.php' ;
[462]58        $mod_version = $module->getVar('version') ;
59
60        $t_mess = xpress_clean_templates_file($mydirname,$mod_version);
61        $msgs = array_merge($msgs,$t_mess);
62       
[102]63        $t_mess = xpress_templates_make($mid,$mydirname);
[128]64        $msgs = array_merge($msgs,$t_mess);
[187]65
[277]66// The activation processing of the XPressME plugin is omitted.
67// Because the XPressME plugin is done with wp-config in activation
[187]68
69        /* activate the xpressme plugin */
[277]70//      require_once dirname( __FILE__ ).'/xpress_active_plugin.php';
71//      if (xpress_pulugin_activation('xpressme/xpressme.php')){
72//              $msgs[] = 'The xpressme plug-in was activated.';
73//      }
[187]74       
[1]75        return true ;
76}
77endif;
78
[187]79if( ! function_exists( 'xpress_put_siteurl' ) ) :
80function xpress_put_siteurl($mydirname,$url){
[749]81                global $xoopsModule,$xoopsDB;
[583]82                $wp_prefix = preg_replace('/wordpress/','wp',$mydirname);
[187]83                $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options');
84
85                $sql = "UPDATE $db_xpress_option SET option_value = '$url' WHERE option_name = 'siteurl'";
86                $res = $xoopsDB->queryF($sql, 0, 0);
87}
88endif;
89
[277]90if( ! function_exists( 'xpress_put_home' ) ) :
91function xpress_put_home($mydirname,$url){
[749]92                global $xoopsModule,$xoopsDB;
[583]93                $wp_prefix = preg_replace('/wordpress/','wp',$mydirname);
[277]94                $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options');
95
96                $sql = "UPDATE $db_xpress_option SET option_value = '$url' WHERE option_name = 'home'";
97                $res = $xoopsDB->queryF($sql, 0, 0);
98}
99endif;
100
[474]101if( ! function_exists( 'get_xpress_option' ) ) {
102        function get_xpress_option($mydirname,$option_name){
[749]103                global $xoopsModule,$xoopsDB;
[583]104                $wp_prefix = preg_replace('/wordpress/','wp',$mydirname);
[474]105                $option_table = $xoopsDB->prefix($wp_prefix . '_options');
[277]106
[474]107                $sql = "SELECT option_value FROM $option_table WHERE option_name = '" . $option_name . "'";
108               
109                $result =  $xoopsDB->query($sql, 0, 0);
110                if ($xoopsDB->getRowsNum($result)  > 0){
111                        $row = $xoopsDB->fetchArray($result);
112                        return $row['option_value'];
113                }
114                return 0;
115        }
116}
117
[1]118if( ! function_exists( 'xpress_message_append_onupdate' ) ) :
119function xpress_message_append_onupdate( &$module_obj , &$log )
120{
121        if( is_array( @$GLOBALS['msgs'] ) ) {
122                foreach( $GLOBALS['msgs'] as $message ) {
123                        $log->add( strip_tags( $message ) ) ;
124                }
125        }
126
127        // use mLog->addWarning() or mLog->addError() if necessary
128}
129endif;
130
131if( ! function_exists( 'get_db_version' ) ) :
132function get_db_version($mydirname){
[749]133                global $xoopsModule,$xoopsDB;
[583]134                $wp_prefix = preg_replace('/wordpress/','wp',$mydirname);
[1]135                $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options');
136
137                $sql = "SELECT option_value FROM $db_xpress_option WHERE option_name = 'db_version'";
138                $res = $xoopsDB->query($sql, 0, 0);
139                if ($res === false){
140                        return false;
141                } else {
142                        $row = $xoopsDB->fetchArray($res);
143                        return $row['option_value'];
144                }
145}
146endif;
147
[277]148if( ! function_exists( 'xpress_block_check' ) ) :
149function xpress_block_check($mydirname){
150        include_once(dirname(dirname(__FILE__)) . '/class/check_blocks_class.php');
[1]151
[277]152        $xoops_block_check =& xoops_block_check::getInstance();
153
154        if ( !$xoops_block_check->is_admin() )
155        {
156                $cont = 'Block Check Pass';
157                return cont;
158        }
159
160        switch ( $xoops_block_check->get_op() )
161        {
162                case "remove_block":
163                        $cont = $xoops_block_check->remove_block();
164                        break;
165
166                default:
167                        $cont = $xoops_block_check->check_blocks($mydirname);
168                        break;
169        }
170        return $cont;
171}
172endif;
173
174if( ! function_exists( 'xpress_table_make' ) ) :
175function xpress_table_make($module, $mydirname)
176{
[749]177        global $xoopsDB;
[277]178        $mid = $module->getVar('mid') ;
179
180// XPressME orignal table update
[583]181        $xp_prefix = preg_replace('/wordpress/','wp',$mydirname);
[277]182        $msgs = array();
183
[428]184        $views_table = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_views' ;
[277]185        if (! enhanced_table_check($mydirname,'views')){
186                $queries ="CREATE TABLE $views_table (
[428]187                blog_id bigint(20) unsigned NOT NULL default '0',
[277]188                post_id bigint(20) unsigned NOT NULL default '0',
189                post_views bigint(20) unsigned NOT NULL default '0',
190                KEY post_id (post_id)
191                ) TYPE=MyISAM";
[749]192                $xoopsDB->queryF( $queries ) ;
[277]193                $msgs[] = "$views_table table of XPressME was made.";
[428]194        } else {
195                if (!is_found_table_column($views_table,'blog_id')){
196                        $queries ="ALTER TABLE $views_table ADD blog_id bigint(20)  FIRST";
[749]197                        $xoopsDB->queryF( $queries ) ;
[428]198                        $msgs[] = "$views_table  ADD blog_id .";
199                }
[481]200               
201                // The table is repaired.
202                $non_blogid_sql ="SELECT * FROM $views_table WHERE blog_id IS NULL OR blog_id < 1";
[749]203                $non_blogid_res = $xoopsDB->query($non_blogid_sql, 0, 0);
204                while($row = $xoopsDB->fetchArray($non_blogid_res)){
[481]205                        $total_view = $row['post_views'];
206                        $post_id = $row['post_id'];
207                        $new_blogid_sql ="SELECT SUM(post_views) as post_views_sum FROM $views_table WHERE post_id = $post_id AND blog_id = 1 GROUP BY post_id";
[749]208                        $new_blogid_res = $xoopsDB->query($new_blogid_sql, 0, 0);
209                        if ($xoopsDB->getRowsNum($new_blogid_res)  > 0){
210                                $new_row = $xoopsDB->fetchArray($new_blogid_res);
[481]211                                $total_view = $total_view + $new_row['post_views_sum'];
212                                $del_sql = "DELETE FROM $views_table WHERE post_id = $post_id AND blog_id = 1";
[749]213                                $xoopsDB->queryF( $del_sql ) ;
[481]214                        }
215                        $update_sql = "UPDATE $views_table SET post_views = $total_view , blog_id = 1 WHERE post_id = $post_id AND (blog_id IS NULL OR blog_id < 1)";
[749]216                        $xoopsDB->queryF( $update_sql ) ;
[481]217                }
[277]218        }
219       
[590]220        $d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ;
[277]221        if (! enhanced_table_check($mydirname,'d3forum_link')){
222                $queries ="CREATE TABLE $d3forum_link (
223                        comment_ID bigint(20) unsigned NOT NULL default '0',
224                        post_id int(10) unsigned NOT NULL default '0' ,
225                        wp_post_ID bigint(20) unsigned NOT NULL default '0',
[590]226                        forum_id bigint(20) unsigned NOT NULL default '0',
227                        blog_id bigint(20) unsigned NOT NULL default '0',
[277]228                        KEY post_id (post_id)
229                        )TYPE=MyISAM";
[749]230                $xoopsDB->queryF( $queries ) ;
[277]231                $msgs[] = "$d3forum_link table of XPressME was made.";
[590]232        } else {
233                if (!is_found_table_column($d3forum_link,'forum_id')){
234                        $queries ="ALTER TABLE $d3forum_link ADD forum_id bigint(20) unsigned NOT NULL default '0' AFTER wp_post_ID";
[749]235                        $xoopsDB->queryF( $queries ) ;
[590]236                        $msgs[] = "$d3forum_link  ADD forum_id .";
237                        // The table is repaired.
238//                      $update_sql = "UPDATE $d3forum_link SET forum_id = 1 WHERE(forum_id IS NULL OR forum_id < 1)";
[749]239//                      $xoopsDB->queryF( $update_sql ) ;
[590]240                }
241                if (!is_found_table_column($d3forum_link,'blog_id')){
242                        $queries ="ALTER TABLE $d3forum_link ADD blog_id bigint(20)  unsigned NOT NULL default '0' AFTER forum_id";
[749]243                        $xoopsDB->queryF( $queries ) ;
[590]244                        $msgs[] = "$d3forum_link  ADD blog_id .";
245                        // The table is repaired.
246                        $update_sql = "UPDATE $d3forum_link SET blog_id = 1 WHERE(blog_id IS NULL OR blog_id < 1)";
[749]247                        $xoopsDB->queryF( $update_sql ) ;
[590]248                }
[277]249        }
250
[534]251        $group_role = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_group_role' ;
[277]252        if (! enhanced_table_check($mydirname,'group_role')){
253                $queries ="CREATE TABLE $group_role (
254                        groupid smallint(5) unsigned NOT NULL default '0',
[534]255                        blog_id bigint(20) unsigned NOT NULL default '0',
[277]256                        name varchar(50)  NOT NULL default '' ,
257                        description text  NOT NULL default '',
258                        group_type varchar(50)  NOT NULL default '' ,
259                        role varchar(20)  NOT NULL default '' ,
260                        login_all smallint(5) unsigned NOT NULL default '0' ,
261                        KEY groupid (groupid)
262                        )TYPE=MyISAM";
[749]263                $xoopsDB->queryF( $queries ) ;
[277]264                $sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')";
[749]265                $xoopsDB->queryF( $sql ) ;
[277]266                $msgs[] = "$group_role table of XPressME was made.";
[534]267        } else {
268                if (!is_found_table_column($group_role,'blog_id')){
269                        $queries ="ALTER TABLE $group_role ADD blog_id bigint(20)  AFTER groupid";
[749]270                        $xoopsDB->queryF( $queries ) ;
[534]271                        $msgs[] = "$group_role  ADD blog_id .";
272                }
273                // The table is repaired.
274                $update_sql = "UPDATE $group_role SET blog_id = 1 WHERE(blog_id IS NULL OR blog_id < 1)";
[749]275                $xoopsDB->queryF( $update_sql ) ;
[277]276        }
277       
[352]278        if (! enhanced_table_check($mydirname,'notify_reserve')){
279                $notify_reserve = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_notify_reserve' ;
280                $queries ="CREATE TABLE $notify_reserve (
281                        notify_reserve_id bigint(20) NOT NULL AUTO_INCREMENT ,
282                        notify_reserve_status varchar(20)  NOT NULL default '' ,
283                        category text  NOT NULL default '',
284                        item_id bigint(20) unsigned NOT NULL default '0',
285                        event varchar(20) NOT NULL default '',
286                        extra_tags_arry longtext NOT NULL default '' ,
287                        user_list_arry longtext NOT NULL default '' ,
288                        module_id smallint(5) unsigned NOT NULL default '0' ,
289                        omit_user_id varchar(20) NOT NULL default '' ,
290                        KEY notify_reserve_id (notify_reserve_id)
291                        )TYPE=MyISAM";
[749]292                $xoopsDB->queryF( $queries ) ;
[352]293                $msgs[] = "$notify_reserve table of XPressME was made.";
294        }
[277]295        return $msgs;
296}
297endif;
298
[1]299if( ! function_exists( 'enhanced_table_check' ) ) :
300function enhanced_table_check($mydirname,$table_name){
[749]301                global $xoopsModule,$xoopsDB;
[1]302               
[583]303                $xpress_prefix = $xoopsDB->prefix(preg_replace('/wordpress/','wp',$mydirname) . '_');
[1]304                $db_enhanced = $xpress_prefix . $table_name;
305
306                $sql = "show tables like '$db_enhanced'";
307                $res = $xoopsDB->query($sql, 0, 0);
308                if ($res === false){
309                        return false;
310                } else {
311                        if ($xoopsDB->getRowsNum($res)  > 0)
312                                return true;
313                        else
314                                return false;
315                }
316}
317endif;
318
[428]319if( ! function_exists( 'is_found_table_column' ) ) :
320function is_found_table_column($table,$column){
[749]321                global $xoopsModule,$xoopsDB;
[151]322
[428]323                $sql = "DESCRIBE $table $column";
324                $res = $xoopsDB->queryF($sql, 0, 0);
325                if ($res === false){
326                        return false;
327                } else {
328                        if ($xoopsDB->getRowsNum($res)  > 0)
329                                return true;
330                        else
331                                return false;
332                }
333}
334endif;
[151]335
[428]336
[1]337?>
Note: See TracBrowser for help on using the repository browser.