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: * @copyright XOOPS Project https://xoops.org/
14: * @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
15: * @package
16: * @since
17: * @author XOOPS Development Team, Kazumi Ono (AKA onokazu)
18: */
19:
20: /**
21: * @param $module
22: * @param null $prev_version
23: *
24: * @return bool|null
25: */
26: function xoops_module_update_system(XoopsModule $module, $prev_version = null)
27: {
28: // irmtfan bug fix: solve templates duplicate issue
29: $ret = null;
30: if ($prev_version < '2.1.1') {
31: $ret = update_system_v211($module);
32: }
33: $errors = $module->getErrors();
34: if (!empty($errors)) {
35: print_r($errors);
36: } else {
37: $ret = true;
38: }
39:
40: return $ret;
41: // irmtfan bug fix: solve templates duplicate issue
42: }
43:
44: // irmtfan bug fix: solve templates duplicate issue
45: /**
46: * @param $module
47: *
48: * @return bool
49: */
50: function update_system_v211($module)
51: {
52: global $xoopsDB;
53: $sql = 'SELECT t1.tpl_id FROM ' . $xoopsDB->prefix('tplfile') . ' t1, ' . $xoopsDB->prefix('tplfile') . ' 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';
54: $result = $xoopsDB->query($sql);
55: if (!$xoopsDB->isResultSet($result)) {
56: throw new \RuntimeException(
57: \sprintf(_DB_QUERY_ERROR, $sql) . $xoopsDB->error(), E_USER_ERROR
58: );
59: }
60: $tplids = array();
61: while (false !== (list($tplid) = $xoopsDB->fetchRow($result))) {
62: $tplids[] = $tplid;
63: }
64: if (count($tplids) > 0) {
65: $tplfile_handler = xoops_getHandler('tplfile');
66: $duplicate_files = $tplfile_handler->getObjects(new Criteria('tpl_id', '(' . implode(',', $tplids) . ')', 'IN'));
67:
68: if (count($duplicate_files) > 0) {
69: foreach (array_keys($duplicate_files) as $i) {
70: $tplfile_handler->delete($duplicate_files[$i]);
71: }
72: }
73: }
74: $sql = 'SHOW INDEX FROM ' . $xoopsDB->prefix('tplfile') . " WHERE KEY_NAME = 'tpl_refid_module_set_file_type'";
75: if (!$result = $xoopsDB->queryF($sql)) {
76: xoops_error($xoopsDB->error() . '<br>' . $sql);
77:
78: return false;
79: }
80: $ret = array();
81: while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
82: $ret[] = $myrow;
83: }
84: if (!empty($ret)) {
85: $module->setErrors("'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.");
86:
87: return true;
88: }
89: $sql = 'ALTER TABLE ' . $xoopsDB->prefix('tplfile') . ' ADD UNIQUE tpl_refid_module_set_file_type ( tpl_refid, tpl_module, tpl_tplset, tpl_file, tpl_type )';
90: if (!$result = $xoopsDB->queryF($sql)) {
91: xoops_error($xoopsDB->error() . '<br>' . $sql);
92: $module->setErrors("'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.");
93:
94: return false;
95: }
96:
97: return true;
98: }
99: // irmtfan bug fix: solve templates duplicate issue
100: