| Conditions | 18 |
| Paths | 7680 |
| Total Lines | 139 |
| Code Lines | 74 |
| 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 declare(strict_types=1); |
||
| 14 | function xoops_module_update_newbb_v400(XoopsModule $module) |
||
| 15 | { |
||
| 16 | $statsHandler = xoops_getModuleHandler('stats', 'newbb'); |
||
| 17 | |||
| 18 | $sql = 'SELECT `forum_id`, `forum_topics`, `forum_posts` FROM ' . $GLOBALS['xoopsDB']->prefix('bb_forums'); |
||
| 19 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
| 20 | if (!$GLOBALS['xoopsDB']->isResultSet($result)) { |
||
| 21 | \trigger_error("Query Failed! SQL: $sql- Error: " . $GLOBALS['xoopsDB']->error(), E_USER_ERROR); |
||
| 22 | } |
||
| 23 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 24 | $statsHandler->update($row['forum_id'], 'topic', $row['forum_topics']); |
||
|
|
|||
| 25 | $statsHandler->update($row['forum_id'], 'post', $row['forum_posts']); |
||
| 26 | } |
||
| 27 | |||
| 28 | $sql = 'SELECT `forum_id`, SUM(topic_views) AS views FROM ' . $GLOBALS['xoopsDB']->prefix('bb_topics') . ' GROUP BY `forum_id`'; |
||
| 29 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
| 30 | if (!$GLOBALS['xoopsDB']->isResultSet($result)) { |
||
| 31 | \trigger_error("Query Failed! SQL: $sql- Error: " . $GLOBALS['xoopsDB']->error(), E_USER_ERROR); |
||
| 32 | } |
||
| 33 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 34 | $statsHandler->update($row['forum_id'], 'view', $row['views']); |
||
| 35 | } |
||
| 36 | |||
| 37 | $sql = 'SELECT `forum_id`, COUNT(*) AS digests FROM ' . $GLOBALS['xoopsDB']->prefix('bb_topics') . ' WHERE topic_digest = 1 GROUP BY `forum_id`'; |
||
| 38 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
| 39 | if (!$GLOBALS['xoopsDB']->isResultSet($result)) { |
||
| 40 | \trigger_error("Query Failed! SQL: $sql- Error: " . $GLOBALS['xoopsDB']->error(), E_USER_ERROR); |
||
| 41 | } |
||
| 42 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 43 | $statsHandler->update($row['forum_id'], 'digest', $row['digests']); |
||
| 44 | } |
||
| 45 | |||
| 46 | $sql = 'SELECT SUM(forum_topics) AS topics, SUM(forum_posts) AS posts FROM ' . $GLOBALS['xoopsDB']->prefix('bb_forums'); |
||
| 47 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
| 48 | if (!$GLOBALS['xoopsDB']->isResultSet($result)) { |
||
| 49 | \trigger_error("Query Failed! SQL: $sql- Error: " . $GLOBALS['xoopsDB']->error(), E_USER_ERROR); |
||
| 50 | } |
||
| 51 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 52 | $statsHandler->update(-1, 'topic', $row['topics']); |
||
| 53 | $statsHandler->update(-1, 'post', $row['posts']); |
||
| 54 | } |
||
| 55 | |||
| 56 | /* |
||
| 57 | $GLOBALS['xoopsDB']->queryF( |
||
| 58 | " INSERT INTO ".$GLOBALS['xoopsDB']->prefix("bb_stats"). |
||
| 59 | " (`id`, `value`, `type`, `period`, `time_update`, `time_format`)". |
||
| 60 | " SELECT `forum_id`, `forum_topics`, '".NEWBB_STATS_TYPE_TOPIC."', '".NEWBB_STATS_PERIOD_TOTAL."', NOW() + 0, ''". |
||
| 61 | " FROM ".$GLOBALS['xoopsDB']->prefix("bb_forums") |
||
| 62 | ); |
||
| 63 | $GLOBALS['xoopsDB']->queryF( |
||
| 64 | " INSERT INTO ".$GLOBALS['xoopsDB']->prefix("bb_stats"). |
||
| 65 | " (`id`, `value`, `type`, `period`, `time_update`, `time_format`)". |
||
| 66 | " SELECT `forum_id`, `forum_posts`, '".NEWBB_STATS_TYPE_POST."', '".NEWBB_STATS_PERIOD_TOTAL."', NOW() + 0, ''". |
||
| 67 | " FROM ".$GLOBALS['xoopsDB']->prefix("bb_forums") |
||
| 68 | ); |
||
| 69 | $GLOBALS['xoopsDB']->queryF( |
||
| 70 | " INSERT INTO ".$GLOBALS['xoopsDB']->prefix("bb_stats"). |
||
| 71 | " (`id`, `value`, `type`, `period`, `time_update`, `time_format`)". |
||
| 72 | " SELECT `forum_id`, count(*), '".NEWBB_STATS_TYPE_DIGEST."', '".NEWBB_STATS_PERIOD_TOTAL."', NOW() + 0, ''". |
||
| 73 | " FROM ".$GLOBALS['xoopsDB']->prefix("bb_topics"). |
||
| 74 | " WHERE topic_digest = 1". |
||
| 75 | " GROUP BY `forum_id`". |
||
| 76 | ); |
||
| 77 | $GLOBALS['xoopsDB']->queryF( |
||
| 78 | " INSERT INTO ".$GLOBALS['xoopsDB']->prefix("bb_stats"). |
||
| 79 | " (`id`, `value`, `type`, `period`, `time_update`, `time_format`)". |
||
| 80 | " SELECT `forum_id`, SUM(topic_views), '".NEWBB_STATS_TYPE_VIEW."', '".NEWBB_STATS_PERIOD_TOTAL."', NOW() + 0, ''". |
||
| 81 | " FROM ".$GLOBALS['xoopsDB']->prefix("bb_topics"). |
||
| 82 | " WHERE topic_digest = 1". |
||
| 83 | " GROUP BY `forum_id`". |
||
| 84 | ); |
||
| 85 | */ |
||
| 86 | |||
| 87 | $sql = ' UPDATE ' |
||
| 88 | . $GLOBALS['xoopsDB']->prefix('bb_posts_text') |
||
| 89 | . ' AS t, ' |
||
| 90 | . $GLOBALS['xoopsDB']->prefix('bb_posts') |
||
| 91 | . ' AS p' |
||
| 92 | . ' SET t.dohtml = p.dohtml, ' |
||
| 93 | . ' t.dosmiley = p.dosmiley, ' |
||
| 94 | . ' t.doxcode = p.doxcode, ' |
||
| 95 | . ' t.doimage = p.doimage, ' |
||
| 96 | . ' t.dobr = p.dobr' |
||
| 97 | . ' WHERE p.post_id =t.post_id '; |
||
| 98 | if ($GLOBALS['xoopsDB']->queryF($sql)) { |
||
| 99 | $sql = ' ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('bb_posts') . ' DROP `dohtml`,' . ' DROP `dosmiley`,' . ' DROP `doxcode`,' . ' DROP `doimage`,' . ' DROP `dobr`'; |
||
| 100 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 101 | } else { |
||
| 102 | xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql); |
||
| 103 | } |
||
| 104 | |||
| 105 | if (\class_exists(\XoopsModules\Tag\TagHandler::class) && xoops_isActiveModule('tag')) { |
||
| 106 | $tagHandler = \XoopsModules\Tag\Helper::getInstance() |
||
| 107 | ->getHandler('Tag'); |
||
| 108 | $table_topic = $GLOBALS['xoopsDB']->prefix('bb_topics'); |
||
| 109 | $sql = ' SELECT topic_id, topic_tags' . " FROM {$table_topic}"; |
||
| 110 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
| 111 | if (!$GLOBALS['xoopsDB']->isResultSet($result)) { |
||
| 112 | xoops_error($GLOBALS['xoopsDB']->error()); |
||
| 113 | // \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); |
||
| 114 | |||
| 115 | } else { |
||
| 116 | while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 117 | if (empty($myrow['topic_tags'])) { |
||
| 118 | continue; |
||
| 119 | } |
||
| 120 | $tagHandler->updateByItem($myrow['topic_tags'], $myrow['topic_id'], $module->getVar('mid')); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | $sql = ' SELECT COUNT(*) |
||
| 126 | FROM ' . $GLOBALS['xoopsDB']->prefix('bb_type_tmp') . ' AS a, ' . $GLOBALS['xoopsDB']->prefix('bb_type_forum_tmp') . ' AS b |
||
| 127 | WHERE a.type_id = b.type_id AND a.type_id >0;'; |
||
| 128 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
| 129 | if (!$result) { |
||
| 130 | //xoops_error($GLOBALS['xoopsDB']->error()); |
||
| 131 | $GLOBALS['xoopsDB']->queryF('DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('bb_type_tmp')); |
||
| 132 | $GLOBALS['xoopsDB']->queryF('DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('bb_type_forum_tmp')); |
||
| 133 | |||
| 134 | return true; |
||
| 135 | } |
||
| 136 | |||
| 137 | $sql = ' INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('bb_type') . ' (`type_id`, `type_name`, `type_color`)' . ' SELECT `type_id`, `type_name`, `type_color`' . ' FROM ' . $GLOBALS['xoopsDB']->prefix('bb_type_tmp'); |
||
| 138 | $result = $GLOBALS['xoopsDB']->queryF($sql); |
||
| 139 | if (!$result){ |
||
| 140 | xoops_error($GLOBALS['xoopsDB']->error()); |
||
| 141 | } |
||
| 142 | |||
| 143 | $sql = ' INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('bb_type_forum') . ' (`type_id`, `forum_id`, `type_order`)' . ' SELECT `type_id`, `forum_id`, `type_order`' . ' FROM ' . $GLOBALS['xoopsDB']->prefix('bb_type_forum_tmp'); |
||
| 144 | $result = $GLOBALS['xoopsDB']->queryF($sql); |
||
| 145 | if (!$result){ |
||
| 146 | xoops_error($GLOBALS['xoopsDB']->error()); |
||
| 147 | } |
||
| 148 | |||
| 149 | $GLOBALS['xoopsDB']->queryF('DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('bb_type_tmp')); |
||
| 150 | $GLOBALS['xoopsDB']->queryF('DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('bb_type_forum_tmp')); |
||
| 151 | |||
| 152 | return true; |
||
| 153 | } |
||
| 154 |