/** * 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); }
/** * Perform common set up tasks. * * @return null */ protected function setup() { // Add common lang $this->user->add_lang('search'); $this->user->add_lang_ext('phpbb/titania', 'search'); $this->manager->set_active_driver(); if (!$this->manager->search_enabled()) { throw new http_exception(200, 'SEARCH_UNAVAILABLE'); } $this->engine = $this->manager->get_active_driver(); // Available Search Types $this->search_types = array(TITANIA_CONTRIB => 'CONTRIBUTION_NAME_DESCRIPTION', TITANIA_FAQ => 'CONTRIB_FAQ'); if ($this->ext_config->support_in_titania) { $this->search_types[TITANIA_SUPPORT] = 'CONTRIB_SUPPORT'; } }
public function delete() { $this->search_manager->delete(TITANIA_FAQ, $this->faq_id); // Update the FAQ count $sql = 'SELECT contrib_faq_count FROM ' . TITANIA_CONTRIBS_TABLE . ' WHERE contrib_id = ' . $this->contrib_id; phpbb::$db->sql_query($sql); $contrib_faq_count = phpbb::$db->sql_fetchfield('contrib_faq_count'); phpbb::$db->sql_freeresult(); $flags = count::update_flags($this->faq_access); $sql = 'UPDATE ' . TITANIA_CONTRIBS_TABLE . ' SET contrib_faq_count = \'' . phpbb::$db->sql_escape(count::decrement($contrib_faq_count, $flags)) . '\' WHERE contrib_id = ' . $this->contrib_id; phpbb::$db->sql_query($sql); parent::delete(); }
/** * 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; } }
/** * Index this post */ public function index() { $this->search_manager->index($this->post_type, $this->post_id, array('parent_id' => $this->topic->parent_id, 'title' => $this->post_subject, 'text' => $this->post_text, 'text_uid' => $this->post_text_uid, 'text_bitfield' => $this->post_text_bitfield, 'text_options' => $this->post_text_options, 'author' => $this->post_user_id, 'date' => $this->post_time, 'url' => serialize($this->get_url_params()), 'access_level' => min($this->post_access, $this->topic->topic_access), 'approved' => $this->post_approved, 'reported' => $this->post_reported, 'parent_contrib_type' => $this->parent_contrib_type)); }
/** * Index the contribution */ public function index() { if (!sizeof($this->revisions)) { $this->get_revisions(); } $phpbb_versions = array(); foreach ($this->revisions as $revision) { if ($revision['revision_status'] == TITANIA_REVISION_APPROVED) { $phpbb_versions = array_merge($phpbb_versions, $revision['phpbb_versions']); } } $phpbb_versions = array_unique(versions::order_phpbb_version_list_from_db($this->cache, $phpbb_versions)); $data = array('title' => $this->contrib_name, 'text' => $this->contrib_desc, 'text_uid' => $this->contrib_desc_uid, 'text_bitfield' => $this->contrib_desc_bitfield, 'text_options' => $this->contrib_desc_options, 'author' => $this->contrib_user_id, 'date' => $this->contrib_last_update, 'url' => serialize(array('contrib_type' => $this->type->url, 'contrib' => $this->contrib_name_clean)), 'approved' => in_array($this->contrib_status, array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED)) ? true : false, 'categories' => explode(',', $this->contrib_categories), 'phpbb_versions' => $phpbb_versions); $this->search_manager->index(TITANIA_CONTRIB, $this->contrib_id, $data); }