Conditions | 20 |
Paths | 36 |
Total Lines | 119 |
Code Lines | 67 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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); |
||
62 | function xoops_module_update_suico( |
||
63 | XoopsModule $module, |
||
64 | $previousVersion = null |
||
65 | ) { |
||
66 | $moduleDirName = \basename(\dirname(__DIR__)); |
||
67 | $moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
||
68 | |||
69 | $helper = Helper::getInstance(); |
||
70 | $utility = new Utility(); |
||
71 | $configurator = new Configurator(); |
||
72 | $helper->loadLanguage('common'); |
||
73 | $migrator = new Migrate($configurator); |
||
74 | $migrator->synchronizeSchema(); |
||
75 | if ($previousVersion < 360) { |
||
76 | //rename column EXAMPLE |
||
77 | // $tables = new Tables(); |
||
78 | // $table = 'xxxx_categories'; |
||
79 | // $column = 'order'; |
||
80 | // $newName = 'order'; |
||
81 | // $attributes = "INT(5) NOT NULL DEFAULT '0'"; |
||
82 | // if ($tables->useTable($table)) { |
||
83 | // $tables->alterColumn($table, $column, $attributes, $newName); |
||
84 | // if (!$tables->executeQueue()) { |
||
85 | // echo '<br>' . constant('CO_' . $moduleDirNameUpper . '_UPGRADEFAILED0') . ' ' . $migrate->getLastError(); |
||
86 | // } |
||
87 | // } |
||
88 | //delete old HTML templates |
||
89 | if (count($configurator->templateFolders) > 0) { |
||
90 | foreach ($configurator->templateFolders as $folder) { |
||
91 | $templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder); |
||
92 | if (is_dir($templateFolder)) { |
||
93 | $templateList = array_diff(scandir($templateFolder, SCANDIR_SORT_NONE), ['..', '.']); |
||
94 | foreach ($templateList as $k => $v) { |
||
95 | $fileInfo = new SplFileInfo($templateFolder . $v); |
||
96 | if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { |
||
97 | if (is_file($templateFolder . $v)) { |
||
98 | if (false === @\unlink($templateFolder . $v)) { |
||
99 | throw new \RuntimeException('The file ' . $templateFolder . $v . ' could not be deleted.'); |
||
100 | } |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 | } |
||
107 | // --- DELETE OLD FILES --------------- |
||
108 | if (count($configurator->oldFiles) > 0) { |
||
109 | // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
||
110 | foreach ( |
||
111 | array_keys( |
||
112 | $configurator->oldFiles |
||
113 | ) as $i |
||
114 | ) { |
||
115 | $tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]); |
||
116 | if (is_file($tempFile)) { |
||
117 | if (false === @\unlink($tempFile)) { |
||
118 | throw new \RuntimeException('The file ' . $tempFile . ' could not be deleted.'); |
||
119 | } |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | // --- DELETE OLD FOLDERS --------------- |
||
124 | xoops_load('XoopsFile'); |
||
125 | if (count($configurator->oldFolders) > 0) { |
||
126 | // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
||
127 | foreach ( |
||
128 | array_keys( |
||
129 | $configurator->oldFolders |
||
130 | ) as $i |
||
131 | ) { |
||
132 | $tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]); |
||
133 | /** @var XoopsObjectHandler $folderHandler */ |
||
134 | $folderHandler = XoopsFile::getHandler( |
||
135 | 'folder', |
||
136 | $tempFolder |
||
137 | ); |
||
138 | $folderHandler->delete($tempFolder); |
||
139 | } |
||
140 | } |
||
141 | // --- CREATE UPLOAD FOLDERS --------------- |
||
142 | if (count($configurator->uploadFolders) > 0) { |
||
143 | // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
||
144 | foreach ( |
||
145 | array_keys( |
||
146 | $configurator->uploadFolders |
||
147 | ) as $i |
||
148 | ) { |
||
149 | $utility::createFolder($configurator->uploadFolders[$i]); |
||
150 | } |
||
151 | } |
||
152 | // --- COPY blank.png FILES --------------- |
||
153 | if (count($configurator->copyBlankFiles) > 0) { |
||
154 | $file = \dirname(__DIR__) . '/assets/images/blank.png'; |
||
155 | foreach (array_keys($configurator->copyBlankFiles) as $i) { |
||
156 | $dest = $configurator->copyBlankFiles[$i] . '/blank.png'; |
||
157 | $utility::copyFile($file, $dest); |
||
158 | } |
||
159 | } |
||
160 | //delete .html entries from the tpl table |
||
161 | $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix( |
||
162 | 'tplfile' |
||
163 | ) . " WHERE `tpl_module` = '" . $module->getVar( |
||
164 | 'dirname', |
||
165 | 'n' |
||
166 | ) . "' AND `tpl_file` LIKE '%.html%'"; |
||
167 | $GLOBALS['xoopsDB']->queryF($sql); |
||
168 | /** @var XoopsGroupPermHandler $grouppermHandler */ |
||
169 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
170 | |||
171 | return $grouppermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
||
172 | } |
||
173 | $profileHandler = $helper->getHandler('Profile'); |
||
174 | $profileHandler->cleanOrphan($GLOBALS['xoopsDB']->prefix('users'), 'uid', 'profile_id'); |
||
175 | $fieldHandler = $helper->getHandler('Field'); |
||
176 | $user_fields = $fieldHandler->getUserVars(); |
||
177 | $criteria = new Criteria('field_name', "('" . implode("', '", $user_fields) . "')", 'IN'); |
||
178 | $fieldHandler->updateAll('field_config', 0, $criteria); |
||
179 | |||
180 | return true; |
||
181 | } |
||
182 |