|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Upgrader from 2.3.3 to 2.4.0 |
|
14
|
|
|
* See the enclosed file license.txt for licensing information. |
|
15
|
|
|
* If you did not receive this file, get it at http://www.fsf.org/copyleft/gpl.html |
|
16
|
|
|
* |
|
17
|
|
|
* @copyright The XOOPS project http://www.xoops.org/ |
|
18
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU General Public License (GPL) |
|
19
|
|
|
* @package upgrader |
|
20
|
|
|
* @since 2.4.0 |
|
21
|
|
|
* @author Taiwen Jiang <[email protected]> |
|
22
|
|
|
* @author trabis <[email protected]> |
|
23
|
|
|
* @version $Id$ |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
class upgrade_240 extends xoopsUpgrade |
|
27
|
|
|
{ |
|
28
|
|
|
public $tasks = array('keys'); |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Check if keys already exist |
|
32
|
|
|
|
|
33
|
|
|
*/ |
|
34
|
|
|
public function check_keys() |
|
35
|
|
|
{ |
|
36
|
|
|
$xoops = Xoops::getInstance(); |
|
37
|
|
|
$db = $xoops->db(); |
|
|
|
|
|
|
38
|
|
|
$tables['modules'] = array('isactive', 'weight', 'hascomments'); |
|
|
|
|
|
|
39
|
|
|
$tables['users'] = array('level'); |
|
40
|
|
|
$tables['online'] = array('online_updated', 'online_uid'); |
|
41
|
|
|
$tables['config'] = array('conf_order'); |
|
42
|
|
|
$tables['xoopscomments'] = array('com_status'); |
|
43
|
|
|
|
|
44
|
|
|
foreach ($tables as $table => $keys) { |
|
45
|
|
|
$sql = "SHOW KEYS FROM `" . $xoops->db()->prefix($table) . "`"; |
|
46
|
|
|
if (!$result = $xoops->db()->queryF($sql)) { |
|
|
|
|
|
|
47
|
|
|
continue; |
|
48
|
|
|
} |
|
49
|
|
|
$existing_keys = array(); |
|
50
|
|
|
while ($row = $xoops->db()->fetchArray($result)) { |
|
51
|
|
|
$existing_keys[] = $row['Key_name']; |
|
52
|
|
|
} |
|
53
|
|
|
foreach ($keys as $key) { |
|
54
|
|
|
if (!in_array($key, $existing_keys)) { |
|
55
|
|
|
return false; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
return true; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Apply keys that are missing |
|
64
|
|
|
|
|
65
|
|
|
*/ |
|
66
|
|
|
public function apply_keys() |
|
67
|
|
|
{ |
|
68
|
|
|
$xoops = Xoops::getInstance(); |
|
69
|
|
|
$db = $xoops->db(); |
|
|
|
|
|
|
70
|
|
|
$tables['modules'] = array('isactive', 'weight', 'hascomments'); |
|
|
|
|
|
|
71
|
|
|
$tables['users'] = array('level'); |
|
72
|
|
|
$tables['online'] = array('online_updated', 'online_uid'); |
|
73
|
|
|
$tables['config'] = array('conf_order'); |
|
74
|
|
|
$tables['xoopscomments'] = array('com_status'); |
|
75
|
|
|
|
|
76
|
|
|
foreach ($tables as $table => $keys) { |
|
77
|
|
|
$sql = "SHOW KEYS FROM `" . $xoops->db()->prefix($table) . "`"; |
|
78
|
|
|
if (!$result = $xoops->db()->queryF($sql)) { |
|
79
|
|
|
continue; |
|
80
|
|
|
} |
|
81
|
|
|
$existing_keys = array(); |
|
82
|
|
|
while ($row = $xoops->db()->fetchArray($result)) { |
|
83
|
|
|
$existing_keys[] = $row['Key_name']; |
|
84
|
|
|
} |
|
85
|
|
|
foreach ($keys as $key) { |
|
86
|
|
|
if (!in_array($key, $existing_keys)) { |
|
87
|
|
|
$sql = "ALTER TABLE `" . $xoops->db()->prefix($table) . "` ADD INDEX `{$key}` (`{$key}`)"; |
|
88
|
|
|
if (!$result = $xoops->db()->queryF($sql)) { |
|
|
|
|
|
|
89
|
|
|
return false; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
return true; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function __construct() |
|
98
|
|
|
{ |
|
99
|
|
|
xoopsUpgrade::__construct(basename(__DIR__)); |
|
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$upg = new upgrade_240(); |
|
104
|
|
|
return $upg; |
|
105
|
|
|
|