Conditions | 21 |
Paths | 40 |
Total Lines | 120 |
Code Lines | 63 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php declare(strict_types=1); |
||
53 | function xoops_module_update_publisher(\XoopsModule $module, ?string $previousVersion = null) |
||
54 | { |
||
55 | // global $GLOBALS['xoopsDB']; |
||
56 | $moduleDirName = \basename(\dirname(__DIR__)); |
||
57 | // $moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
||
58 | |||
59 | /** @var Helper $helper */ |
||
60 | /** @var Common\Configurator $configurator */ |
||
61 | $helper = Helper::getInstance(); |
||
62 | $configurator = new Common\Configurator(); |
||
63 | $utility = new Utility(); |
||
64 | $errors = 0; |
||
|
|||
65 | |||
66 | $helper->loadLanguage('common'); |
||
67 | $helper->loadLanguage('field'); |
||
68 | |||
69 | //delete .html entries from the tpl table |
||
70 | $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; |
||
71 | $GLOBALS['xoopsDB']->queryF($sql); |
||
72 | $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('newblocks') . " WHERE `dirname` = '" . $module->getVar('dirname', 'n') . "' AND `template` LIKE '%.html%'"; |
||
73 | $GLOBALS['xoopsDB']->queryF($sql); |
||
74 | |||
75 | if ($previousVersion <= 105) { |
||
76 | //change TEXT fields to NULL |
||
77 | $sql = ' ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_categories') . ' MODIFY `description` TEXT NULL'; |
||
78 | $GLOBALS['xoopsDB']->queryF($sql); |
||
79 | $sql = ' ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_categories') . ' MODIFY `header` TEXT NULL'; |
||
80 | $GLOBALS['xoopsDB']->queryF($sql); |
||
81 | $sql = ' ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_categories') . ' MODIFY `meta_keywords` TEXT NULL'; |
||
82 | $GLOBALS['xoopsDB']->queryF($sql); |
||
83 | $sql = ' ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_categories') . ' MODIFY `meta_description` TEXT NULL'; |
||
84 | $GLOBALS['xoopsDB']->queryF($sql); |
||
85 | |||
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 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
149 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
150 | |||
151 | return $grouppermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
||
152 | } |
||
153 | |||
154 | // check table items for field `dateexpire` |
||
155 | if (!$GLOBALS['xoopsDB']->query('SELECT dateexpire FROM ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_items'))) { |
||
156 | $sql = 'ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_items') . " ADD `dateexpire` INT(11) NULL DEFAULT '0' AFTER `datesub`"; |
||
157 | $GLOBALS['xoopsDB']->queryF($sql); |
||
158 | } |
||
159 | // check table items for field `votetype` |
||
160 | if (!$GLOBALS['xoopsDB']->query('SELECT votetype FROM ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_items'))) { |
||
161 | $sql = 'ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_items') . " ADD `votetype` TINYINT(1) NOT NULL DEFAULT '0' AFTER `item_tag`"; |
||
162 | $GLOBALS['xoopsDB']->queryF($sql); |
||
163 | } |
||
164 | |||
165 | // Publisher 1.8.0 |
||
166 | // check table items for field `template_item` for custom templates |
||
167 | if (!$GLOBALS['xoopsDB']->query('SELECT template_item FROM ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_categories'))) { |
||
168 | $sql = 'ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_categories') . " ADD `template_item` VARCHAR(150) NOT NULL DEFAULT '' AFTER `template`"; |
||
169 | $GLOBALS['xoopsDB']->queryF($sql); |
||
170 | } |
||
171 | |||
172 | return true; |
||
173 | } |
||
174 |