/** * Synchronize queue topic url values. * * @return bool|int */ protected function sync_contrib_topics($progress) { $i = 0; $topic_type_where = $this->db->sql_in_set('topic_type', array(TITANIA_SUPPORT, TITANIA_QUEUE_DISCUSSION)); $sql = 'SELECT contrib_id, contrib_type, contrib_name_clean FROM ' . $this->contribs_table; $result = $this->db->sql_query_limit($sql, $this->limit, $this->start); while ($row = $this->db->sql_fetchrow($result)) { $url = serialize(array('contrib_type' => $this->types->get($row['contrib_type'])->url, 'contrib' => $row['contrib_name_clean'])); $where = 'parent_id = ' . (int) $row['contrib_id'] . ' AND ' . $topic_type_where; $this->update_field($this->topics_table, 'topic', $url, $where); $i++; } $this->db->sql_freeresult($result); $sql = "SELECT topic_id, topic_url\n\t\t\tFROM {$this->topics_table}\n\t\t\tWHERE {$topic_type_where}"; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $where = 'topic_id = ' . (int) $row['topic_id']; $this->update_field($this->posts_table, 'post', $row['topic_url'], $where); if ($progress) { $progress->advance(); } } $this->db->sql_freeresult($result); if ($i === $this->limit) { return $this->start + $this->limit; } return false; }
/** * Get the contribution type of the category. * * @return \phpbb\titania\contribution\type\type_interface|bool False if the type couldn't be determined */ protected function get_category_type() { $children = $this->get_children_ids(); $type_id = $this->category->category_type; // If the category is the top most parent, we'll try to get the type from the first child if (!$type_id && !empty($children)) { $type_id = $this->categories[$children[0]]['category_type']; } return $type_id ? $this->types->get($type_id) : false; }
/** * Run the tool * * @param int $prev_contrib Previous contrib that was resynced * @param ProgressHelper|null $progress * @return array */ public function run($prev_contrib = 0, $progress = null) { $defaults = $this->get_defaults(); $total = $this->get_total(); // Reset counts to 0 if ($this->start == 0) { $this->reset_counts($defaults); } $batch = $this->get_batch(); foreach ($batch as $row) { if ($prev_contrib != $row['contrib_id']) { $this->update_contrib($row); } $type_count = ''; // Does the type have a field in the authors table for storing the type total? if (isset($this->types->get($row['contrib_type'])->author_count)) { $count_name = $this->types->get($row['contrib_type'])->author_count; $type_count = ", {$count_name} = {$count_name} +1"; } // Update owner's count if ($prev_contrib != $row['contrib_id']) { $this->increase_author_count($type_count, $row['contrib_user_id']); } // Update coauthor's count if (isset($row['user_id'])) { $this->increase_author_count($type_count, $row['user_id']); } if ($progress) { $progress->advance(); } $prev_contrib = $row['contrib_id']; } $next_batch = $this->start + $this->limit; if ($next_batch >= $total) { $result = $this->get_result('RESYNC_CONTRIB_COUNT_COMPLETE', $total, false); } else { $result = $this->get_result($this->user->lang('TOOL_PROGRESS_TOTAL', $next_batch, $total), $total, $next_batch); } $result['prev_contrib'] = $prev_contrib; return $result; }
/** * 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; } }
/** * Generate the category select (much is from the make_jumpbox function) * * @param array|bool $selected Array of selected categories. Defaults to false. * @param bool $is_manage Whether in category management, in which case all are listed * @param bool $disable_parents Whether to disable categories that do not have a contribution type * @param bool|int $category_type Category type to limit list to * @return void */ public function generate_category_select($selected = false, $is_manage = false, $disable_parents = true, $category_type = false) { if (!is_array($selected)) { $selected = array($selected); } $right = $padding = 0; $padding_store = array('0' => 0); $categories = $this->cache->get_categories(); $hidden_categories = array(); $category = new \titania_category(); foreach ($categories as $row) { $type = $this->types->get($row['category_type']); if ($type && (!$type->acl_get('submit') || $category_type && $type->id != $category_type)) { continue; } $category->__set_array($row); if ($row['left_id'] < $right) { $padding++; $padding_store[$row['parent_id']] = $padding; } else { if ($row['left_id'] > $right + 1) { $padding = isset($padding_store[$row['parent_id']]) ? $padding_store[$row['parent_id']] : $padding; } } $right = $row['right_id']; if (!$is_manage) { // Non-postable category with no children, don't display $not_postable = $row['category_type'] == 0 && $row['left_id'] + 1 == $row['right_id']; $hidden = !$row['category_visible'] || in_array($row['parent_id'], $hidden_categories); $team_only_restriction = $category->is_option_set('team_only') && !$type->acl_get('moderate'); if ($not_postable || $hidden || $team_only_restriction) { if ($hidden) { $hidden_categories[] = $row['category_id']; } continue; } } $this->template->assign_block_vars('category_select', array('S_SELECTED' => in_array($row['category_id'], $selected), 'S_DISABLED' => $row['category_type'] == 0 && $disable_parents, 'VALUE' => $row['category_id'], 'TYPE' => $row['category_type'], 'NAME' => $category->get_name())); for ($i = 0; $i < $padding; $i++) { $this->template->assign_block_vars('category_select.level', array()); } } }
/** * Get additional FAQ data. * * @param array $ids * @param array $documents * @return array */ protected function get_faqs(array $ids, array $documents) { if (!$ids) { return $documents; } $sql = 'SELECT f.faq_id AS id, f.faq_subject AS title, c.contrib_name_clean, c.contrib_type, f.faq_text AS text, f.faq_text_uid AS text_uid, f.faq_text_bitfield AS text_bitfield, f.faq_text_options AS text_options FROM ' . $this->contribs_table . ' c, ' . $this->faq_table . ' f WHERE ' . $this->db->sql_in_set('f.faq_id', $ids) . ' AND f.contrib_id = c.contrib_id'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $id = TITANIA_FAQ . '_' . $row['id']; $row['url'] = serialize(array('contrib_type' => $this->types->get($row['contrib_type'])->url, 'contrib' => $row['contrib_name_clean'], 'id' => $row['id'])); $documents[$id] = array_merge($documents[$id], $row); } $this->db->sql_freeresult($result); return $documents; }
/** * Get queue item template row. * * @param array $row * @return array */ protected function get_queue_tpl_row($row) { $queue_id = $row['watch_object_id']; $type = $this->types->get($queue_id); return array('SUBSCRIPTION_ID' => $queue_id, 'SUBSCRIPTION_TARGET' => $type->lang, 'SUBSCRIPTION_TIME' => $this->user->format_date($row['watch_mark_time']), 'SUBSCRIPTION_TITLE' => $this->user->lang['SUBSCRIPTION_QUEUE'], 'SUBSCRIPTION_TYPE' => $row['watch_object_type'], 'S_QUEUE' => true, 'S_ACCESS_TEAMS' => true, 'U_VIEW_SUBSCRIPTION' => $this->get_real_url($this->helper->route('phpbb.titania.queue.type', array('queue_type' => $type->url)))); }
/** * Dump include file. * * @param string $type Contrib type name * @param int $group Group id * @param array $packages Packages */ protected function dump_include($type, $group, array $packages) { $type_name = $this->types->get($type)->name; $this->repo->dump_include("packages-{$type_name}-{$group}.json", $packages); }
/** * Set the contribution type. * * @param int $type Contribution type id. * @return null */ public function set_type($type) { $this->contrib_type = $type; $this->type = $this->types->get($this->contrib_type); }
/** * Set the contribution type to generate stats for. * * @param string $type Contribution type URL value. * @return null */ protected function set_type($type) { $type = $this->types->type_from_url($type); $this->type = $type ? $this->types->get($type) : false; }
/** * Get the author contribs for the specified user id * * @param int $user_id The user ID * @param type_collection $types * @param \phpbb\user $user User object * @param bool $active True to request only active contributions, false for all * * @return array Array of contrib_id's */ public function get_author_contribs($user_id, type_collection $types, $user, $active = false) { $user_id = (int) $user_id; // We shall group authors by id in groups of 2500 $author_block_name = '_titania_authors_' . floor($user_id / 2500); if ($author_block = $this->driver->get($author_block_name) === false) { $author_block = array(); } if (!isset($author_block[$user_id])) { $author_block[$user_id] = array(); // Need to get the contribs for the selected author $sql = 'SELECT contrib_id, contrib_type, contrib_status FROM ' . TITANIA_CONTRIBS_TABLE . ' WHERE contrib_user_id = ' . $user_id; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $author_block[$user_id][$row['contrib_id']] = array('status' => $row['contrib_status'], 'active' => true, 'type' => $row['contrib_type']); } $this->db->sql_freeresult($result); // Now get the lists where the user is a co-author $sql = 'SELECT cc.contrib_id, c.contrib_status, c.contrib_type, cc.active FROM ' . TITANIA_CONTRIB_COAUTHORS_TABLE . ' cc, ' . TITANIA_CONTRIBS_TABLE . ' c WHERE cc.user_id = ' . $user_id . ' AND c.contrib_id = cc.contrib_id'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $author_block[$user_id][$row['contrib_id']] = array('status' => $row['contrib_status'], 'active' => $row['active'], 'type' => $row['contrib_type']); } $this->db->sql_freeresult($result); // Store the updated cache data $this->driver->put($author_block_name, $author_block); } $contribs = array(); foreach ($author_block[$user_id] as $contrib_id => $data) { // If approved, or new and doesn't require approval, or the user is viewing their own, or permission to view non-validated, add them to the list if ($user->data['user_id'] == $user_id || in_array($data['status'], array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED)) || $types->get($data['type'])->acl_get('view') || $types->get($data['type'])->acl_get('moderate')) { if (!$active || $data['active']) { $contribs[] = $contrib_id; } } } return $contribs; }