forked from nbuy/xoops-modules-eguide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
onupdate.php
111 lines (99 loc) · 3.51 KB
/
onupdate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
# eguide module onUpdate proceeding.
# $Id: onupdate.php,v 1.5 2010/02/21 11:07:50 nobu Exp $
global $xoopsDB;
include_once __DIR__ . "/const.php";
$config = XOOPS_ROOT_PATH . '/modules/eguide/cache/config.php';
if ( file_exists( $config ) ) {
include $config;
$cri_mods = new CriteriaCompo( new Criteria( 'conf_modid', $xoopsModule->getVar( 'mid' ) ) );
$criteria = new CriteriaCompo();
foreach ( array( 'group', 'notify', 'auth', 'max_item', 'max_event', 'user_notify' ) as $name ) {
if ( $eventConfig[ $name ] != $xoopsModuleConfig[ $name ] ) {
$criteria->add( new Criteria( 'conf_name', $name ), 'OR' );
}
}
if ( count( $criteria->criteriaElements ) ) {
$cri_mods->add( $criteria );
$configs =& $config_handler->getConfigs( $criteria );
foreach ( $configs as $config ) {
$name = $config->getVar( 'conf_name' );
$config->setConfValueForInput( $eventConfig[ $name ] );
}
}
unlink( $config );
}
// create table eguide_category, eguide_extent
$xoopsDB->query( 'UPDATE ' . EGTBL . ' SET ldate=edate WHERE ldate=0' );
// add field in 2.0b
add_field( RVTBL, 'exid', "INT DEFAULT 0 NOT NULL", 'eid' );
add_field( OPTBL, 'closetime', "INT DEFAULT 0 NOT NULL", 'reserved' );
// add field in 2.0b2 added
add_field( EXTBL, 'expersons', 'INTEGER', 'exdate' );
// eguide_cat table add in 2.0
$xoopsDB->query( 'SELECT * FROM ' . CATBL, 1 );
if ( $xoopsDB->errno() ) { // check exists
$xoopsDB->query( "CREATE TABLE " . CATBL . " (
catid integer NOT NULL auto_increment,
catname varchar(40) NOT NULL,
catimg varchar(191),
catdesc text,
catpri integer NOT NULL default '0',
weight integer NOT NULL default '0',
PRIMARY KEY (catid)
)" );
$xoopsDB->query( "INSERT INTO " . CATBL . " VALUES(1, '')" );
}
// eguide_extent table add in 2.0
$xoopsDB->query( 'SELECT * FROM ' . EXTBL, 1 );
if ( $xoopsDB->errno() ) { // check exists
$xoopsDB->query( "CREATE TABLE " . EXTBL . " (
exid integer NOT NULL auto_increment,
eidref integer NOT NULL,
exdate integer NOT NULL,
expersons integer,
reserved int(8) unsigned NOT NULL default '0',
PRIMARY KEY (exid)
)" );
report_message( " Add new table: <b>$table</b>" );
}
// add field in 2.1
$res = $xoopsDB->query( "SELECT optvars FROM " . OPTBL, 1 );
if ( empty( $res ) && $xoopsDB->errno() ) {
add_field( OPTBL, 'redirect', "varchar(128) NOT NULL default ''", 'optfield' );
// change field name and type
$xoopsDB->query( "ALTER TABLE " . OPTBL . " CHANGE `redirect` `optvars` TEXT" );
// convert internal format
$xoopsDB->query( "UPDATE " . OPTBL . " SET optvars=concat('redirect=', optvars) WHERE optvars<>''" );
}
// add field in 2.4
add_field( CATBL, 'catpri', "INT DEFAULT 0 NOT NULL", 'catdesc' );
add_field( CATBL, 'weight', "INT DEFAULT 0 NOT NULL", 'catpri' );
// add field in 2.7
add_field( RVTBL, 'operator', "INT", 'uid' );
function report_message( $msg ) {
global $msgs; // module manager's variable
static $first = true;
if ( $first ) {
$msgs[] = "Update Database...";
$first = false;
}
$msgs[] = " $msg";
}
function add_field( $table, $field, $type, $after ) {
global $xoopsDB;
$res = $xoopsDB->query( "SELECT $field FROM $table", 1 );
if ( empty( $res ) && $xoopsDB->errno() ) { // check exists
if ( $after ) {
$after = "AFTER $after";
}
$res = $xoopsDB->query( "ALTER TABLE $table ADD $field $type $after" );
} else {
return false;
}
report_message( " Add new field: <b>$table.$field</b>" );
if ( ! $res ) {
echo "<span style='color: red; font: bold;'>" . $xoopsDB->error() . "</span>\n";
}
return $res;
}