From f12f9215aac1a50933f67f418a941d5bc50c353a Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 26 Nov 2023 09:16:26 -0800 Subject: [PATCH 1/5] Fix so when previewing a post, the selected prefix stays selected in the form Signed-off-by: Matt Friedman --- event/listener.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/event/listener.php b/event/listener.php index 2903564..cee0b92 100644 --- a/event/listener.php +++ b/event/listener.php @@ -161,6 +161,12 @@ protected function get_selected_prefix($event) // Get the prefix from the select menu $prefix_id = $this->request->variable('topic_prefix', 0); + // If we are in preview mode, send back the prefix from the form + if (!empty($event['preview'])) + { + return $prefix_id; + } + // If no prefix was selected, get one if it already exists (ie: editing a post) if (!$prefix_id && !empty($event['post_data']['topic_prefix_id'])) { From 2e0ff8967c7e40f904b3bb6ad704e2d07e5aa971 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 26 Nov 2023 09:17:37 -0800 Subject: [PATCH 2/5] Fix so when editing posts and going back and forth between prefix or no prefix updates all replies correctly Signed-off-by: Matt Friedman --- event/listener.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/event/listener.php b/event/listener.php index cee0b92..3735ddf 100644 --- a/event/listener.php +++ b/event/listener.php @@ -102,23 +102,23 @@ public function add_to_posting_form($event) */ public function submit_prefix_data($event) { - if (!($selected = $this->request->variable('topic_prefix', 0))) - { - return; - } + $selected = $this->request->variable('topic_prefix', 0); // Get data for the prefix selected by the user $prefix = $this->manager->get_prefix($selected); // First, add the topic prefix id to the data to be stored with the db $data = $event['data']; - $data['topic_prefix_id'] = (int) $prefix['prefix_id']; + $data['topic_prefix_id'] = $prefix ? (int) $prefix['prefix_id'] : 0; $event['data'] = $data; // Next, prepend the topic prefix to the subject (if necessary) - $post_data = $event['post_data']; - $post_data['post_subject'] = $this->manager->prepend_prefix($prefix['prefix_tag'], $post_data['post_subject']); - $event['post_data'] = $post_data; + if (isset($prefix['prefix_tag'])) + { + $post_data = $event['post_data']; + $post_data['post_subject'] = $this->manager->prepend_prefix($prefix['prefix_tag'], $post_data['post_subject']); + $event['post_data'] = $post_data; + } } /** From dbff7363d4f548fc87d9aa04bd6983c69421a9a0 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 26 Nov 2023 09:17:49 -0800 Subject: [PATCH 3/5] Update unit tests Signed-off-by: Matt Friedman --- tests/event/listener_test.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/event/listener_test.php b/tests/event/listener_test.php index 8a91738..4486e63 100644 --- a/tests/event/listener_test.php +++ b/tests/event/listener_test.php @@ -223,6 +223,30 @@ public function data_add_to_posting_form() 'SELECTED_PREFIX' => '', ), ), + array( // test post preview mode shows the expected prefix when no prefix is selected + $prefix_data, + array( + 'mode' => 'edit', + 'preview' => true, + ), + 0, + array( + 'PREFIXES' => $prefix_data, + 'SELECTED_PREFIX' => '', + ), + ), + array( // test post preview mode shows the expected prefix when a prefix is selected + $prefix_data, + array( + 'mode' => 'edit', + 'preview' => true, + ), + 1, + array( + 'PREFIXES' => $prefix_data, + 'SELECTED_PREFIX' => '[foo]', + ), + ), ); } @@ -320,7 +344,7 @@ public function data_submit_prefix_data() ), ), array( - 'data' => array(), + 'data' => array('topic_prefix_id' => 0), 'post_data' => array('post_subject' => 'test subject'), ), ), @@ -333,7 +357,7 @@ public function data_submit_prefix_data() ), ), array( - 'data' => array(), + 'data' => array('topic_prefix_id' => 0), 'post_data' => array('post_subject' => 'test subject'), ), ), From 216e7f3111ad4dff30725ba1ed3e08f3d6dee2a5 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 26 Nov 2023 09:18:01 -0800 Subject: [PATCH 4/5] Small style fixes Signed-off-by: Matt Friedman --- event/listener.php | 2 +- prefixes/manager.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/event/listener.php b/event/listener.php index 3735ddf..e4f3e47 100644 --- a/event/listener.php +++ b/event/listener.php @@ -143,7 +143,7 @@ public function save_prefix_to_topic($event) * Is a new topic being posted/edited? * * @param \phpbb\event\data $event Event data object - * @return bool + * @return bool Return true if starting a new post or editing the first post, false otherwise */ protected function is_new_topic($event) { diff --git a/prefixes/manager.php b/prefixes/manager.php index 4b5902c..cb2b337 100644 --- a/prefixes/manager.php +++ b/prefixes/manager.php @@ -65,7 +65,7 @@ public function add_prefix($tag, $forum_id) { $data = [ 'prefix_tag' => $tag, - 'forum_id' => (int) $forum_id, + 'forum_id' => (int) $forum_id, 'prefix_enabled' => true, ]; From e750e7f3a28dcfa5c4ab5fd1feaad910354e6cbc Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 26 Nov 2023 09:18:09 -0800 Subject: [PATCH 5/5] Update workflow test suite Signed-off-by: Matt Friedman --- .github/workflows/tests.yml | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3aa230b..f9a9965 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -93,24 +93,22 @@ jobs: strategy: matrix: include: - - php: '7.1' + - php: '7.2' db: "mariadb:10.1" - - php: '7.1' + - php: '7.2' db: "mariadb:10.2" - - php: '7.1' + - php: '7.2' db: "mariadb:10.3" - - php: '7.1' + - php: '7.2' db: "mariadb:10.4" - - php: '7.1' + - php: '7.2' db: "mariadb:10.5" - - php: '7.1' + - php: '7.2' db: "mysql:5.6" db_alias: "MyISAM Tests" MYISAM: 1 - - php: '7.1' + - php: '7.2' db: "mysql:5.6" - - php: '7.1' - db: "mysql:5.7" - php: '7.2' db: "mysql:5.7" COVERAGE: 1 @@ -244,18 +242,16 @@ jobs: strategy: matrix: include: - - php: '7.1' + - php: '7.2' db: "postgres:9.5" - - php: '7.1' + - php: '7.2' db: "postgres:9.6" - - php: '7.1' + - php: '7.2' db: "postgres:10" - - php: '7.1' + - php: '7.2' db: "postgres:11" - - php: '7.1' + - php: '7.2' db: "postgres:12" - - php: '7.1' - db: "postgres:13" - php: '7.2' db: "postgres:13" - php: '7.3' @@ -358,7 +354,7 @@ jobs: strategy: matrix: include: - - php: '7.1' + - php: '7.2' db: "sqlite3" - php: '7.2' db: "mcr.microsoft.com/mssql/server:2017-latest"