|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
You may not change or alter any portion of this comment or credits |
|
5
|
|
|
of supporting developers from this source code or any supporting source code |
|
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
|
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
/** |
|
13
|
|
|
* tdmcreate module. |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
16
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
17
|
|
|
* |
|
18
|
|
|
* @since 2.5.0 |
|
19
|
|
|
* |
|
20
|
|
|
* @author Txmod Xoops http://www.txmodxoops.org |
|
21
|
|
|
* |
|
22
|
|
|
* @version $Id: update.php 12258 2014-01-02 09:33:29Z timgno $ |
|
23
|
|
|
* @param mixed $module |
|
24
|
|
|
* @param null|mixed $prev_version |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param $module |
|
29
|
|
|
* @param null $prev_version |
|
|
|
|
|
|
30
|
|
|
* |
|
31
|
|
|
* @return bool|null |
|
32
|
|
|
*/ |
|
33
|
|
|
function xoops_module_update_tdmcreate(&$module, $prev_version = null) |
|
34
|
|
|
{ |
|
35
|
|
|
// irmtfan bug fix: solve templates duplicate issue |
|
36
|
|
|
$ret = null; |
|
37
|
|
|
if ($prev_version < 191) { |
|
38
|
|
|
$ret = update_system_v191($module); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
$errors = $module->getErrors(); |
|
41
|
|
|
if (!empty($errors)) { |
|
42
|
|
|
print_r($errors); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return $ret; |
|
46
|
|
|
// irmtfan bug fix: solve templates duplicate issue |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
// irmtfan bug fix: solve templates duplicate issue |
|
50
|
|
|
/** |
|
51
|
|
|
* @param $module |
|
52
|
|
|
* |
|
53
|
|
|
* @return bool |
|
54
|
|
|
*/ |
|
55
|
|
|
function update_tdmcreate_v191(&$module) |
|
56
|
|
|
{ |
|
57
|
|
|
global $xoopsDB; |
|
58
|
|
|
$result = $xoopsDB->query( |
|
59
|
|
|
'SELECT t1.tpl_id FROM ' . $xoopsDB->prefix('tplfile') . ' t1, ' . $xoopsDB->prefix('tplfile') |
|
60
|
|
|
. ' t2 WHERE t1.tpl_refid = t2.tpl_refid AND t1.tpl_module = t2.tpl_module AND t1.tpl_tplset=t2.tpl_tplset AND t1.tpl_file = t2.tpl_file AND t1.tpl_type = t2.tpl_type AND t1.tpl_id > t2.tpl_id' |
|
61
|
|
|
); |
|
62
|
|
|
$tplids = []; |
|
63
|
|
|
while (list($tplid) = $xoopsDB->fetchRow($result)) { |
|
64
|
|
|
$tplids[] = $tplid; |
|
65
|
|
|
} |
|
66
|
|
|
if (count($tplids) > 0) { |
|
67
|
|
|
$tplfileHandler = xoops_getHandler('tplfile'); |
|
68
|
|
|
$duplicate_files = $tplfileHandler->getObjects( |
|
|
|
|
|
|
69
|
|
|
new \Criteria('tpl_id', '(' . implode(',', $tplids) . ')', 'IN') |
|
70
|
|
|
); |
|
71
|
|
|
|
|
72
|
|
|
if (count($duplicate_files) > 0) { |
|
73
|
|
|
foreach (array_keys($duplicate_files) as $i) { |
|
74
|
|
|
$tplfileHandler->delete($duplicate_files[$i]); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
$sql = 'SHOW INDEX FROM ' . $xoopsDB->prefix('tplfile') . " WHERE KEY_NAME = 'tpl_refid_module_set_file_type'"; |
|
79
|
|
|
if (!$result = $xoopsDB->queryF($sql)) { |
|
80
|
|
|
xoops_error($this->db->error() . '<br />' . $sql); |
|
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
return false; |
|
83
|
|
|
} |
|
84
|
|
|
$ret = []; |
|
85
|
|
|
while (false !== ($myrow = $xoopsDB->fetchArray($result))) { |
|
86
|
|
|
$ret[] = $myrow; |
|
87
|
|
|
} |
|
88
|
|
|
if (!empty($ret)) { |
|
89
|
|
|
$module->setErrors( |
|
90
|
|
|
"'tpl_refid_module_set_file_type' unique index is exist. Note: check 'tplfile' table to be sure this index is UNIQUE because XOOPS CORE need it." |
|
91
|
|
|
); |
|
92
|
|
|
|
|
93
|
|
|
return true; |
|
94
|
|
|
} |
|
95
|
|
|
$sql = 'ALTER TABLE ' . $xoopsDB->prefix('tplfile') |
|
96
|
|
|
. ' ADD UNIQUE tpl_refid_module_set_file_type ( tpl_refid, tpl_module, tpl_tplset, tpl_file, tpl_type )'; |
|
97
|
|
|
if (!$result = $xoopsDB->queryF($sql)) { |
|
|
|
|
|
|
98
|
|
|
xoops_error($xoopsDB->error() . '<br />' . $sql); |
|
99
|
|
|
$module->setErrors( |
|
100
|
|
|
"'tpl_refid_module_set_file_type' unique index is not added to 'tplfile' table. Warning: do not use XOOPS until you add this unique index." |
|
101
|
|
|
); |
|
102
|
|
|
|
|
103
|
|
|
return false; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return true; |
|
107
|
|
|
} |
|
108
|
|
|
// irmtfan bug fix: solve templates duplicate issue |
|
109
|
|
|
|