Skip to content

Commit 14201c8

Browse files
committed
Export the avatar from the file system of version 6.2+
1 parent 549f249 commit 14201c8

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

files/lib/system/exporter/WBB4xExporter.class.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,16 @@ public function exportProfileCommentResponses($offset, $limit)
812812
*/
813813
public function countUserAvatars()
814814
{
815+
if (\version_compare($this->getPackageVersion('com.woltlab.wcf'), '6.2.0 Alpha 1', '>=')) {
816+
$sql = "SELECT COUNT(*) as counter
817+
FROM wcf" . $this->dbNo . "_user
818+
WHERE avatarFileID IS NOT NULL";
819+
$statement = $this->database->prepareUnmanaged($sql);
820+
$statement->execute();
821+
822+
return $statement->fetchSingleColumn();
823+
}
824+
815825
return $this->__getMaxID("wcf" . $this->dbNo . "_user_avatar", 'avatarID');
816826
}
817827

@@ -823,6 +833,12 @@ public function countUserAvatars()
823833
*/
824834
public function exportUserAvatars($offset, $limit)
825835
{
836+
if (\version_compare($this->getPackageVersion('com.woltlab.wcf'), '6.2.0 Alpha 1', '>=')) {
837+
$this->exportUserAvatars62($offset, $limit);
838+
839+
return;
840+
}
841+
826842
$sql = "SELECT *
827843
FROM wcf" . $this->dbNo . "_user_avatar
828844
WHERE avatarID BETWEEN ? AND ?
@@ -847,6 +863,37 @@ public function exportUserAvatars($offset, $limit)
847863
}
848864
}
849865

866+
private function exportUserAvatars62(int $offset, int $limit): void
867+
{
868+
$sql = "SELECT userID, avatarFileID
869+
FROM wcf" . $this->dbNo . "_user
870+
WHERE avatarFileID IS NOT NULL
871+
ORDER BY userID";
872+
$statement = $this->database->prepareUnmanaged($sql, $limit, $offset);
873+
$statement->execute();
874+
875+
$userIDToFileID = $statement->fetchMap('userID', 'avatarFileID');
876+
$fileIDs = \array_values($userIDToFileID);
877+
$avatarLocations = $this->getFileLocations($fileIDs);
878+
879+
foreach ($userIDToFileID as $userID => $fileID) {
880+
['location' => $fileLocation, 'filename' => $avatarName] = $avatarLocations[$fileID];
881+
882+
$data = [
883+
'avatarName' => $avatarName,
884+
'userID' => $userID,
885+
];
886+
887+
ImportHandler::getInstance()
888+
->getImporter('com.woltlab.wcf.user.avatar')
889+
->import(
890+
$fileID,
891+
$data,
892+
['fileLocation' => $fileLocation]
893+
);
894+
}
895+
}
896+
850897
/**
851898
* Counts user options.
852899
*/

0 commit comments

Comments
 (0)