Skip to content

Commit bee1a7a

Browse files
authored
Merge pull request phpbb#325 from iMattPro/fixes
Fix search result issues
2 parents c4ec4d8 + d55e567 commit bee1a7a

5 files changed

Lines changed: 29 additions & 11 deletions

File tree

src/QuickInstall/Sandbox/SeedRuntime/ContentBuilder.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,8 @@ private function createReply(
477477
private function postData(int $forumId, int $topicId, string $subject, string $message): array
478478
{
479479
$db = $this->context->db;
480-
$uid = $bitfield = '';
481-
$options = 7;
482-
generate_text_for_storage($message, $uid, $bitfield, $options, true, true, true);
480+
$parser = $this->parseMessage($message);
481+
$message = $parser->message;
483482
$result = $db->sql_query_limit('SELECT forum_name FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $forumId, 1);
484483
$forumName = (string) $db->sql_fetchfield('forum_name');
485484
$db->sql_freeresult($result);
@@ -497,8 +496,8 @@ private function postData(int $forumId, int $topicId, string $subject, string $m
497496
'enable_sig' => true,
498497
'message' => $message,
499498
'message_md5' => md5($message),
500-
'bbcode_bitfield' => $bitfield,
501-
'bbcode_uid' => $uid,
499+
'bbcode_bitfield' => $parser->bbcode_bitfield,
500+
'bbcode_uid' => $parser->bbcode_uid,
502501
'post_edit_locked' => 0,
503502
'notify_set' => false,
504503
'notify' => false,

src/QuickInstall/Sandbox/SeedRuntime/SeedContext.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,20 @@ public function __construct(SeedContext $context)
415415
$this->context = $context;
416416
}
417417

418+
/** Parses user-authored content through phpBB's posting pipeline. */
419+
protected function parseMessage(string $message)
420+
{
421+
$parser = new \parse_message($message);
422+
// Keep phpBB's generated UID even with TextFormatter's empty legacy bitfield.
423+
$parser->parse(true, true, true, true, true, true, true);
424+
if ($parser->warn_msg)
425+
{
426+
throw new RuntimeException('Unable to parse seed message: ' . implode(' ', $parser->warn_msg));
427+
}
428+
429+
return $parser;
430+
}
431+
418432
/** Returns the last inserted ID across supported phpBB DBAL versions. */
419433
protected function lastInsertedId(): int
420434
{

src/QuickInstall/Sandbox/SeedRuntime/StateBuilder.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ private function sendMessage(int $recipientId, string $label, string $message):
207207
$db->sql_freeresult($result);
208208
if (!$messageId)
209209
{
210-
$uid = $bitfield = '';
211-
$options = 7;
212-
generate_text_for_storage($message, $uid, $bitfield, $options, true, true, true);
210+
$parser = $this->parseMessage($message);
213211
$data = [
214212
'address_list' => ['u' => [$recipientId => 'to']],
215213
'from_user_id' => $authorId,
@@ -220,9 +218,9 @@ private function sendMessage(int $recipientId, string $label, string $message):
220218
'enable_smilies' => true,
221219
'enable_urls' => true,
222220
'icon_id' => 0,
223-
'bbcode_uid' => $uid,
224-
'bbcode_bitfield' => $bitfield,
225-
'message' => $message,
221+
'bbcode_uid' => $parser->bbcode_uid,
222+
'bbcode_bitfield' => $parser->bbcode_bitfield,
223+
'message' => $parser->message,
226224
];
227225
submit_pm('post', $subject, $data, true);
228226
$messageId = (int) ($data['msg_id'] ?? 0);

src/QuickInstall/Sandbox/SeedRuntime/run.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363

6464
require_once $phpbb_root_path . 'includes/functions_user.' . $phpEx;
6565
require_once $phpbb_root_path . 'includes/functions_content.' . $phpEx;
66+
require_once $phpbb_root_path . 'includes/message_parser.' . $phpEx;
6667
require_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
6768
require_once $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
6869
require_once $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;

tests/Unit/SeederPackageTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function testWritesUnifiedSeederPackage(): void
4040
$run = file_get_contents($path . '/run.php');
4141
self::assertStringContainsString("getenv('QUICKINSTALL_SEED_RUNTIME') !== '1'", $run);
4242
self::assertStringContainsString('!isset($argv[1], $argv[2], $argv[3])', $run);
43+
self::assertStringContainsString("'includes/message_parser.'", $run);
4344
self::assertFileDoesNotExist($path . '/StandardSeeder.php');
4445
self::assertStringContainsString("'25 users'", file_get_contents($path . '/DevelopmentSeeder.php'));
4546
self::assertStringContainsString("'90 posts'", file_get_contents($path . '/DevelopmentSeeder.php'));
@@ -61,6 +62,11 @@ public function testWritesUnifiedSeederPackage(): void
6162
self::assertStringContainsString("ids('logs')", file_get_contents($path . '/Seeder.php'));
6263
self::assertStringContainsString('[size=50]Smaller text[/size]', file_get_contents($path . '/ContentBuilder.php'));
6364
self::assertStringContainsString('[list=a]', file_get_contents($path . '/ContentBuilder.php'));
65+
self::assertStringContainsString('new \\parse_message($message)', file_get_contents($path . '/SeedContext.php'));
66+
self::assertStringContainsString('$this->parseMessage($message)', file_get_contents($path . '/ContentBuilder.php'));
67+
self::assertStringContainsString('$this->parseMessage($message)', file_get_contents($path . '/StateBuilder.php'));
68+
self::assertStringContainsString("'bbcode_uid' => \$parser->bbcode_uid", file_get_contents($path . '/ContentBuilder.php'));
69+
self::assertStringContainsString("'bbcode_uid' => \$parser->bbcode_uid", file_get_contents($path . '/StateBuilder.php'));
6470
self::assertStringContainsString('reply with three quote levels', file_get_contents($path . '/ContentBuilder.php'));
6571
self::assertStringContainsString('SupercalifragilisticexpialidociousSupercalifragilisticexpialidocious', file_get_contents($path . '/ContentBuilder.php'));
6672
self::assertStringContainsString('Unread private message', file_get_contents($path . '/StateBuilder.php'));

0 commit comments

Comments
 (0)