Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues when changing and previewing prefixes #26

Merged
merged 5 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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"
Expand Down
24 changes: 15 additions & 9 deletions event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand All @@ -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)
{
Expand All @@ -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']))
{
Expand Down
2 changes: 1 addition & 1 deletion prefixes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];

Expand Down
28 changes: 26 additions & 2 deletions tests/event/listener_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]',
),
),
);
}

Expand Down Expand Up @@ -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'),
),
),
Expand All @@ -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'),
),
),
Expand Down