From c4ec4f7c18aca5f0703f864d7d3cd6960e7c9211 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Fri, 14 May 2021 13:14:59 +0200 Subject: [PATCH] Fix attachment ids in metacode elements during import (#4213) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Fix attachment ids in metacode elements during import Close #4212 * Update wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php Co-authored-by: Tim Düsterhus Co-authored-by: Tim Düsterhus --- .../AbstractAttachmentImporter.class.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php index 36b86b6b8b..6cdc414b4c 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php @@ -4,6 +4,7 @@ use wcf\data\attachment\Attachment; use wcf\data\attachment\AttachmentEditor; use wcf\system\exception\SystemException; use wcf\util\FileUtil; +use wcf\util\JSON; /** * Imports attachments. @@ -108,6 +109,32 @@ class AbstractAttachmentImporter extends AbstractImporter { return $message; } + else { + return \preg_replace_callback( + '~~', + static function (array $matches) use ($oldID, $newID): string { + $encodedAttributes = $matches['attributes']; + + $base64Decoded = \base64_decode($matches['attributes']); + if ($base64Decoded) { + try { + $attributes = JSON::decode($base64Decoded); + if ($attributes[0] == $oldID) { + $attributes[0] = $newID; + } + + $encodedAttributes = \base64_encode(JSON::encode($attributes)); + } + catch (\Exception $e) { + $encodedAttributes = $matches['attributes']; + } + } + + return ''; + }, + $message + ); + } return false; } -- 2.20.1