| Conditions | 17 |
| Paths | 96 |
| Total Lines | 135 |
| Code Lines | 82 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 32 | function xoops_module_update_profile(XoopsModule $module, $oldversion = null) |
||
| 33 | { |
||
| 34 | if ($oldversion < '1.6.2') { |
||
| 35 | $GLOBALS['xoopsDB']->queryF('UPDATE `' . $GLOBALS['xoopsDB']->prefix('profile_field') . ' SET field_valuetype=2 WHERE field_name=umode'); |
||
| 36 | } |
||
| 37 | |||
| 38 | if ($oldversion < '1.0.0') { |
||
| 39 | |||
| 40 | // Drop old category table |
||
| 41 | $sql = 'DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('profile_category'); |
||
| 42 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 43 | |||
| 44 | // Drop old field-category link table |
||
| 45 | $sql = 'DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('profile_fieldcategory'); |
||
| 46 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 47 | |||
| 48 | // Create new tables for new profile module |
||
| 49 | $GLOBALS['xoopsDB']->queryFromFile(XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/sql/mysql.sql'); |
||
| 50 | |||
| 51 | include_once __DIR__ . '/install.php'; |
||
| 52 | xoops_module_install_profile($module); |
||
| 53 | /* @var XoopsGroupPermHandler $goupperm_handler */ |
||
| 54 | $goupperm_handler = xoops_getHandler('groupperm'); |
||
| 55 | |||
| 56 | $field_handler = xoops_getModuleHandler('field', $module->getVar('dirname', 'n')); |
||
| 57 | $skip_fields = $field_handler->getUserVars(); |
||
| 58 | $skip_fields[] = 'newemail'; |
||
| 59 | $skip_fields[] = 'pm_link'; |
||
| 60 | $sql = 'SELECT * FROM `' . $GLOBALS['xoopsDB']->prefix('user_profile_field') . "` WHERE `field_name` NOT IN ('" . implode("', '", $skip_fields) . "')"; |
||
| 61 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
| 62 | if (!$GLOBALS['xoopsDB']->isResultSet($result)) { |
||
| 63 | \trigger_error("Query Failed! SQL: $sql- Error: " . $GLOBALS['xoopsDB']->error(), E_USER_ERROR); |
||
| 64 | } |
||
| 65 | $fields = array(); |
||
| 66 | while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 67 | $fields[] = $myrow['field_name']; |
||
| 68 | $object = $field_handler->create(); |
||
| 69 | $object->setVars($myrow, true); |
||
| 70 | $object->setVar('cat_id', 1); |
||
| 71 | if (!empty($myrow['field_register'])) { |
||
| 72 | $object->setVar('step_id', 2); |
||
| 73 | } |
||
| 74 | if (!empty($myrow['field_options'])) { |
||
| 75 | $object->setVar('field_options', unserialize($myrow['field_options'])); |
||
| 76 | } |
||
| 77 | $field_handler->insert($object, true); |
||
| 78 | |||
| 79 | $gperm_itemid = $object->getVar('field_id'); |
||
| 80 | $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('group_permission') . ' SET gperm_itemid = ' . $gperm_itemid . ' WHERE gperm_itemid = ' . $myrow['fieldid'] . ' AND gperm_modid = ' . $module->getVar('mid') . " AND gperm_name IN ('profile_edit', 'profile_search')"; |
||
| 81 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 82 | |||
| 83 | $groups_visible = $goupperm_handler->getGroupIds('profile_visible', $myrow['fieldid'], $module->getVar('mid')); |
||
| 84 | $groups_show = $goupperm_handler->getGroupIds('profile_show', $myrow['fieldid'], $module->getVar('mid')); |
||
| 85 | foreach ($groups_visible as $ugid) { |
||
| 86 | foreach ($groups_show as $pgid) { |
||
| 87 | $sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('profile_visibility') . ' (field_id, user_group, profile_group) ' . ' VALUES ' . " ({$gperm_itemid}, {$ugid}, {$pgid})"; |
||
| 88 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | //profile_install_setPermissions($object->getVar('field_id'), $module->getVar('mid'), $canedit, $visible); |
||
| 93 | unset($object); |
||
| 94 | } |
||
| 95 | |||
| 96 | // Copy data from profile table |
||
| 97 | foreach ($fields as $field) { |
||
| 98 | $GLOBALS['xoopsDB']->queryF('UPDATE `' . $GLOBALS['xoopsDB']->prefix('profile_profile') . '` u, `' . $GLOBALS['xoopsDB']->prefix('user_profile') . "` p SET u.{$field} = p.{$field} WHERE u.profile_id=p.profileid"); |
||
| 99 | } |
||
| 100 | |||
| 101 | // Drop old profile table |
||
| 102 | $sql = 'DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('user_profile'); |
||
| 103 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 104 | |||
| 105 | // Drop old field module |
||
| 106 | $sql = 'DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('user_profile_field'); |
||
| 107 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 108 | |||
| 109 | // Remove not used items |
||
| 110 | $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('group_permission') . ' WHERE `gperm_modid` = ' . $module->getVar('mid') . " AND `gperm_name` IN ('profile_show', 'profile_visible')"; |
||
| 111 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 112 | } |
||
| 113 | |||
| 114 | if ($oldversion < '1.6.2') { |
||
| 115 | $GLOBALS['xoopsDB']->queryF('UPDATE `' . $GLOBALS['xoopsDB']->prefix('profile_field') . "` SET `field_valuetype`=1 WHERE `field_name`='umode'"); |
||
| 116 | } |
||
| 117 | |||
| 118 | if ($oldversion < '1.8.6') { |
||
| 119 | // delete old html template files |
||
| 120 | $templateDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/templates/'; |
||
| 121 | $template_list = array_diff(scandir($templateDirectory), array('..', '.')); |
||
| 122 | foreach ($template_list as $k => $v) { |
||
| 123 | $fileinfo = new SplFileInfo($templateDirectory . $v); |
||
| 124 | if ($fileinfo->getExtension() === 'html' && $fileinfo->getFilename() !== 'index.html') { |
||
| 125 | @unlink($templateDirectory . $v); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | xoops_load('xoopsfile'); |
||
| 130 | //delete /images directory |
||
| 131 | $imagesDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/images/'; |
||
| 132 | $folderHandler = XoopsFile::getHandler('folder', $imagesDirectory); |
||
| 133 | $folderHandler->delete($imagesDirectory); |
||
| 134 | //delete /templates/style.css file |
||
| 135 | $cssFile = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/templates/style.css'; |
||
| 136 | $folderHandler = XoopsFile::getHandler('file', $cssFile); |
||
| 137 | $folderHandler->delete($cssFile); |
||
| 138 | //delete .html entries from the tpl table |
||
| 139 | $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; |
||
| 140 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 141 | } |
||
| 142 | |||
| 143 | if ($oldversion < '1.8.8') { |
||
| 144 | // update user_sig field to use dhtml editor |
||
| 145 | $tables = new Xmf\Database\Tables(); |
||
| 146 | $tables->useTable('profile_field'); |
||
| 147 | $criteria = new Criteria('field_name', 'user_sig', '='); |
||
| 148 | $tables->update('profile_field', array('field_type' => 'dhtml'), $criteria); |
||
| 149 | $tables->executeQueue(true); |
||
| 150 | } |
||
| 151 | |||
| 152 | if ($oldversion < '1.9.2') { |
||
| 153 | // decrease field_name field's size from 200 to 64 |
||
| 154 | $sql = 'ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('profile_field') . " CHANGE `field_name` `field_name` VARCHAR(64) NOT NULL DEFAULT ''"; |
||
| 155 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 156 | |||
| 157 | } |
||
| 158 | |||
| 159 | $profile_handler = xoops_getModuleHandler('profile', $module->getVar('dirname', 'n')); |
||
| 160 | $profile_handler->cleanOrphan($GLOBALS['xoopsDB']->prefix('users'), 'uid', 'profile_id'); |
||
| 161 | $field_handler = xoops_getModuleHandler('field', $module->getVar('dirname', 'n')); |
||
| 162 | $user_fields = $field_handler->getUserVars(); |
||
| 163 | $criteria = new Criteria('field_name', "('" . implode("', '", $user_fields) . "')", 'IN'); |
||
| 164 | $field_handler->updateAll('field_config', 0, $criteria); |
||
| 165 | |||
| 166 | return true; |
||
| 167 | } |
||
| 168 |