|
1
|
|
|
<?php |
|
2
|
|
|
// Upgrade functions used when adding or altering tables etc between versions |
|
3
|
|
|
/** |
|
4
|
|
|
* Function to do the creatind |
|
5
|
|
|
* |
|
6
|
|
|
*/ |
|
7
|
|
|
function smallworld_doUpgrade () { |
|
8
|
|
|
global $xoopsDB, $xoopsUser; |
|
|
|
|
|
|
9
|
|
|
varcharToBlog (); |
|
10
|
|
|
smallworld_comToBlog (); |
|
11
|
|
|
smallworld_adminAvatarRename (); |
|
12
|
|
|
if (smallworld_DoTableExists($xoopsDB->prefix('smallworld_settings'))) { |
|
13
|
|
|
// Table exists |
|
14
|
|
|
Return false; |
|
15
|
|
|
} else { |
|
16
|
|
|
// Table does not exist -> create |
|
17
|
|
|
|
|
18
|
|
|
$sql = "CREATE TABLE IF NOT EXISTS ".$xoopsDB->prefix('smallworld_settings')." ("; |
|
19
|
|
|
$sql .= "`id` int(11) NOT NULL AUTO_INCREMENT,"; |
|
20
|
|
|
$sql .= "`userid` int(11) NOT NULL,"; |
|
21
|
|
|
$sql .= "`value` text NOT NULL,"; |
|
22
|
|
|
$sql .= "PRIMARY KEY (`id`)"; |
|
23
|
|
|
$sql .= ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"; |
|
24
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
function smallworld_adminAvatarRename () { |
|
29
|
|
|
global $xoopsDB; |
|
|
|
|
|
|
30
|
|
|
$sql = "update ".$xoopsDB->prefix('smallworld_admin')." set userimage = '' WHERE userimage = 'blank.gif' || userimage NOT REGEXP '\.(jpe?g|gif|png|bmp)'"; |
|
31
|
|
|
$sql2 = "update ".$xoopsDB->prefix('smallworld_user')." set userimage = '' WHERE userimage = 'blank.gif' || userimage NOT REGEXP '\.(jpe?g|gif|png|bmp)'"; |
|
32
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
33
|
|
|
$result2 = $xoopsDB->queryF($sql2); |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function smallworld_DoTableExists($tablename) { |
|
37
|
|
|
global $xoopsDB; |
|
|
|
|
|
|
38
|
|
|
$result = $xoopsDB->queryF("SHOW TABLES LIKE '$tablename'"); |
|
39
|
|
|
|
|
40
|
|
|
return ($xoopsDB->getRowsNum($result) > 0); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Alter table messages from varchar(200) to text() |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
|
|
function varcharToBlog () { |
|
48
|
|
|
global $xoopsDB; |
|
|
|
|
|
|
49
|
|
|
$sql ="ALTER TABLE ".$xoopsDB->prefix('smallworld_messages')." CHANGE message message TEXT"; |
|
50
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* function to correct the comments from varchar to text |
|
55
|
|
|
* @return void |
|
56
|
|
|
*/ |
|
57
|
|
|
function smallworld_comToBlog () { |
|
58
|
|
|
global $xoopsDB; |
|
|
|
|
|
|
59
|
|
|
$sql ="ALTER TABLE ".$xoopsDB->prefix('smallworld_comments')." CHANGE comment comment TEXT"; |
|
60
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state