From 6d23cc3a0e6c71bebc239d3b6ecd55f05f4b98d4 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sun, 22 Jun 2014 17:55:30 +0530 Subject: [PATCH 01/12] [ticket/12759] Allow multiple fields to be loaded via get_option_lang PHPBB3-12759 --- phpBB/phpbb/profilefields/lang_helper.php | 21 ++++++++++++++----- phpBB/phpbb/profilefields/type/type_bool.php | 4 ++-- .../profilefields/type/type_dropdown.php | 6 +++--- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index c055931181..9e4991e94a 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -51,7 +51,7 @@ class lang_helper /** * Get language entries for options and store them here for later use */ - public function get_option_lang($field_id, $lang_id, $field_type, $preview_options) + public function get_option_lang($field_id, $lang_id, $preview_options) { if ($preview_options !== false) { @@ -72,17 +72,28 @@ class lang_helper } else { - $sql = 'SELECT option_id, lang_value + if (is_array($field_id)) + { + foreach ($field_id as $k => $id) + { + $field_id[$k] = (int) $id; + } + } + else + { + $field_id = array((int) $field_id); + } + + $sql = 'SELECT field_id, option_id, lang_value FROM ' . $this->language_table . ' - WHERE field_id = ' . (int) $field_id . ' + WHERE ' . $this->db->sql_in_set('field_id', $field_id) . ' AND lang_id = ' . (int) $lang_id . " - AND field_type = '" . $this->db->sql_escape($field_type) . "' ORDER BY option_id"; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - $this->options_lang[$field_id][$lang_id][($row['option_id'] + 1)] = $row['lang_value']; + $this->options_lang[$row['field_id']][$lang_id][($row['option_id'] + 1)] = $row['lang_value']; } $this->db->sql_freeresult($result); } diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index eb8d3e47d6..86e480f6b3 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -155,7 +155,7 @@ class type_bool extends type_base if (!$this->lang_helper->is_set($field_id, $lang_id)) { - $this->lang_helper->get_option_lang($field_id, $lang_id, FIELD_BOOL, false); + $this->lang_helper->get_option_lang($field_id, $lang_id, false); } if (!$field_value && $field_data['field_show_novalue']) @@ -203,7 +203,7 @@ class type_bool extends type_base { if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $this->get_service_name(), $preview_options); + $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $preview_options); } $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']); diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 52c9fcf86a..5ecbf4e167 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -135,7 +135,7 @@ class type_dropdown extends type_base // retrieve option lang data if necessary if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], 1)) { - $this->lang_helper->get_option_lang($field_data['field_id'], $field_data['lang_id'], $this->get_service_name(), false); + $this->lang_helper->get_option_lang($field_data['field_id'], $field_data['lang_id'], false); } if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], $field_value)) @@ -160,7 +160,7 @@ class type_dropdown extends type_base $lang_id = $field_data['lang_id']; if (!$this->lang_helper->is_set($field_id, $lang_id)) { - $this->lang_helper->get_option_lang($field_id, $lang_id, $this->get_service_name(), false); + $this->lang_helper->get_option_lang($field_id, $lang_id, false); } if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) @@ -199,7 +199,7 @@ class type_dropdown extends type_base if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $this->get_service_name(), $preview_options); + $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $preview_options); } $profile_row['field_value'] = (int) $value; From 6cf6ec33545ae3be2cd6f02f0c23f154006a29cf Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sun, 22 Jun 2014 18:13:01 +0530 Subject: [PATCH 02/12] [ticket/12759] Cache lang options for all fields while displaying Previously these would be fetched one field at one time, causing a large number of queries in case there were large number of custom profile fields and/or unique number of users in areas such as viewing topics. Resolve this by caching them at once when generating data for displaying them in templates. PHPBB3-12759 --- phpBB/config/profilefields.yml | 1 + phpBB/phpbb/profilefields/manager.php | 29 ++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/phpBB/config/profilefields.yml b/phpBB/config/profilefields.yml index ce2a84b12b..2ed8ca5600 100644 --- a/phpBB/config/profilefields.yml +++ b/phpBB/config/profilefields.yml @@ -5,6 +5,7 @@ services: - @auth - @dbal.conn - @dispatcher + - @profilefields.lang_helper - @request - @template - @profilefields.type_collection diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 490db0419a..a32baaac56 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -36,6 +36,12 @@ class manager */ protected $dispatcher; + /** + * Profile fields language helper + * @var \phpbb\profilefields\lang_helper + */ + protected $lang_helper; + /** * Request object * @var \phpbb\request\request @@ -74,6 +80,7 @@ class manager * @param \phpbb\auth\auth $auth Auth object * @param \phpbb\db\driver\driver_interface $db Database object * @param \phpbb\event\dispatcher $dispatcher Event dispatcher object + * @param \phpbb\profilefields\lang_helper $lang_helper Language helper object * @param \phpbb\request\request $request Request object * @param \phpbb\template\template $template Template object * @param \phpbb\di\service_collection $type_collection @@ -82,11 +89,12 @@ class manager * @param string $fields_language_table * @param string $fields_data_table */ - public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher $dispatcher, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) + public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher $dispatcher, \phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) { $this->auth = $auth; $this->db = $db; $this->dispatcher = $dispatcher; + $this->lang_helper = $lang_helper; $this->request = $request; $this->template = $template; $this->type_collection = $type_collection; @@ -385,6 +393,25 @@ class manager $vars = array('profile_row', 'tpl_fields', 'use_contact_fields'); extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_data_before', compact($vars))); + if (!empty($profile_row)) + { + $field_ids = array(); + foreach ($profile_row as $ident_ary) + { + if (empty($field_ids[$ident_ary['data']['lang_id']])) + { + $field_ids[$ident_ary['data']['lang_id']] = array(); + + } + $field_ids[$ident_ary['data']['lang_id']][] = $ident_ary['data']['field_id']; + } + + foreach ($field_ids as $lang => $fields) + { + $this->lang_helper->get_option_lang($fields, $lang, false); + } + } + foreach ($profile_row as $ident => $ident_ary) { $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; From aebe03f88cb3c2aee6e0b859be82d5235efdacea Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sun, 22 Jun 2014 18:55:35 +0530 Subject: [PATCH 03/12] [ticket/12759] Cache the lang options earlier Previously it would re-run on every post PHPBB3-12759 --- phpBB/phpbb/profilefields/manager.php | 47 ++++++++++++++++----------- phpBB/viewtopic.php | 8 ++++- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index a32baaac56..f14aa2a2b4 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -367,6 +367,34 @@ class manager return $user_fields; } + /** + * Cache user's profile fields' language options + * @param array $profile_row Array with users profile field data + * @return void + */ + public function cache_profile_fields_lang_options($profile_row) + { + if (!empty($profile_row)) + { + $field_ids = array(); + foreach ($profile_row as $ident_ary) + { + if (empty($field_ids[$ident_ary['data']['lang_id']])) + { + $field_ids[$ident_ary['data']['lang_id']] = array(); + + } + + $field_ids[$ident_ary['data']['lang_id']][] = $ident_ary['data']['field_id']; + } + + foreach ($field_ids as $lang => $fields) + { + $this->lang_helper->get_option_lang($fields, $lang, false); + } + } + } + /** * Assign the user's profile fields data to the template * @@ -393,25 +421,6 @@ class manager $vars = array('profile_row', 'tpl_fields', 'use_contact_fields'); extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_data_before', compact($vars))); - if (!empty($profile_row)) - { - $field_ids = array(); - foreach ($profile_row as $ident_ary) - { - if (empty($field_ids[$ident_ary['data']['lang_id']])) - { - $field_ids[$ident_ary['data']['lang_id']] = array(); - - } - $field_ids[$ident_ary['data']['lang_id']][] = $ident_ary['data']['field_id']; - } - - foreach ($field_ids as $lang => $fields) - { - $this->lang_helper->get_option_lang($fields, $lang, false); - } - } - foreach ($profile_row as $ident => $ident_ary) { $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index d87f7de2b0..760b4e5c87 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1270,6 +1270,7 @@ if ($config['load_cpf_viewtopic']) // filter out fields not to be displayed on viewtopic. Yes, it's a hack, but this shouldn't break any MODs. $profile_fields_cache = array(); + $profile_rows = array(); foreach ($profile_fields_tmp as $profile_user_id => $profile_fields) { $profile_fields_cache[$profile_user_id] = array(); @@ -1278,10 +1279,15 @@ if ($config['load_cpf_viewtopic']) if ($profile_field['data']['field_show_on_vt']) { $profile_fields_cache[$profile_user_id][$used_ident] = $profile_field; + $profile_rows[] = $profile_field; } } } - unset($profile_fields_tmp); + + // Cache the language options for optimisation + $cp->cache_profile_fields_lang_options($profile_rows); + + unset($profile_fields_tmp, $profile_rows); } // Generate online information for user From 6251d68be431704086477d143cddadcc1fcebb33 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sun, 22 Jun 2014 19:04:28 +0530 Subject: [PATCH 04/12] [ticket/12759] Make sure $field_id has unique elements Otherwise it would cause a bunch of repetitive IDs passed to the IN clause PHPBB3-12759 --- phpBB/phpbb/profilefields/lang_helper.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index 9e4991e94a..b950ace872 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -78,6 +78,7 @@ class lang_helper { $field_id[$k] = (int) $id; } + $field_id = array_unique($field_id); } else { From 51bc31da20c402b820d8af41ca7d4bfdb7caaed2 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sun, 22 Jun 2014 19:08:55 +0530 Subject: [PATCH 05/12] [ticket/12759] Little code cleanup PHPBB3-12759 --- phpBB/phpbb/profilefields/lang_helper.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index b950ace872..2ea3066f94 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -74,11 +74,7 @@ class lang_helper { if (is_array($field_id)) { - foreach ($field_id as $k => $id) - { - $field_id[$k] = (int) $id; - } - $field_id = array_unique($field_id); + $field_id = array_map('intval', array_unique($field_id)); } else { From c82a0b74cfc009af61aa1bfc5e220ec82b441f7a Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sun, 22 Jun 2014 19:18:08 +0530 Subject: [PATCH 06/12] [ticket/12759] Add phpDoc comments to explain get_option_lang PHPBB3-12759 --- phpBB/phpbb/profilefields/lang_helper.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index 2ea3066f94..86c4e6ff72 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -50,6 +50,10 @@ class lang_helper /** * Get language entries for options and store them here for later use + * + * @param mixed $field_id Can be an int or an array of int for multiple field IDs + * @param int $lang_id + * @param mixed $preview_options If set to not false, $field_id cannot be an array */ public function get_option_lang($field_id, $lang_id, $preview_options) { From 7484859c71d092c378f1fd25392e604c4ffdd931 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Mon, 23 Jun 2014 00:23:15 +0530 Subject: [PATCH 07/12] [ticket/12759] Cache lang_options on memberlist PHPBB3-12759 --- phpBB/memberlist.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 63541dbee6..e42c7fab0c 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -1382,6 +1382,7 @@ switch ($mode) { // Grab all profile fields from users in id cache for later use - similar to the poster cache $profile_fields_cache = $cp->grab_profile_fields_data($user_list); + $profile_rows = array(); // Filter the fields we don't want to show foreach ($profile_fields_cache as $user_id => $user_profile_fields) @@ -1392,8 +1393,14 @@ switch ($mode) { unset($profile_fields_cache[$user_id][$field_ident]); } + else + { + $profile_rows[] = $profile_field; + } } } + + $cp->cache_profile_fields_lang_options($profile_rows); } // If we sort by last active date we need to adjust the id cache due to user_lastvisit not being the last active date... From f776ac7d5862cbb8be7b78db6a46655f4aaa225a Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Mon, 23 Jun 2014 01:08:39 +0530 Subject: [PATCH 08/12] [ticket/12759] Cache lang_options for pm_viewmessage PHPBB3-12759 --- phpBB/includes/ucp/ucp_pm_viewmessage.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index f42200d249..9e26b3b129 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -68,6 +68,8 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) $cp = $phpbb_container->get('profilefields.manager'); $profile_fields = $cp->grab_profile_fields_data($author_id); + + $cp->cache_profile_fields_lang_options($profile_fields[$author_id]); } // Assign TO/BCC Addresses to template From c1df2ce62a62517e840ff30fa11a6cffb84396bc Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Mon, 23 Jun 2014 13:32:46 +0530 Subject: [PATCH 09/12] [ticket/12759] Extra line in profilefields_manager PHPBB3-12759 --- phpBB/phpbb/profilefields/manager.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index f14aa2a2b4..251899146b 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -382,7 +382,6 @@ class manager if (empty($field_ids[$ident_ary['data']['lang_id']])) { $field_ids[$ident_ary['data']['lang_id']] = array(); - } $field_ids[$ident_ary['data']['lang_id']][] = $ident_ary['data']['field_id']; From 2cf4a4f6fe74ee6d774956113570d6ed7c5246cc Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Thu, 26 Jun 2014 03:07:45 +0530 Subject: [PATCH 10/12] [ticket/12759] Cache all lang_options in lang_helper instead PHPBB3-12759 --- phpBB/includes/ucp/ucp_pm_viewmessage.php | 2 - phpBB/memberlist.php | 7 -- phpBB/phpbb/profilefields/lang_helper.php | 67 +++++++++---------- phpBB/phpbb/profilefields/manager.php | 27 -------- phpBB/phpbb/profilefields/type/type_bool.php | 4 +- .../profilefields/type/type_dropdown.php | 6 +- phpBB/viewtopic.php | 8 +-- 7 files changed, 37 insertions(+), 84 deletions(-) diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index 9e26b3b129..f42200d249 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -68,8 +68,6 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) $cp = $phpbb_container->get('profilefields.manager'); $profile_fields = $cp->grab_profile_fields_data($author_id); - - $cp->cache_profile_fields_lang_options($profile_fields[$author_id]); } // Assign TO/BCC Addresses to template diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index e42c7fab0c..63541dbee6 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -1382,7 +1382,6 @@ switch ($mode) { // Grab all profile fields from users in id cache for later use - similar to the poster cache $profile_fields_cache = $cp->grab_profile_fields_data($user_list); - $profile_rows = array(); // Filter the fields we don't want to show foreach ($profile_fields_cache as $user_id => $user_profile_fields) @@ -1393,14 +1392,8 @@ switch ($mode) { unset($profile_fields_cache[$user_id][$field_ident]); } - else - { - $profile_rows[] = $profile_field; - } } } - - $cp->cache_profile_fields_lang_options($profile_rows); } // If we sort by last active date we need to adjust the id cache due to user_lastvisit not being the last active date... diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index 86c4e6ff72..2e353722b2 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -49,55 +49,50 @@ class lang_helper } /** - * Get language entries for options and store them here for later use + * Loads preview options into language entries for options * - * @param mixed $field_id Can be an int or an array of int for multiple field IDs + * @param int $field_id * @param int $lang_id - * @param mixed $preview_options If set to not false, $field_id cannot be an array + * @param mixed $preview_options */ - public function get_option_lang($field_id, $lang_id, $preview_options) + public function load_preview_options($field_id, $lang_id, $preview_options) { - if ($preview_options !== false) - { - $lang_options = (!is_array($preview_options)) ? explode("\n", $preview_options) : $preview_options; + $lang_options = (!is_array($preview_options)) ? explode("\n", $preview_options) : $preview_options; - foreach ($lang_options as $num => $var) + foreach ($lang_options as $num => $var) + { + if (!isset($this->options_lang[$field_id])) { - if (!isset($this->options_lang[$field_id])) - { - $this->options_lang[$field_id] = array(); - } - if (!isset($this->options_lang[$field_id][$lang_id])) - { - $this->options_lang[$field_id][$lang_id] = array(); - } - $this->options_lang[$field_id][$lang_id][($num + 1)] = $var; + $this->options_lang[$field_id] = array(); } + if (!isset($this->options_lang[$field_id][$lang_id])) + { + $this->options_lang[$field_id][$lang_id] = array(); + } + $this->options_lang[$field_id][$lang_id][($num + 1)] = $var; } - else - { - if (is_array($field_id)) - { - $field_id = array_map('intval', array_unique($field_id)); - } - else - { - $field_id = array((int) $field_id); - } + } - $sql = 'SELECT field_id, option_id, lang_value + /** + * Fetches language entries for options from DB + * + * @param int $lang_id + */ + public function load_option_lang($lang_id) + { + $sql = 'SELECT field_id, option_id, lang_value FROM ' . $this->language_table . ' - WHERE ' . $this->db->sql_in_set('field_id', $field_id) . ' - AND lang_id = ' . (int) $lang_id . " + WHERE lang_id = ' . (int) $lang_id . " ORDER BY option_id"; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $this->options_lang[$row['field_id']][$lang_id][($row['option_id'] + 1)] = $row['lang_value']; - } - $this->db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->options_lang[$row['field_id']][$lang_id][($row['option_id'] + 1)] = $row['lang_value']; } + + $this->db->sql_freeresult($result); } /** diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 251899146b..bd08580431 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -367,33 +367,6 @@ class manager return $user_fields; } - /** - * Cache user's profile fields' language options - * @param array $profile_row Array with users profile field data - * @return void - */ - public function cache_profile_fields_lang_options($profile_row) - { - if (!empty($profile_row)) - { - $field_ids = array(); - foreach ($profile_row as $ident_ary) - { - if (empty($field_ids[$ident_ary['data']['lang_id']])) - { - $field_ids[$ident_ary['data']['lang_id']] = array(); - } - - $field_ids[$ident_ary['data']['lang_id']][] = $ident_ary['data']['field_id']; - } - - foreach ($field_ids as $lang => $fields) - { - $this->lang_helper->get_option_lang($fields, $lang, false); - } - } - } - /** * Assign the user's profile fields data to the template * diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 86e480f6b3..b9a7f93b85 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -155,7 +155,7 @@ class type_bool extends type_base if (!$this->lang_helper->is_set($field_id, $lang_id)) { - $this->lang_helper->get_option_lang($field_id, $lang_id, false); + $this->lang_helper->load_option_lang($lang_id); } if (!$field_value && $field_data['field_show_novalue']) @@ -203,7 +203,7 @@ class type_bool extends type_base { if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $preview_options); + $this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options); } $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']); diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 5ecbf4e167..7780f70d64 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -135,7 +135,7 @@ class type_dropdown extends type_base // retrieve option lang data if necessary if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], 1)) { - $this->lang_helper->get_option_lang($field_data['field_id'], $field_data['lang_id'], false); + $this->lang_helper->load_option_lang($field_data['lang_id']); } if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], $field_value)) @@ -160,7 +160,7 @@ class type_dropdown extends type_base $lang_id = $field_data['lang_id']; if (!$this->lang_helper->is_set($field_id, $lang_id)) { - $this->lang_helper->get_option_lang($field_id, $lang_id, false); + $this->lang_helper->load_option_lang($lang_id); } if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) @@ -199,7 +199,7 @@ class type_dropdown extends type_base if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $preview_options); + $this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options); } $profile_row['field_value'] = (int) $value; diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 760b4e5c87..d87f7de2b0 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1270,7 +1270,6 @@ if ($config['load_cpf_viewtopic']) // filter out fields not to be displayed on viewtopic. Yes, it's a hack, but this shouldn't break any MODs. $profile_fields_cache = array(); - $profile_rows = array(); foreach ($profile_fields_tmp as $profile_user_id => $profile_fields) { $profile_fields_cache[$profile_user_id] = array(); @@ -1279,15 +1278,10 @@ if ($config['load_cpf_viewtopic']) if ($profile_field['data']['field_show_on_vt']) { $profile_fields_cache[$profile_user_id][$used_ident] = $profile_field; - $profile_rows[] = $profile_field; } } } - - // Cache the language options for optimisation - $cp->cache_profile_fields_lang_options($profile_rows); - - unset($profile_fields_tmp, $profile_rows); + unset($profile_fields_tmp); } // Generate online information for user From 98262a5a175727b2dacea283d2fec127a35ed819 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Thu, 26 Jun 2014 03:15:12 +0530 Subject: [PATCH 11/12] [ticket/12759] Remove lang_helper from profilefields_manager No longer required PHPBB3-12759 --- phpBB/config/profilefields.yml | 1 - phpBB/phpbb/profilefields/manager.php | 10 +--------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/phpBB/config/profilefields.yml b/phpBB/config/profilefields.yml index 2ed8ca5600..ce2a84b12b 100644 --- a/phpBB/config/profilefields.yml +++ b/phpBB/config/profilefields.yml @@ -5,7 +5,6 @@ services: - @auth - @dbal.conn - @dispatcher - - @profilefields.lang_helper - @request - @template - @profilefields.type_collection diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index bd08580431..490db0419a 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -36,12 +36,6 @@ class manager */ protected $dispatcher; - /** - * Profile fields language helper - * @var \phpbb\profilefields\lang_helper - */ - protected $lang_helper; - /** * Request object * @var \phpbb\request\request @@ -80,7 +74,6 @@ class manager * @param \phpbb\auth\auth $auth Auth object * @param \phpbb\db\driver\driver_interface $db Database object * @param \phpbb\event\dispatcher $dispatcher Event dispatcher object - * @param \phpbb\profilefields\lang_helper $lang_helper Language helper object * @param \phpbb\request\request $request Request object * @param \phpbb\template\template $template Template object * @param \phpbb\di\service_collection $type_collection @@ -89,12 +82,11 @@ class manager * @param string $fields_language_table * @param string $fields_data_table */ - public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher $dispatcher, \phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) + public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher $dispatcher, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) { $this->auth = $auth; $this->db = $db; $this->dispatcher = $dispatcher; - $this->lang_helper = $lang_helper; $this->request = $request; $this->template = $template; $this->type_collection = $type_collection; From 6d464e0bc44574687d5d9fce42d5a0515b7c9a01 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Fri, 27 Jun 2014 17:58:28 +0530 Subject: [PATCH 12/12] [ticket/12759] Fix type_bool and type_dropdown's UCP fields PHPBB3-12759 --- phpBB/phpbb/profilefields/type/type_bool.php | 9 ++++++++- phpBB/phpbb/profilefields/type/type_dropdown.php | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index b9a7f93b85..f67e58ee3a 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -203,7 +203,14 @@ class type_bool extends type_base { if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options); + if ($preview_options) + { + $this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options); + } + else + { + $this->lang_helper->load_option_lang($profile_row['lang_id']); + } } $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']); diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 7780f70d64..118ddf1f37 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -199,7 +199,14 @@ class type_dropdown extends type_base if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options); + if ($preview_options) + { + $this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options); + } + else + { + $this->lang_helper->load_option_lang($profile_row['lang_id']); + } } $profile_row['field_value'] = (int) $value;