|
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
|
|
|
* userlog module |
|
13
|
|
|
* |
|
14
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
15
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
16
|
|
|
* @package userlog include |
|
17
|
|
|
* @since 1 |
|
18
|
|
|
* @author irmtfan ([email protected]) |
|
19
|
|
|
* @author XOOPS Project <www.xoops.org> <www.xoops.ir> |
|
20
|
|
|
*/ |
|
21
|
|
|
defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
|
22
|
|
|
require_once __DIR__ . '/common.php'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param XoopsModule $module |
|
26
|
|
|
* @param null $prev_version |
|
27
|
|
|
* |
|
28
|
|
|
* @return bool|mixed |
|
29
|
|
|
*/ |
|
30
|
|
|
|
|
31
|
|
|
function xoops_module_update_userlog(XoopsModule $module, $prev_version = null) |
|
32
|
|
|
{ |
|
33
|
|
|
if ($prev_version == round($module->getInfo('version') * 100, 2)) { |
|
34
|
|
|
$module->setErrors('You have the latest ' . $module->getInfo('name') . ' module (' . $module->getInfo('dirname') . ' version ' . $module->getInfo('version') . ') and update is not necessary'); |
|
35
|
|
|
print_r($module->getErrors()); |
|
36
|
|
|
|
|
37
|
|
|
return true; |
|
38
|
|
|
} |
|
39
|
|
|
$ret = true; |
|
40
|
|
|
// first db update |
|
41
|
|
|
if (100 == $prev_version) { |
|
42
|
|
|
$ret = update_userlog_v100($module); |
|
43
|
|
|
} |
|
44
|
|
|
if ($prev_version < 114) { |
|
45
|
|
|
$ret = update_userlog_v114($module); |
|
46
|
|
|
} |
|
47
|
|
|
if ($prev_version < 115) { |
|
48
|
|
|
$ret = update_userlog_v115($module); |
|
49
|
|
|
} |
|
50
|
|
|
if ($prev_version < 116) { |
|
51
|
|
|
$ret = update_userlog_v116($module); |
|
52
|
|
|
} |
|
53
|
|
|
$errors = $module->getErrors(); |
|
54
|
|
|
if (!empty($errors)) { |
|
55
|
|
|
print_r($errors); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $ret; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
// update database from v1 to 1.01 (Beta1 to RC1) |
|
62
|
|
|
// module_name VARCHAR(25) change to VARCHAR(50) |
|
63
|
|
|
/** |
|
64
|
|
|
* @param XoopsModule $module |
|
65
|
|
|
* |
|
66
|
|
|
* @return bool |
|
67
|
|
|
*/ |
|
68
|
|
View Code Duplication |
function update_userlog_v100(XoopsModule $module) |
|
69
|
|
|
{ |
|
70
|
|
|
$field = 'module_name'; |
|
71
|
|
|
$userlog = Userlog::getInstance(); |
|
72
|
|
|
$ret = $userlog->getHandler('log')->showFields($field); |
|
73
|
|
|
preg_match_all('!\d+!', $ret[$field]['Type'], $nums); |
|
74
|
|
|
// only change if module_name Type was VARCHAR(25) |
|
75
|
|
|
if (25 == $nums[0][0]) { |
|
76
|
|
|
$ret2 = $userlog->getHandler('log')->changeField($field, "VARCHAR(50) NOT NULL default ''"); |
|
77
|
|
|
} else { |
|
78
|
|
|
$ret2 = true; |
|
79
|
|
|
$module->setErrors("Your table field ({$field}) with size {$ret[$field]['Type']} don't need change."); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $ret2; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
// add ",active,inside,outside,unset_pass" to all settings |
|
86
|
|
|
/** |
|
87
|
|
|
* @param XoopsModule $module |
|
88
|
|
|
* |
|
89
|
|
|
* @return bool |
|
90
|
|
|
*/ |
|
91
|
|
View Code Duplication |
function update_userlog_v114(XoopsModule $module) |
|
92
|
|
|
{ |
|
93
|
|
|
$userlog = Userlog::getInstance(); |
|
94
|
|
|
$logsetsObj = $userlog->getHandler('setting')->getAll(); |
|
95
|
|
|
$ret = true; |
|
96
|
|
|
foreach ($logsetsObj as $setObj) { |
|
97
|
|
|
if (strpos($setObj->getVar('options'), 'active')) { |
|
98
|
|
|
continue; |
|
99
|
|
|
} |
|
100
|
|
|
$setObj->setVar('options', $setObj->getVar('options') . ',active,inside,outside,unset_pass'); |
|
101
|
|
|
if (!$setObj->storeSet(true)) { |
|
102
|
|
|
$ret = false; |
|
103
|
|
|
$module->setErrors(_AM_USERLOG_SET_ERROR . ' id=' . $setObj->set_id() . ' options=' . $setObj->options()); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return $ret; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @param XoopsModule $module |
|
112
|
|
|
* |
|
113
|
|
|
* @return mixed |
|
114
|
|
|
*/ |
|
115
|
|
View Code Duplication |
function update_userlog_v115(XoopsModule $module) |
|
116
|
|
|
{ |
|
117
|
|
|
$userlog = Userlog::getInstance(); |
|
118
|
|
|
// Only change the field from INDEX to UNIQUE if it is not unique |
|
119
|
|
|
// if (isset($indexArr[0]["Non_unique"]) || $indexArr[0]["Non_unique"] == 1) { } |
|
120
|
|
|
// change the index in _stats table |
|
121
|
|
|
if (!$ret = $userlog->getHandler('stats')->changeIndex('stats_type_link_period', ['stats_type', 'stats_link', 'stats_period'], 'UNIQUE')) { |
|
122
|
|
|
$module->setErrors("'stats_type_link_period' index is not changed to unique. Warning: do not use module until you change this index to unique."); |
|
123
|
|
|
} |
|
124
|
|
|
// drop the index in _log table |
|
125
|
|
|
if (!$ret = $userlog->getHandler('log')->dropIndex('log_id_uid')) { |
|
126
|
|
|
$module->setErrors("'log_id_uid' index is not dropped."); |
|
127
|
|
|
} |
|
128
|
|
|
// add the index in _log table |
|
129
|
|
|
if (!$ret = $userlog->getHandler('log')->addIndex('log_time', ['log_time'])) { |
|
130
|
|
|
$module->setErrors("'log_time' index is not added."); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
return $ret; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @param XoopsModule $module |
|
138
|
|
|
* |
|
139
|
|
|
* @return bool |
|
140
|
|
|
*/ |
|
141
|
|
View Code Duplication |
function update_userlog_v116(XoopsModule $module) |
|
142
|
|
|
{ |
|
143
|
|
|
// remove old html template files |
|
144
|
|
|
$template_directory = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/templates/'; |
|
145
|
|
|
$template_list = array_diff(scandir($template_directory, SCANDIR_SORT_NONE), ['..', '.']); |
|
146
|
|
|
foreach ($template_list as $k => $v) { |
|
147
|
|
|
$fileinfo = new SplFileInfo($template_directory . $v); |
|
148
|
|
|
if ('html' === $fileinfo->getExtension() && 'index.html' !== $fileinfo->getFilename()) { |
|
149
|
|
|
@unlink($template_directory . $v); |
|
|
|
|
|
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
return true; |
|
154
|
|
|
} |
|
155
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: