/** * Run the tool * * @param ProgressHelper|null $progress * @return array */ public function run($progress = null) { if ($this->start == 0) { $this->db->sql_query('TRUNCATE ' . $this->topics_posted_table); } $insert_buffer = new sql_insert_buffer($this->db, $this->topics_posted_table); $batch = $this->get_batch(); $total = $this->get_total(); foreach ($batch as $row) { $insert_buffer->insert(array('topic_id' => (int) $row['topic_id'], 'user_id' => (int) $row['post_user_id'], 'topic_posted' => 1)); if ($progress) { $progress->advance(); } } $insert_buffer->flush(); $next_batch = $this->start + $this->limit; if ($next_batch >= $total) { return $this->get_result('RESYNC_DOTTED_TOPICS_COMPLETE', $total, false); } return $this->get_result($this->user->lang('TOOL_PROGRESS_TOTAL', $next_batch, $total), $total, $next_batch); }