/** * Sync contribs * * @param string $mode The mode (validated) * @param int|bool $contrib_id Contrib id to limit to * @param int|bool $start For indexing only * @param int|bool $limit For indexing only */ public function contribs($mode, $contrib_id = false, $start = false, $limit = false) { switch ($mode) { case 'validated': $sql = 'SELECT contrib_id, contrib_status FROM ' . $this->contribs_table . ($contrib_id ? ' AND contrib_id = ' . (int) $contrib_id : ''); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $sql = 'SELECT COUNT(revision_id) AS cnt FROM ' . $this->revisions_table . ' WHERE contrib_id = ' . $row['contrib_id'] . ' AND revision_status = ' . TITANIA_REVISION_APPROVED; $result1 = $this->db->sql_query($sql); $cnt = $this->db->sql_fetchfield('cnt', $result1); $this->db->sql_freeresult($result1); if ($cnt > 0 && $row['contrib_status'] == TITANIA_CONTRIB_NEW || $cnt == 0 && $row['contrib_status'] == TITANIA_CONTRIB_APPROVED) { $sql = 'UPDATE ' . $this->contribs_table . ' SET contrib_status = ' . ($cnt > 0 ? TITANIA_CONTRIB_APPROVED : TITANIA_CONTRIB_NEW) . ' WHERE contrib_id = ' . $row['contrib_id']; $this->db->sql_query($sql); } } $this->db->sql_freeresult($result); break; case 'faq_count': $contribs = array(); $sql = 'SELECT faq_access, contrib_id FROM ' . $this->contrib_faq_table; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $flags = count::update_flags($row['faq_access']); $contribs[$row['contrib_id']] = count::increment(isset($contribs[$row['contrib_id']]) ? $contribs[$row['contrib_id']] : '', $flags); } $this->db->sql_freeresult($result); foreach ($contribs as $contrib_id => $count) { $sql = 'UPDATE ' . $this->contribs_table . ' SET contrib_faq_count = \'' . $this->db->sql_escape($count) . '\' WHERE contrib_id = ' . $contrib_id; $this->db->sql_query($sql); } break; case 'index': $data = $contribs = array(); $sql = 'SELECT * FROM ' . $this->contribs_table . ' ORDER BY contrib_id ASC'; if ($start === false || $limit === false) { $result = $this->db->sql_query($sql); } else { $result = $this->db->sql_query_limit($sql, (int) $limit, (int) $start); } while ($row = $this->db->sql_fetchrow($result)) { $data[$row['contrib_id']] = array('object_type' => TITANIA_CONTRIB, 'object_id' => $row['contrib_id'], 'title' => $row['contrib_name'], 'text' => $row['contrib_desc'], 'text_uid' => $row['contrib_desc_uid'], 'text_bitfield' => $row['contrib_desc_bitfield'], 'text_options' => $row['contrib_desc_options'], 'author' => $row['contrib_user_id'], 'date' => $row['contrib_last_update'], 'url' => serialize(array('contrib_type' => $this->types->get($row['contrib_type'])->url, 'contrib' => $row['contrib_name_clean'])), 'approved' => in_array($row['contrib_status'], array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED)) ? true : false, 'categories' => explode(',', $row['contrib_categories'])); $contribs[] = $row['contrib_id']; } $this->db->sql_freeresult($result); $sql = 'SELECT DISTINCT contrib_id, phpbb_version_branch, phpbb_version_revision FROM ' . TITANIA_REVISIONS_PHPBB_TABLE . ' WHERE ' . $this->db->sql_in_set('contrib_id', $contribs) . ' AND revision_validated = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $phpbb_versions[$row['contrib_id']][] = $row; } $this->db->sql_freeresult($result); foreach ($data as $contrib_id => $contrib_data) { if (isset($phpbb_versions[$contrib_id])) { $data[$contrib_id]['phpbb_versions'] = versions::order_phpbb_version_list_from_db($this->cache, $phpbb_versions[$contrib_id]); } } $this->search_manager->mass_index($data); break; } }
/** * Update data or submit new faq * * @return void */ public function submit() { // Get the FAQ count to update it $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(); // If already submitted we need to decrement first if ($this->faq_id) { if (empty($this->sql_data)) { throw new exception('Modifying a FAQ entry requires you load it through the load() function (we require the original information).'); } $original_flags = count::update_flags($this->sql_data['faq_access']); $contrib_faq_count = count::decrement($contrib_faq_count, $original_flags); } // Update the FAQ count $flags = count::update_flags($this->faq_access); $sql = 'UPDATE ' . TITANIA_CONTRIBS_TABLE . ' SET contrib_faq_count = \'' . phpbb::$db->sql_escape(count::increment($contrib_faq_count, $flags)) . '\' WHERE contrib_id = ' . $this->contrib_id; phpbb::$db->sql_query($sql); // Submit this FAQ item parent::submit(); // Index $this->search_manager->index(TITANIA_FAQ, $this->faq_id, array('title' => $this->faq_subject, 'text' => $this->faq_text, 'text_uid' => $this->faq_text_uid, 'text_bitfield' => $this->faq_text_bitfield, 'text_options' => $this->faq_text_options, 'author' => 0, 'date' => 0, 'url' => serialize(array('contrib_type' => $this->contrib->type->url, 'contrib' => $this->contrib->contrib_name_clean)), 'access_level' => $this->faq_access)); }