Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export user avatar from 6.2+ #88

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions files/lib/system/exporter/WBB4xExporter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,16 @@ public function exportProfileCommentResponses($offset, $limit)
*/
public function countUserAvatars()
{
if (Package::compareVersion($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');
}

Expand All @@ -823,6 +833,12 @@ public function countUserAvatars()
*/
public function exportUserAvatars($offset, $limit)
{
if (Package::compareVersion($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 ?
Expand All @@ -847,6 +863,37 @@ public function exportUserAvatars($offset, $limit)
}
}

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.
*/
Expand Down