From 05629849997e676202e56e40f9a68be4428aa9c2 Mon Sep 17 00:00:00 2001 From: rxu Date: Mon, 12 May 2025 23:39:31 +0700 Subject: [PATCH] [ticket/17508] Fix PHP warning on custom profile fields edit PHPBB-17508 --- phpBB/includes/acp/acp_profile.php | 35 +++++++++++++++++++++ tests/functional/acp_profile_field_test.php | 28 +++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php index a234a511b9..8cf60c2e7d 100644 --- a/phpBB/includes/acp/acp_profile.php +++ b/phpBB/includes/acp/acp_profile.php @@ -475,6 +475,41 @@ class acp_profile $cp->vars[$key] = $var; } + // step 3 - all arrays + if ($action == 'edit') + { + // Get language entries + $sql = 'SELECT * + FROM ' . PROFILE_FIELDS_LANG_TABLE . ' + WHERE lang_id <> ' . $this->edit_lang_id . " + AND field_id = $field_id + ORDER BY option_id ASC"; + $result = $db->sql_query($sql); + + $l_lang_options = []; + while ($row = $db->sql_fetchrow($result)) + { + $l_lang_options[$row['lang_id']][$row['option_id']] = $row['lang_value']; + } + $db->sql_freeresult($result); + + $sql = 'SELECT lang_id, lang_name, lang_explain, lang_default_value + FROM ' . PROFILE_LANG_TABLE . ' + WHERE lang_id <> ' . $this->edit_lang_id . " + AND field_id = $field_id + ORDER BY lang_id ASC"; + $result = $db->sql_query($sql); + + $l_lang_name = $l_lang_explain = $l_lang_default_value = []; + while ($row = $db->sql_fetchrow($result)) + { + $l_lang_name[$row['lang_id']] = $row['lang_name']; + $l_lang_explain[$row['lang_id']] = $row['lang_explain']; + $l_lang_default_value[$row['lang_id']] = $row['lang_default_value']; + } + $db->sql_freeresult($result); + } + foreach ($exclude[3] as $key) { $cp->vars[$key] = $request->variable($key, array(0 => ''), true); diff --git a/tests/functional/acp_profile_field_test.php b/tests/functional/acp_profile_field_test.php index 44755675b4..9730e1e385 100644 --- a/tests/functional/acp_profile_field_test.php +++ b/tests/functional/acp_profile_field_test.php @@ -69,4 +69,32 @@ class phpbb_functional_acp_profile_field_test extends phpbb_functional_test_case $this->assertContainsLang('ADDED_PROFILE_FIELD', $crawler->text()); } + + public function test_edit_profile_fields() + { + // Custom profile fields page + $crawler = self::request('GET', 'adm/index.php?i=acp_profile&mode=profile&sid=' . $this->sid); + + // Get all profile fields edit URLs + $edits = $crawler->filter('td.actions a') + ->reduce( + function ($node, $i) { + $url = $node->attr('href'); + return ((bool) strpos($url, 'action=edit')); + }) + ->each( + function ($node, $i) { + $url = $node->attr('href'); + return ($url); + }); + + foreach ($edits as $edit_url) + { + $crawler = self::request('GET', 'adm/' . $edit_url . '&sid=' . $this->sid); + $form = $crawler->selectButton('Save')->form(); + $crawler= self::submit($form); + + $this->assertContainsLang('CHANGED_PROFILE_FIELD', $crawler->text()); + } + } }