/** * Run tool * * @param ProgressHelper|null $progress * @return array */ public function run($progress = null) { $total = $this->get_total(); switch ($this->get_step()) { case 'truncate': $this->search_manager->truncate(); $display_message = 'TRUNCATING_SEARCH'; break; case 'contribs': $this->sync->contribs('index', false, $this->start, $this->limit); $display_message = 'INDEXING_CONTRIBS'; break; case 'posts': $this->sync->posts('index', $this->start, $this->limit); $display_message = 'INDEXING_POSTS'; break; case 'faqs': $this->sync->faqs('index', $this->start, $this->limit); $display_message = 'INDEXING_FAQ'; break; } $next_batch = $this->start + $this->limit; if ($total >= $next_batch) { if ($progress) { $progress->advance($this->limit); } return $this->get_result($display_message, $total, $next_batch, $this->get_step()); } $next_step = $this->get_next_step(); $next_batch = $next_step ? 0 : false; return $this->get_result($display_message, $total, $next_batch, $next_step); }
/** * Sync FAQ * * @param string $mode */ public function faqs($mode) { switch ($mode) { case 'index': $this->search_manager->truncate(TITANIA_FAQ); $data = array(); $sql = 'SELECT f.*, c.contrib_name_clean, c.contrib_type FROM ' . $this->contrib_faq_table . ' f, ' . $this->contribs_table . ' c WHERE c.contrib_id = f.contrib_id'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $data[] = array('object_type' => TITANIA_FAQ, 'object_id' => $row['faq_id'], 'title' => $row['faq_subject'], 'text' => $row['faq_text'], 'text_uid' => $row['faq_text_uid'], 'text_bitfield' => $row['faq_text_bitfield'], 'text_options' => $row['faq_text_options'], 'author' => 0, 'date' => 0, 'url' => serialize(array('contrib_type' => $this->types->get($row['contrib_type'])->url, 'contrib' => $row['contrib_name_clean'], 'id' => $row['faq_id'])), 'access_level' => $row['faq_access']); } $this->db->sql_freeresult($result); $this->search_manager->mass_index($data); break; } }