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