--- /dev/null
+<?php
+
+use wcf\data\user\rank\UserRank;
+use wcf\data\user\rank\UserRankEditor;
+use wcf\data\user\rank\UserRankList;
+use wcf\system\background\BackgroundQueueHandler;
+use wcf\system\background\job\DownloadRankImageJob;
+use wcf\util\Url;
+
+/**
+ * Downloads the rank image files to the new internal upload system.
+ *
+ * @author Joshua Ruesweg
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core
+ */
+$rankList = new UserRankList();
+$rankList->readObjects();
+
+foreach ($rankList as $rank) {
+ if (!empty($rank->rankImage)) {
+ if (Url::is($rank->rankImage)) {
+ BackgroundQueueHandler::getInstance()->enqueueIn(new DownloadRankImageJob($rank), 60);
+ continue;
+ }
+
+ $rankEditor = new UserRankEditor($rank);
+
+ if (file_exists(WCF_DIR . $rank->rankImage)) {
+ $newImageName = WCF_DIR . UserRank::RANK_IMAGE_DIR . $rank->rankID .'-'. basename($rank->rankImage);
+ copy(WCF_DIR . $rank->rankImage, $newImageName);
+
+ $rankEditor->update([
+ 'rankImage' => basename($newImageName)
+ ]);
+ }
+ else {
+ $rankEditor->update([
+ 'rankImage' => ""
+ ]);
+ }
+ }
+}
--- /dev/null
+<?php
+namespace wcf\system\background\job;
+use GuzzleHttp\Psr7\Request;
+use wcf\data\user\rank\UserRank;
+use wcf\data\user\rank\UserRankEditor;
+use wcf\system\io\HttpFactory;
+use wcf\util\Url;
+
+/**
+ * Downloads the rank images and stores it locally within the rank image path.
+ *
+ * @author Joshua Ruesweg
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Background\Job
+ * @since 5.4
+ * @deprecated 5.4 - This background job is used for the upgrade from 5.3 to 5.4 and will be removed with 5.5.
+ */
+class DownloadRankImageJob extends AbstractBackgroundJob {
+ /**
+ * @inheritDoc
+ */
+ const MAX_FAILURES = 5;
+
+ /**
+ * @var int
+ */
+ protected $userRankID;
+
+ public function __construct(UserRank $userRank) {
+ $this->userRankID = $userRank->rankID;
+ }
+
+ /**
+ * @return int every 10 minutes
+ */
+ public function retryAfter() {
+ return 10 * 60;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function perform() {
+ $rank = new UserRank($this->userRankID);
+ if (!$rank->rankID) return;
+ if (empty($rank->rankImage)) return;
+ if (!Url::is($rank->rankImage)) return;
+
+ $rankEditor = new UserRankEditor($rank);
+
+ $extension = pathinfo(Url::parse($rank->rankImage)['path'], PATHINFO_EXTENSION);
+ if (in_array($extension, ['gif','png','jpg','jpeg','svg','webp'])) {
+ $http = HttpFactory::makeClient([
+ 'timeout' => 10,
+ ]);
+
+ $imageDest = WCF_DIR . UserRank::RANK_IMAGE_DIR . $rank->rankID .'-rankImage.'. $extension;
+ $http->send(new Request('GET', $rank->rankImage), [
+ 'sink' => $imageDest,
+ ]);
+
+ $rankEditor->update([
+ 'rankImage' => basename($imageDest)
+ ]);
+ }
+ else {
+ $rankEditor->update([
+ 'rankImage' => ""
+ ]);
+ }
+ }
+}