From: Matthias Schmidt Date: Fri, 14 May 2021 11:14:59 +0000 (+0200) Subject: Fix attachment ids in metacode elements during import (#4213) X-Git-Tag: 5.4.0_Alpha_3~5^2~7 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c4ec4f7c18aca5f0703f864d7d3cd6960e7c9211;p=GitHub%2FWoltLab%2FWCF.git Fix attachment ids in metacode elements during import (#4213) * 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 --- 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; }