|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits of |
|
4
|
|
|
supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit |
|
6
|
|
|
authors. |
|
7
|
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, but |
|
9
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Module: Waiting |
|
15
|
|
|
* |
|
16
|
|
|
* @category Module |
|
17
|
|
|
* @author XOOPS Module Development Team |
|
18
|
|
|
* @copyright {@link https://xoops.org 2001-2016 XOOPS Project} |
|
19
|
|
|
* @license {@link https://www.fsf.org/copyleft/gpl.html GNU public license} |
|
20
|
|
|
* @link https://xoops.org XOOPS |
|
21
|
|
|
*/ |
|
22
|
|
|
if ((!defined('XOOPS_ROOT_PATH')) || !($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
23
|
|
|
exit('Restricted Access - ' . basename($_SERVER['SCRIPT_NAME']) . PHP_EOL); |
|
24
|
|
|
} |
|
25
|
|
|
/** |
|
26
|
|
|
* Waiting Block installation update |
|
27
|
|
|
* @param \XoopsModule $module {@see XoopsModule} |
|
28
|
|
|
* @param int $version currently installed module version |
|
29
|
|
|
* |
|
30
|
|
|
* @return bool success |
|
31
|
|
|
*/ |
|
32
|
|
|
function xoops_module_update_waiting($module, $version) |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
return true; // force return - following code is really only needed for XOOPS < 2.3 |
|
35
|
|
|
// Keep Block option values when update (by nobunobu) |
|
36
|
|
|
$mid = $module->mid(); |
|
|
|
|
|
|
37
|
|
|
if ($mid) { |
|
38
|
|
|
/** @var \XoopsConfigHandler $configHandler */ |
|
39
|
|
|
$configHandler = xoops_getHandler('config'); |
|
40
|
|
|
$waitingModuleConfig = $configHandler->getConfigsByCat(0, $mid); |
|
41
|
|
|
|
|
42
|
|
|
$count = count($waitingModuleConfig['blocks']); |
|
43
|
|
|
|
|
44
|
|
|
/** @var \XoopsBlockHandler $blockHandler */ |
|
45
|
|
|
$blockHandler = xoops_getHandler('block'); |
|
46
|
|
|
$criteria = new \CriteriaCompo(); |
|
47
|
|
|
$criteria->add(new \Criteria('mid', $mid)); |
|
48
|
|
|
$criteria->add(new \Criteria('block_type', 'D')); |
|
49
|
|
|
$criteria->add(new \Criteria('func_num', $count, '>')); |
|
50
|
|
|
$blockObjs = $blockHandler->getAll($criteria); |
|
51
|
|
|
|
|
52
|
|
|
foreach ($blockObjs as $blockObj) { |
|
53
|
|
|
$local_msgs[] = "Non Defined Block <b>{$fblock['name']}</b> will be deleted"; |
|
54
|
|
|
$success = $blockHandler->delete($blockObj); // remove the invalid block |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$fieldsArray = ['func_num', 'name', 'options']; |
|
58
|
|
|
$criteria = new \CriteriaCompo(); |
|
59
|
|
|
$criteria->add(new \Criteria('mid', $mid)); |
|
60
|
|
|
// $criteria->add(new \Criteria('func_num', $i)); |
|
61
|
|
|
$criteria->add(new \Criteria('show_func'), addslashes($waitingModuleConfig['blocks'][$i]['show_func'])); |
|
62
|
|
|
$criteria->add(new \Criteria('func_file', addslashes($waitingModuleConfig['blocks'][$i]['file']))); |
|
63
|
|
|
$fblockObjs = $blockHandler->getObjects($criteria); |
|
64
|
|
|
foreach ($fblockObjs as $fblockObj) { |
|
65
|
|
|
if (!empty($fblockObj->options())) { |
|
66
|
|
|
$old_vals = explode('|', $fblockObj->getVar('options')); |
|
67
|
|
|
$def_vals = explode('|', $modversion['blocks'][$fblockObj->getVar('func_num')]['options']); |
|
68
|
|
|
if (count($old_vals) == count($def_vals)) { |
|
69
|
|
|
$modversion['blocks'][$fblock->getVar('func_num')]['options'] = $fblockObj->getVar('options'); |
|
70
|
|
|
$local_msgs[] = "Option's values of the block <b>" . $fblockObj->getVar('name') . '</b> will be kept. (value = <b>' . $fblockObj->getVar('options') . '</b>)'; |
|
71
|
|
|
} elseif (count($old_vals) < count($def_vals)) { |
|
72
|
|
|
$def_vals = array_merge($old_vals, $def_vals); //merges prev. values with new - older are preserved |
|
73
|
|
|
$modversion['blocks'][$fblockObj->getVar('func_num')]['options'] = implode('|', $def_vals); |
|
74
|
|
|
$local_msgs[] = "Option's values of the block " |
|
75
|
|
|
. '<b>' |
|
76
|
|
|
. $fblockObj->getVar('name') |
|
77
|
|
|
. '</b> ' |
|
78
|
|
|
. 'will be kept and new option(s) are added. (value = ' |
|
79
|
|
|
. '<b>' |
|
80
|
|
|
. $waitingModuleConfig['blocks'][$fblockObj->getVar('options')] |
|
81
|
|
|
. '</b>)'; |
|
82
|
|
|
} else { |
|
83
|
|
|
$local_msgs[] = "Option's values of the block " . '<b>' . $fblockObj->getVar('name') . '</b> ' . 'will be reset to the default, because of some decrease of options. (value = ' . '<b>' . $waitingModuleConfig['blocks'][$fblockObj->getVar('func_num')]['options'] . '</b>)'; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
global $msgs, $myblocksadmin_parsed_updateblock; |
|
90
|
|
|
if (!empty($msgs) && empty($myblocksadmin_parsed_updateblock)) { |
|
91
|
|
|
$msgs = array_merge($msgs, $local_msgs); |
|
92
|
|
|
$myblocksadmin_parsed_updateblock = true; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return true; //@todo: for now force success - eventually send 'actual' results |
|
96
|
|
|
} |
|
97
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.