Conditions | 10 |
Paths | 7 |
Total Lines | 97 |
Code Lines | 66 |
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 |
||
82 | public function run() |
||
83 | { |
||
84 | if ($this->config['dark1_rsi_enable'] && ($this->config['dark1_rsi_time'] < (time() - $this->config['dark1_rsi_interval']))) |
||
85 | { |
||
86 | $this->config->set('dark1_rsi_time', (time() - $this->config['dark1_rsi_interval']), false); |
||
87 | $post_ids = $poster_ids = $topic_ids = $forum_ids = array(); |
||
88 | |||
89 | $sql = 'SELECT t.topic_id, p.post_id, p.poster_id, p.forum_id' . PHP_EOL . |
||
90 | 'FROM ' . POSTS_TABLE . ' as p' . PHP_EOL . |
||
91 | 'LEFT JOIN ' . TOPICS_TABLE . ' as t' . PHP_EOL . |
||
92 | 'ON t.topic_id = p.topic_id' . PHP_EOL . |
||
93 | 'LEFT JOIN ' . FORUMS_TABLE . ' as f' . PHP_EOL . |
||
94 | 'ON f.forum_id = p.forum_id' . PHP_EOL . |
||
95 | 'WHERE f.dark1_rsi_f_enable = 3 AND t.topic_time <= ' . (int) $this->config['dark1_rsi_time']; |
||
96 | $result = $this->db->sql_query($sql); |
||
97 | |||
98 | while ($row = $this->db->sql_fetchrow($result)) |
||
99 | { |
||
100 | $post_ids[] = (int) $row['post_id']; |
||
101 | $poster_ids[] = (int) $row['poster_id']; |
||
102 | $topic_ids[] = (int) $row['topic_id']; |
||
103 | $forum_ids[] = (int) $row['forum_id']; |
||
104 | } |
||
105 | $this->db->sql_freeresult($result); |
||
106 | |||
107 | $sql = 'SELECT p.post_id, p.poster_id, p.forum_id' . PHP_EOL . |
||
108 | 'FROM ' . POSTS_TABLE . ' as p' . PHP_EOL . |
||
109 | 'LEFT JOIN ' . TOPICS_TABLE . ' as t' . PHP_EOL . |
||
110 | 'ON t.topic_id = p.topic_id' . PHP_EOL . |
||
111 | 'LEFT JOIN ' . FORUMS_TABLE . ' as f' . PHP_EOL . |
||
112 | 'ON f.forum_id = p.forum_id' . PHP_EOL . |
||
113 | 'WHERE f.dark1_rsi_f_enable = 2 AND t.topic_time <= ' . (int) $this->config['dark1_rsi_time']; |
||
114 | $result = $this->db->sql_query($sql); |
||
115 | |||
116 | while ($row = $this->db->sql_fetchrow($result)) |
||
117 | { |
||
118 | $post_ids[] = (int) $row['post_id']; |
||
119 | $poster_ids[] = (int) $row['poster_id']; |
||
120 | $forum_ids[] = (int) $row['forum_id']; |
||
121 | } |
||
122 | $this->db->sql_freeresult($result); |
||
123 | |||
124 | $sql = 'SELECT p.post_id, p.poster_id, p.forum_id' . PHP_EOL . |
||
125 | 'FROM ' . POSTS_TABLE . ' as p' . PHP_EOL . |
||
126 | 'LEFT JOIN ' . FORUMS_TABLE . ' as f' . PHP_EOL . |
||
127 | 'ON f.forum_id = p.forum_id' . PHP_EOL . |
||
128 | 'WHERE f.dark1_rsi_f_enable = 1 AND p.post_time <= ' . (int) $this->config['dark1_rsi_time']; |
||
129 | $result = $this->db->sql_query($sql); |
||
130 | |||
131 | while ($row = $this->db->sql_fetchrow($result)) |
||
132 | { |
||
133 | $post_ids[] = (int) $row['post_id']; |
||
134 | $poster_ids[] = (int) $row['poster_id']; |
||
135 | $forum_ids[] = (int) $row['forum_id']; |
||
136 | } |
||
137 | $this->db->sql_freeresult($result); |
||
138 | |||
139 | $post_ids = $this->array_unique_sort($post_ids); |
||
140 | $poster_ids = $this->array_unique_sort($poster_ids); |
||
141 | $topic_ids = $this->array_unique_sort($topic_ids); |
||
142 | $forum_ids = $this->array_unique_sort($forum_ids); |
||
143 | |||
144 | // Lock Topics |
||
145 | if (count($topic_ids) > 0) |
||
146 | { |
||
147 | $sql = 'UPDATE ' . TOPICS_TABLE . PHP_EOL . |
||
148 | 'SET topic_status = ' . ITEM_LOCKED . PHP_EOL . |
||
149 | 'WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids); |
||
150 | $this->db->sql_query($sql); |
||
151 | } |
||
152 | |||
153 | // Remove the message from the search index |
||
154 | $search_type = $this->config['search_type']; |
||
155 | $identifier = substr($search_type, strrpos($search_type, '\\') + 1); |
||
156 | if ($identifier == 'fulltext_native' && class_exists($search_type)) |
||
157 | { |
||
158 | $error = false; |
||
159 | $phpbb_root_path = $this->phpbb_container->getParameter('core.root_path'); |
||
160 | $phpEx = $this->phpbb_container->getParameter('core.php_ext'); |
||
161 | $auth = $this->phpbb_container->get('auth'); |
||
162 | $user = $this->phpbb_container->get('user'); |
||
163 | $phpbb_dispatcher = $this->phpbb_container->get('dispatcher'); |
||
164 | |||
165 | $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $this->config, $this->db, $user, $phpbb_dispatcher); |
||
166 | if ($error == false) |
||
167 | { |
||
168 | @$search->index_remove($post_ids, $poster_ids, $forum_ids); |
||
169 | } |
||
170 | } |
||
171 | |||
172 | $dark1_rsi_interval = $this->config['dark1_rsi_interval'] / 86400; |
||
173 | $dark1_rsi_time = date('Y-m-d h:i:s A P', $this->config['dark1_rsi_time']); |
||
174 | $this->phpbb_log->add('admin', '', '', 'RSI_AUTO_LOG', time(), array($dark1_rsi_interval, $dark1_rsi_time)); |
||
175 | } |
||
176 | |||
177 | // Update the last backup time |
||
178 | $this->config->set('dark1_rsi_auto_reduce_sync_last_gc', time(), false); |
||
179 | } |
||
196 |