Export the avatar from the file system of version 6.2+ 6.2-user-avatar-export
authorCyperghost <olaf_schmitz_1@t-online.de>
Mon, 18 Nov 2024 11:49:50 +0000 (12:49 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Mon, 18 Nov 2024 11:49:50 +0000 (12:49 +0100)
files/lib/system/exporter/WBB4xExporter.class.php

index 115407f53fe45a0731b30f666bdd69efaf275990..289d10f9837306941201cacfd04c89a3c023b182 100644 (file)
@@ -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.
      */