PHPBB3-15444 - Merge duplicate BBCodes via a migration

Discuss requests for comments/changes posted in the Issue Tracker for the development of phpBB. Current releases are 3.2/Rhea and 3.3/Proteus.
Post Reply
User avatar
JoshyPHP
Registered User
Posts: 381
Joined: Fri Jul 08, 2011 9:43 pm

PHPBB3-15444 - Merge duplicate BBCodes via a migration

Post by JoshyPHP »

Context: in 3.1, it was possible to create two BBCodes using the same name; One without an attribute and the other with. This was presumably to handle polymorphic BBCodes such as [url] or [quote]. In 3.2.1, it is still possible to create two BBCodes in the ACP but only one of them will effectively work as intended. Starting with 3.2.2, only one BBCode can be created in the ACP but old definitions remain in the database and the behaviour remains unchanged: only one of them works.

Since the overwhelming majority of those BBCodes fall into one of two categories ([url]-style or [quote]-style) it is possible to merge them programmatically. A migration seems the right way to do that. I am not familiar with the migration system and I won't have time to learn it, that's why I'm looking for someone to handle this part.

On my end, I will create a text_formatter.s9e.bbcode_merger service that takes the two BBCode definitions as input and produces a single, merged definition as output:

Code: Select all

$bbcode_merger = $phpbb_container->get('text_formatter.s9e.bbcode_merger');
$merged = $bbcode_merger->merge_bbcodes(
	[
		// First argument is the BBCode definition without an attribute
		'usage'    => '[url]{URL}[/url]',
		'template' => '<a href="{URL}">{URL}</a>'
	],
	[
		// Second argument is the BBCode definition with an attribute
		'usage'    => '[url={URL}]{TEXT}[/url]',
		'template' => '<a href="{URL}">{TEXT}</a>'
	]
);

Code: Select all

// $merged =
[
	'usage'    => '[url={URL;useContent}]{TEXT}[/url]',
	'template' => '<a href="{@url}"><xsl:apply-templates/></a>'
]
The migration should read the phpbb_bbcodes table, find entries with the same case-insensitive name minus the equal sign in bbcode_tag (e.g. foo and foo=) then generate a merged definition, remove the entry with an equal sign and replace the remaining entry with the merged one. Maybe the BBCode's "help line" could be merged somehow, too.

I have already written the service part, it's available in Pull request #5038. It relies on a yet-to-be-released version of s9e\TextFormatter, that's why it's currently marked WIP.


References

Post Reply