1
|
|
|
<?php declare(strict_types=1); |
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
|
|
|
* @author XOOPS Development Team |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
use Xmf\Database\Tables; |
19
|
|
|
use XoopsModules\Adslight\{ |
20
|
|
|
Common\Configurator, |
21
|
|
|
Common\Migrate, |
22
|
|
|
Helper, |
23
|
|
|
Utility |
24
|
|
|
}; |
25
|
|
|
|
26
|
|
|
/** @var Helper $helper */ |
27
|
|
|
/** @var Utility $utility */ |
28
|
|
|
/** @var Configurator $configurator */ |
29
|
|
|
if ((!defined('XOOPS_ROOT_PATH')) |
30
|
|
|
|| !($GLOBALS['xoopsUser'] instanceof \XoopsUser) |
31
|
|
|
|| !$GLOBALS['xoopsUser']->isAdmin()) { |
32
|
|
|
exit('Restricted access' . PHP_EOL); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $tablename |
37
|
|
|
*/ |
38
|
|
|
function tableExists($tablename): bool |
39
|
|
|
{ |
40
|
|
|
$result = $GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '{$tablename}'"); |
41
|
|
|
|
42
|
|
|
return $GLOBALS['xoopsDB']->getRowsNum($result) > 0; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Prepares system prior to attempting to install module |
47
|
|
|
* @param XoopsModule $module {@link XoopsModule} |
48
|
|
|
* |
49
|
|
|
* @return bool true if ready to install, false if not |
50
|
|
|
*/ |
51
|
|
|
function xoops_module_pre_update_adslight(\XoopsModule $module): bool |
52
|
|
|
{ |
53
|
|
|
$helper = Helper::getInstance(); |
|
|
|
|
54
|
|
|
$utility = new Utility(); |
55
|
|
|
|
56
|
|
|
$xoopsSuccess = $utility::checkVerXoops($module); |
|
|
|
|
57
|
|
|
$phpSuccess = $utility::checkVerPhp($module); |
|
|
|
|
58
|
|
|
|
59
|
|
|
$migrate = new Xmf\Database\Migrate('adslight'); |
60
|
|
|
$result = $migrate->synchronizeSchema(); |
|
|
|
|
61
|
|
|
|
62
|
|
|
return true; |
63
|
|
|
|
64
|
|
|
return $xoopsSuccess && $phpSuccess; |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Performs tasks required during update of the module |
69
|
|
|
* @param XoopsModule $module {@link XoopsModule} |
70
|
|
|
* @param null|string|int $previousVersion |
71
|
|
|
* |
72
|
|
|
* @return bool true if update successful, false if not |
73
|
|
|
*/ |
74
|
|
|
function xoops_module_update_adslight(\XoopsModule $module, $previousVersion = null): bool |
75
|
|
|
{ |
76
|
|
|
global $xoopsDB; |
77
|
|
|
$moduleDirName = \basename(\dirname(__DIR__)); |
78
|
|
|
$helper = Helper::getInstance(); |
|
|
|
|
79
|
|
|
$utility = new Utility(); |
80
|
|
|
$configurator = new Configurator(); |
81
|
|
|
|
82
|
|
|
$migrator = new Migrate(); |
83
|
|
|
$migrator->synchronizeSchema(); |
84
|
|
|
|
85
|
|
|
if ($previousVersion < 240) { |
86
|
|
|
//delete old HTML templates |
87
|
|
|
if (count($configurator->templateFolders) > 0) { |
88
|
|
|
foreach ($configurator->templateFolders as $folder) { |
89
|
|
|
$templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder); |
90
|
|
|
if (is_dir($templateFolder)) { |
91
|
|
|
$templateList = array_diff(scandir($templateFolder, SCANDIR_SORT_NONE), ['..', '.']); |
92
|
|
|
foreach ($templateList as $k => $v) { |
93
|
|
|
$fileInfo = new \SplFileInfo($templateFolder . $v); |
94
|
|
|
if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { |
95
|
|
|
if (is_file($templateFolder . $v)) { |
96
|
|
|
unlink($templateFolder . $v); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
// --- DELETE OLD FILES --------------- |
105
|
|
|
if (count($configurator->oldFiles) > 0) { |
106
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
107
|
|
|
foreach (array_keys($configurator->oldFiles) as $i) { |
108
|
|
|
$tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]); |
109
|
|
|
if (is_file($tempFile)) { |
110
|
|
|
unlink($tempFile); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
// --- DELETE OLD FOLDERS --------------- |
116
|
|
|
xoops_load('XoopsFile'); |
117
|
|
|
if (count($configurator->oldFolders) > 0) { |
118
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
119
|
|
|
foreach (array_keys($configurator->oldFolders) as $i) { |
120
|
|
|
$tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]); |
121
|
|
|
/** @var \XoopsObjectHandler $folderHandler */ |
122
|
|
|
$folderHandler = XoopsFile::getHandler('folder', $tempFolder); |
123
|
|
|
$folderHandler->delete($tempFolder); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
// --- CREATE FOLDERS --------------- |
128
|
|
|
if (count($configurator->uploadFolders) > 0) { |
129
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
130
|
|
|
foreach (array_keys($configurator->uploadFolders) as $i) { |
131
|
|
|
$utility::createFolder($configurator->uploadFolders[$i]); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
// --- COPY blank.png FILES --------------- |
136
|
|
|
if (count($configurator->copyBlankFiles) > 0) { |
137
|
|
|
$file = \dirname(__DIR__) . '/assets/images/blank.png'; |
138
|
|
|
foreach (array_keys($configurator->copyBlankFiles) as $i) { |
139
|
|
|
$dest = $configurator->copyBlankFiles[$i] . '/blank.png'; |
140
|
|
|
$utility::copyFile($file, $dest); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
//delete .html entries from the tpl table |
145
|
|
|
$sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; |
146
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
147
|
|
|
|
148
|
|
|
//delete .tpl entries from the tpl table |
149
|
|
|
$sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.tpl%'"; |
150
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
151
|
|
|
|
152
|
|
|
//delete tdmdownloads entries from the tpl_source table |
153
|
|
|
$sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplsource') . " WHERE `tpl_source` LIKE '%" . $module->getVar('dirname', 'n') . "%'"; |
154
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
155
|
|
|
|
156
|
|
|
//delete block entries from the newblocks table |
157
|
|
|
$sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('newblocks') . " WHERE `dirname` = '" . $module->getVar('dirname', 'n') . "'"; |
158
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
159
|
|
|
|
160
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
161
|
|
|
$grouppermHandler = xoops_getHandler('groupperm'); |
162
|
|
|
|
163
|
|
|
return $grouppermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
return true; |
167
|
|
|
} |
168
|
|
|
|