| Conditions | 12 |
| Paths | 192 |
| Total Lines | 113 |
| Code Lines | 55 |
| 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 |
||
| 14 | function xoops_module_update_newbb_v400(XoopsModule $module) |
||
| 15 | { |
||
| 16 | $statsHandler = xoops_getModuleHandler('stats', 'newbb'); |
||
| 17 | |||
| 18 | $result = $GLOBALS['xoopsDB']->query('SELECT `forum_id`, `forum_topics`, `forum_posts` FROM ' . $GLOBALS['xoopsDB']->prefix('bb_forums')); |
||
| 19 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 20 | $statsHandler->update($row['forum_id'], 'topic', $row['forum_topics']); |
||
|
|
|||
| 21 | $statsHandler->update($row['forum_id'], 'post', $row['forum_posts']); |
||
| 22 | } |
||
| 23 | $result = $GLOBALS['xoopsDB']->query('SELECT `forum_id`, SUM(topic_views) AS views FROM ' . $GLOBALS['xoopsDB']->prefix('bb_topics') . ' GROUP BY `forum_id`'); |
||
| 24 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 25 | $statsHandler->update($row['forum_id'], 'view', $row['views']); |
||
| 26 | } |
||
| 27 | $result = $GLOBALS['xoopsDB']->query('SELECT `forum_id`, COUNT(*) AS digests FROM ' . $GLOBALS['xoopsDB']->prefix('bb_topics') . ' WHERE topic_digest = 1 GROUP BY `forum_id`'); |
||
| 28 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 29 | $statsHandler->update($row['forum_id'], 'digest', $row['digests']); |
||
| 30 | } |
||
| 31 | $result = $GLOBALS['xoopsDB']->query('SELECT SUM(forum_topics) AS topics, SUM(forum_posts) AS posts FROM ' . $GLOBALS['xoopsDB']->prefix('bb_forums')); |
||
| 32 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 33 | $statsHandler->update(-1, 'topic', $row['topics']); |
||
| 34 | $statsHandler->update(-1, 'post', $row['posts']); |
||
| 35 | } |
||
| 36 | |||
| 37 | /* |
||
| 38 | $GLOBALS['xoopsDB']->queryF( |
||
| 39 | " INSERT INTO ".$GLOBALS['xoopsDB']->prefix("bb_stats"). |
||
| 40 | " (`id`, `value`, `type`, `period`, `time_update`, `time_format`)". |
||
| 41 | " SELECT `forum_id`, `forum_topics`, '".NEWBB_STATS_TYPE_TOPIC."', '".NEWBB_STATS_PERIOD_TOTAL."', NOW() + 0, ''". |
||
| 42 | " FROM ".$GLOBALS['xoopsDB']->prefix("bb_forums") |
||
| 43 | ); |
||
| 44 | $GLOBALS['xoopsDB']->queryF( |
||
| 45 | " INSERT INTO ".$GLOBALS['xoopsDB']->prefix("bb_stats"). |
||
| 46 | " (`id`, `value`, `type`, `period`, `time_update`, `time_format`)". |
||
| 47 | " SELECT `forum_id`, `forum_posts`, '".NEWBB_STATS_TYPE_POST."', '".NEWBB_STATS_PERIOD_TOTAL."', NOW() + 0, ''". |
||
| 48 | " FROM ".$GLOBALS['xoopsDB']->prefix("bb_forums") |
||
| 49 | ); |
||
| 50 | $GLOBALS['xoopsDB']->queryF( |
||
| 51 | " INSERT INTO ".$GLOBALS['xoopsDB']->prefix("bb_stats"). |
||
| 52 | " (`id`, `value`, `type`, `period`, `time_update`, `time_format`)". |
||
| 53 | " SELECT `forum_id`, count(*), '".NEWBB_STATS_TYPE_DIGEST."', '".NEWBB_STATS_PERIOD_TOTAL."', NOW() + 0, ''". |
||
| 54 | " FROM ".$GLOBALS['xoopsDB']->prefix("bb_topics"). |
||
| 55 | " WHERE topic_digest = 1". |
||
| 56 | " GROUP BY `forum_id`". |
||
| 57 | ); |
||
| 58 | $GLOBALS['xoopsDB']->queryF( |
||
| 59 | " INSERT INTO ".$GLOBALS['xoopsDB']->prefix("bb_stats"). |
||
| 60 | " (`id`, `value`, `type`, `period`, `time_update`, `time_format`)". |
||
| 61 | " SELECT `forum_id`, SUM(topic_views), '".NEWBB_STATS_TYPE_VIEW."', '".NEWBB_STATS_PERIOD_TOTAL."', NOW() + 0, ''". |
||
| 62 | " FROM ".$GLOBALS['xoopsDB']->prefix("bb_topics"). |
||
| 63 | " WHERE topic_digest = 1". |
||
| 64 | " GROUP BY `forum_id`". |
||
| 65 | ); |
||
| 66 | */ |
||
| 67 | |||
| 68 | $sql = ' UPDATE ' |
||
| 69 | . $GLOBALS['xoopsDB']->prefix('bb_posts_text') |
||
| 70 | . ' AS t, ' |
||
| 71 | . $GLOBALS['xoopsDB']->prefix('bb_posts') |
||
| 72 | . ' AS p' |
||
| 73 | . ' SET t.dohtml = p.dohtml, ' |
||
| 74 | . ' t.dosmiley = p.dosmiley, ' |
||
| 75 | . ' t.doxcode = p.doxcode, ' |
||
| 76 | . ' t.doimage = p.doimage, ' |
||
| 77 | . ' t.dobr = p.dobr' |
||
| 78 | . ' WHERE p.post_id =t.post_id '; |
||
| 79 | if ($GLOBALS['xoopsDB']->queryF($sql)) { |
||
| 80 | $sql = ' ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('bb_posts') . ' DROP `dohtml`,' . ' DROP `dosmiley`,' . ' DROP `doxcode`,' . ' DROP `doimage`,' . ' DROP `dobr`'; |
||
| 81 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 82 | } else { |
||
| 83 | xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql); |
||
| 84 | } |
||
| 85 | |||
| 86 | @require_once $GLOBALS['xoops']->path('modules/tag/include/functions.php'); |
||
| 87 | if (function_exists('tag_getTagHandler') && $tag_handler = tag_getTagHandler()) { |
||
| 88 | $table_topic = $GLOBALS['xoopsDB']->prefix('bb_topics'); |
||
| 89 | |||
| 90 | $sql = ' SELECT topic_id, topic_tags' . " FROM {$table_topic}"; |
||
| 91 | if (false === ($result = $GLOBALS['xoopsDB']->query($sql))) { |
||
| 92 | xoops_error($GLOBALS['xoopsDB']->error()); |
||
| 93 | } |
||
| 94 | while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 95 | if (empty($myrow['topic_tags'])) { |
||
| 96 | continue; |
||
| 97 | } |
||
| 98 | $tag_handler->updateByItem($myrow['topic_tags'], $myrow['topic_id'], $module->getVar('mid')); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | if (!$GLOBALS['xoopsDB']->query( |
||
| 103 | ' |
||
| 104 | SELECT COUNT(*) |
||
| 105 | FROM ' . $GLOBALS['xoopsDB']->prefix('bb_type_tmp') . ' AS a, ' . $GLOBALS['xoopsDB']->prefix('bb_type_forum_tmp') . ' AS b |
||
| 106 | WHERE a.type_id = b.type_id AND a.type_id >0; |
||
| 107 | ' |
||
| 108 | )) { |
||
| 109 | //xoops_error($GLOBALS['xoopsDB']->error()); |
||
| 110 | $GLOBALS['xoopsDB']->queryF('DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('bb_type_tmp')); |
||
| 111 | $GLOBALS['xoopsDB']->queryF('DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('bb_type_forum_tmp')); |
||
| 112 | |||
| 113 | return true; |
||
| 114 | } |
||
| 115 | |||
| 116 | $GLOBALS['xoopsDB']->queryF( |
||
| 117 | ' 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') |
||
| 118 | ); |
||
| 119 | $GLOBALS['xoopsDB']->queryF( |
||
| 120 | ' 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') |
||
| 121 | ); |
||
| 122 | |||
| 123 | $GLOBALS['xoopsDB']->queryF('DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('bb_type_tmp')); |
||
| 124 | $GLOBALS['xoopsDB']->queryF('DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('bb_type_forum_tmp')); |
||
| 125 | |||
| 126 | return true; |
||
| 127 | } |
||
| 128 |