From 14201c8383f0503d45bbfc4df4518749ff4bd8bd Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Mon, 18 Nov 2024 12:49:50 +0100 Subject: [PATCH] Export the avatar from the file system of version 6.2+ --- .../system/exporter/WBB4xExporter.class.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/files/lib/system/exporter/WBB4xExporter.class.php b/files/lib/system/exporter/WBB4xExporter.class.php index 115407f..289d10f 100644 --- a/files/lib/system/exporter/WBB4xExporter.class.php +++ b/files/lib/system/exporter/WBB4xExporter.class.php @@ -812,6 +812,16 @@ final class WBB4xExporter extends AbstractExporter */ public function countUserAvatars() { + if (\version_compare($this->getPackageVersion('com.woltlab.wcf'), '6.2.0 Alpha 1', '>=')) { + $sql = "SELECT COUNT(*) as counter + FROM wcf" . $this->dbNo . "_user + WHERE avatarFileID IS NOT NULL"; + $statement = $this->database->prepareUnmanaged($sql); + $statement->execute(); + + return $statement->fetchSingleColumn(); + } + return $this->__getMaxID("wcf" . $this->dbNo . "_user_avatar", 'avatarID'); } @@ -823,6 +833,12 @@ final class WBB4xExporter extends AbstractExporter */ public function exportUserAvatars($offset, $limit) { + if (\version_compare($this->getPackageVersion('com.woltlab.wcf'), '6.2.0 Alpha 1', '>=')) { + $this->exportUserAvatars62($offset, $limit); + + return; + } + $sql = "SELECT * FROM wcf" . $this->dbNo . "_user_avatar WHERE avatarID BETWEEN ? AND ? @@ -847,6 +863,37 @@ final class WBB4xExporter extends AbstractExporter } } + private function exportUserAvatars62(int $offset, int $limit): void + { + $sql = "SELECT userID, avatarFileID + FROM wcf" . $this->dbNo . "_user + WHERE avatarFileID IS NOT NULL + ORDER BY userID"; + $statement = $this->database->prepareUnmanaged($sql, $limit, $offset); + $statement->execute(); + + $userIDToFileID = $statement->fetchMap('userID', 'avatarFileID'); + $fileIDs = \array_values($userIDToFileID); + $avatarLocations = $this->getFileLocations($fileIDs); + + foreach ($userIDToFileID as $userID => $fileID) { + ['location' => $fileLocation, 'filename' => $avatarName] = $avatarLocations[$fileID]; + + $data = [ + 'avatarName' => $avatarName, + 'userID' => $userID, + ]; + + ImportHandler::getInstance() + ->getImporter('com.woltlab.wcf.user.avatar') + ->import( + $fileID, + $data, + ['fileLocation' => $fileLocation] + ); + } + } + /** * Counts user options. */ -- 2.20.1