Skip to content

Commit

Permalink
Import the avatar in UserImporter and remove UserAvatarImporter
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyperghost committed Nov 11, 2024
1 parent 21b96a1 commit af4056e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 99 deletions.
1 change: 1 addition & 0 deletions com.woltlab.wcf/fileDelete.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2771,6 +2771,7 @@
<file>lib/system/html/output/node/HtmlOutputNodeWoltlabSize.class.php</file>
<file>lib/system/html/output/node/QuoteHtmlOutputNode.class.php</file>
<file>lib/system/image/Thumbnail.class.php</file>
<file>lib/system/importer/UserAvatarImporter.class.php</file>
<file>lib/system/language/I18nPlural.class.php</file>
<file>lib/system/language/LanguageServerProcessor.class.php</file>
<file>lib/system/language/preload/LanguagePreloader.class.php</file>
Expand Down
8 changes: 3 additions & 5 deletions com.woltlab.wcf/objectType.xml
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,6 @@
<definitionname>com.woltlab.wcf.importer</definitionname>
<classname>wcf\system\importer\UserOptionImporter</classname>
</type>
<type>
<name>com.woltlab.wcf.user.avatar</name>
<definitionname>com.woltlab.wcf.importer</definitionname>
<classname>wcf\system\importer\UserAvatarImporter</classname>
</type>
<type>
<name>com.woltlab.wcf.user.comment</name>
<definitionname>com.woltlab.wcf.importer</definitionname>
Expand Down Expand Up @@ -1804,5 +1799,8 @@
<type name="com.woltlab.wcf.sitemap">
<definitionname>com.woltlab.wcf.rebuildData</definitionname>
</type>
<type name="com.woltlab.wcf.user.avatar">
<definitionname>com.woltlab.wcf.importer</definitionname>
</type>
</delete>
</data>
12 changes: 7 additions & 5 deletions wcfsetup/install/files/lib/data/file/FileEditor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public static function createFromTemporary(FileTemporary $fileTemporary): File
public static function createFromExistingFile(
string $pathname,
string $originalFilename,
string $objectTypeName
string $objectTypeName,
bool $copy = false
): ?File {
if (!\is_readable($pathname)) {
return null;
Expand Down Expand Up @@ -174,10 +175,11 @@ public static function createFromExistingFile(
\mkdir($filePath, recursive: true);
}

\rename(
$pathname,
$filePath . $file->getSourceFilename()
);
if ($copy) {
\copy($pathname, $filePath . $file->getSourceFilename());
} else {
\rename($pathname, $filePath . $file->getSourceFilename());
}

return $file;
}
Expand Down

This file was deleted.

13 changes: 13 additions & 0 deletions wcfsetup/install/files/lib/system/importer/UserImporter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace wcf\system\importer;

use wcf\data\file\FileEditor;
use wcf\data\user\group\UserGroup;
use wcf\data\user\option\UserOption;
use wcf\data\user\option\UserOptionList;
Expand Down Expand Up @@ -201,6 +202,18 @@ public function import($oldID, array $data, array $additionalData = [])
// assign an interface language
$data['languageID'] = \reset($languageIDs);

if (!empty($additionalData['avatarLocation']) && \is_readable($additionalData['avatarLocation'])) {
$avatarFile = FileEditor::createFromExistingFile(
$additionalData['avatarLocation'],
$additionalData['avatarFilename'] ?? \pathinfo($additionalData['avatarLocation'], \PATHINFO_BASENAME),
'com.woltlab.wcf.user.avatar',
true
);
if ($avatarFile !== null) {
$data['avatarFileID'] = $avatarFile->fileID;
}
}

// create user
$user = UserEditor::create($data);
$userEditor = new UserEditor($user);
Expand Down

0 comments on commit af4056e

Please sign in to comment.