XPressME Integration Kit

Trac

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

Last change on this file since 462 was 462, checked in by toemon, 14 years ago

XPressME アップデート時のtemplatesフォルダーを整理 Fixes #253
XPressME Ver1.Xからのアップデート時templatesフォルダー内のsourceディレクトリとindex.phpを残し後はすべて削除した後、テンプレートを作成するようにする。
Ver2.X以降からのアップデート時は、不要ディレクトリと不要ファイル(ファイルのプレフィックスが異なるファイルを削除

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