From 5c8a667db2e47313e687fd8afe3c4fa7c73abeb9 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 22 Jan 2018 02:37:47 +0100 Subject: [PATCH 1/2] [ticket/15527] Skip malformed BBCodes during merge_duplicate_bbcodes migration PHPBB3-15527 --- .../data/v32x/merge_duplicate_bbcodes.php | 31 +++++++++++++------ .../phpbb/textformatter/s9e/bbcode_merger.php | 3 ++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v32x/merge_duplicate_bbcodes.php b/phpBB/phpbb/db/migration/data/v32x/merge_duplicate_bbcodes.php index 08609b571b..6457a84adb 100644 --- a/phpBB/phpbb/db/migration/data/v32x/merge_duplicate_bbcodes.php +++ b/phpBB/phpbb/db/migration/data/v32x/merge_duplicate_bbcodes.php @@ -13,6 +13,8 @@ namespace phpbb\db\migration\data\v32x; +use Exception; + class merge_duplicate_bbcodes extends \phpbb\db\migration\container_aware_migration { public function update_data() @@ -46,16 +48,25 @@ class merge_duplicate_bbcodes extends \phpbb\db\migration\container_aware_migrat protected function merge_bbcodes(array $without, array $with) { - $merged = $this->container->get('text_formatter.s9e.bbcode_merger')->merge_bbcodes( - [ - 'usage' => $without['bbcode_match'], - 'template' => $without['bbcode_tpl'] - ], - [ - 'usage' => $with['bbcode_match'], - 'template' => $with['bbcode_tpl'] - ] - ); + try + { + $merged = $this->container->get('text_formatter.s9e.bbcode_merger')->merge_bbcodes( + [ + 'usage' => $without['bbcode_match'], + 'template' => $without['bbcode_tpl'] + ], + [ + 'usage' => $with['bbcode_match'], + 'template' => $with['bbcode_tpl'] + ] + ); + } + catch (Exception $e) + { + // Ignore the pair and move on. The BBCodes would have to be fixed manually + return; + } + $bbcode_data = [ 'bbcode_tag' => $without['bbcode_tag'], 'bbcode_helpline' => $without['bbcode_helpline'] . ' | ' . $with['bbcode_helpline'], diff --git a/phpBB/phpbb/textformatter/s9e/bbcode_merger.php b/phpBB/phpbb/textformatter/s9e/bbcode_merger.php index 72b1473751..a05ca3c2b8 100644 --- a/phpBB/phpbb/textformatter/s9e/bbcode_merger.php +++ b/phpBB/phpbb/textformatter/s9e/bbcode_merger.php @@ -37,6 +37,9 @@ class bbcode_merger * * All of the arrays contain a "usage" element and a "template" element * + * @throws InvalidArgumentException if a definition cannot be interpreted + * @throws RuntimeException if something unexpected occurs + * * @param array $without BBCode definition without an attribute * @param array $with BBCode definition with an attribute * @return array Merged definition From 532afbf83a509b25c5042f5bb374657417ca3e5d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 24 Jan 2018 18:47:40 +0100 Subject: [PATCH 2/2] [ticket/15527] Remove "use" and specify full class name for exception PHPBB3-15527 --- .../phpbb/db/migration/data/v32x/merge_duplicate_bbcodes.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v32x/merge_duplicate_bbcodes.php b/phpBB/phpbb/db/migration/data/v32x/merge_duplicate_bbcodes.php index 6457a84adb..ad50089d4e 100644 --- a/phpBB/phpbb/db/migration/data/v32x/merge_duplicate_bbcodes.php +++ b/phpBB/phpbb/db/migration/data/v32x/merge_duplicate_bbcodes.php @@ -13,8 +13,6 @@ namespace phpbb\db\migration\data\v32x; -use Exception; - class merge_duplicate_bbcodes extends \phpbb\db\migration\container_aware_migration { public function update_data() @@ -61,7 +59,7 @@ class merge_duplicate_bbcodes extends \phpbb\db\migration\container_aware_migrat ] ); } - catch (Exception $e) + catch (\Exception $e) { // Ignore the pair and move on. The BBCodes would have to be fixed manually return;