Skip to content
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
9 changes: 4 additions & 5 deletions src/QuickInstall/Sandbox/SeedRuntime/ContentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,8 @@ private function createReply(
private function postData(int $forumId, int $topicId, string $subject, string $message): array
{
$db = $this->context->db;
$uid = $bitfield = '';
$options = 7;
generate_text_for_storage($message, $uid, $bitfield, $options, true, true, true);
$parser = $this->parseMessage($message);
$message = $parser->message;
$result = $db->sql_query_limit('SELECT forum_name FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $forumId, 1);
$forumName = (string) $db->sql_fetchfield('forum_name');
$db->sql_freeresult($result);
Expand All @@ -497,8 +496,8 @@ private function postData(int $forumId, int $topicId, string $subject, string $m
'enable_sig' => true,
'message' => $message,
'message_md5' => md5($message),
'bbcode_bitfield' => $bitfield,
'bbcode_uid' => $uid,
'bbcode_bitfield' => $parser->bbcode_bitfield,
'bbcode_uid' => $parser->bbcode_uid,
'post_edit_locked' => 0,
'notify_set' => false,
'notify' => false,
Expand Down
14 changes: 14 additions & 0 deletions src/QuickInstall/Sandbox/SeedRuntime/SeedContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,20 @@ public function __construct(SeedContext $context)
$this->context = $context;
}

/** Parses user-authored content through phpBB's posting pipeline. */
protected function parseMessage(string $message)
{
$parser = new \parse_message($message);
// Keep phpBB's generated UID even with TextFormatter's empty legacy bitfield.
$parser->parse(true, true, true, true, true, true, true);
if ($parser->warn_msg)
{
throw new RuntimeException('Unable to parse seed message: ' . implode(' ', $parser->warn_msg));
}

return $parser;
}

/** Returns the last inserted ID across supported phpBB DBAL versions. */
protected function lastInsertedId(): int
{
Expand Down
10 changes: 4 additions & 6 deletions src/QuickInstall/Sandbox/SeedRuntime/StateBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ private function sendMessage(int $recipientId, string $label, string $message):
$db->sql_freeresult($result);
if (!$messageId)
{
$uid = $bitfield = '';
$options = 7;
generate_text_for_storage($message, $uid, $bitfield, $options, true, true, true);
$parser = $this->parseMessage($message);
$data = [
'address_list' => ['u' => [$recipientId => 'to']],
'from_user_id' => $authorId,
Expand All @@ -220,9 +218,9 @@ private function sendMessage(int $recipientId, string $label, string $message):
'enable_smilies' => true,
'enable_urls' => true,
'icon_id' => 0,
'bbcode_uid' => $uid,
'bbcode_bitfield' => $bitfield,
'message' => $message,
'bbcode_uid' => $parser->bbcode_uid,
'bbcode_bitfield' => $parser->bbcode_bitfield,
'message' => $parser->message,
];
submit_pm('post', $subject, $data, true);
$messageId = (int) ($data['msg_id'] ?? 0);
Expand Down
1 change: 1 addition & 0 deletions src/QuickInstall/Sandbox/SeedRuntime/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

require_once $phpbb_root_path . 'includes/functions_user.' . $phpEx;
require_once $phpbb_root_path . 'includes/functions_content.' . $phpEx;
require_once $phpbb_root_path . 'includes/message_parser.' . $phpEx;
require_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
require_once $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
require_once $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/SeederPackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function testWritesUnifiedSeederPackage(): void
$run = file_get_contents($path . '/run.php');
self::assertStringContainsString("getenv('QUICKINSTALL_SEED_RUNTIME') !== '1'", $run);
self::assertStringContainsString('!isset($argv[1], $argv[2], $argv[3])', $run);
self::assertStringContainsString("'includes/message_parser.'", $run);
self::assertFileDoesNotExist($path . '/StandardSeeder.php');
self::assertStringContainsString("'25 users'", file_get_contents($path . '/DevelopmentSeeder.php'));
self::assertStringContainsString("'90 posts'", file_get_contents($path . '/DevelopmentSeeder.php'));
Expand All @@ -61,6 +62,11 @@ public function testWritesUnifiedSeederPackage(): void
self::assertStringContainsString("ids('logs')", file_get_contents($path . '/Seeder.php'));
self::assertStringContainsString('[size=50]Smaller text[/size]', file_get_contents($path . '/ContentBuilder.php'));
self::assertStringContainsString('[list=a]', file_get_contents($path . '/ContentBuilder.php'));
self::assertStringContainsString('new \\parse_message($message)', file_get_contents($path . '/SeedContext.php'));
self::assertStringContainsString('$this->parseMessage($message)', file_get_contents($path . '/ContentBuilder.php'));
self::assertStringContainsString('$this->parseMessage($message)', file_get_contents($path . '/StateBuilder.php'));
self::assertStringContainsString("'bbcode_uid' => \$parser->bbcode_uid", file_get_contents($path . '/ContentBuilder.php'));
self::assertStringContainsString("'bbcode_uid' => \$parser->bbcode_uid", file_get_contents($path . '/StateBuilder.php'));
self::assertStringContainsString('reply with three quote levels', file_get_contents($path . '/ContentBuilder.php'));
self::assertStringContainsString('SupercalifragilisticexpialidociousSupercalifragilisticexpialidocious', file_get_contents($path . '/ContentBuilder.php'));
self::assertStringContainsString('Unread private message', file_get_contents($path . '/StateBuilder.php'));
Expand Down