-
Notifications
You must be signed in to change notification settings - Fork 1
/
onupdate.php
46 lines (40 loc) · 1.48 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
<?php
# medialinks module onUpdate proceeding.
# $Id: onupdate.php,v 1.1 2007/11/24 09:49:13 nobu Exp $
global $xoopsDB;
define('MAIN', $xoopsDB->prefix('medialinks'));
define('ACLS', $xoopsDB->prefix('medialinks_access'));
// addional field in 2.0
add_field(MAIN, 'nacl', "INT DEFAULT 0 NOT NULL", 'hits');
$xoopsDB->query('SELECT * FROM '.ACLS, 1);
if ($xoopsDB->errno()) { // check exists
$msgs[] = "Update Database...";
$msgs[] = " Add new table: <b>medialinks_access</b>";
$xoopsDB->query("CREATE TABLE ".ACLS." (
auid integer NOT NULL default '0',
amid integer NOT NULL default '0',
writable ENUM('Y', 'N') NOT NULL default 'N',
KEY (auid, amid)
)");
}
// reset nacl value
$xoopsDB->query('UPDATE '.MAIN." SET nacl=0");
$res = $xoopsDB->query('SELECT mid,count(auid) FROM '.MAIN.', '.ACLS.' WHERE mid=amid GROUP BY mid');
$n = $xoopsDB->getRowsNum($res);
$msgs[] = "Access control entry in Database ($n)";
while (list($mid, $nacl) = $xoopsDB->fetchRow($res)) {
$xoopsDB->query("UPDATE ".MAIN." SET nacl=$nacl WHERE mid=$mid");
}
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;
if (!$res) {
echo "<div class='errorMsg'>".$xoopsDB->errno()."</div>\n";
}
return $res;
}
?>