Skip to content

Commit af4056e

Browse files
committed
Import the avatar in UserImporter and remove UserAvatarImporter
1 parent 21b96a1 commit af4056e

File tree

5 files changed

+24
-99
lines changed

5 files changed

+24
-99
lines changed

com.woltlab.wcf/fileDelete.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,6 +2771,7 @@
27712771
<file>lib/system/html/output/node/HtmlOutputNodeWoltlabSize.class.php</file>
27722772
<file>lib/system/html/output/node/QuoteHtmlOutputNode.class.php</file>
27732773
<file>lib/system/image/Thumbnail.class.php</file>
2774+
<file>lib/system/importer/UserAvatarImporter.class.php</file>
27742775
<file>lib/system/language/I18nPlural.class.php</file>
27752776
<file>lib/system/language/LanguageServerProcessor.class.php</file>
27762777
<file>lib/system/language/preload/LanguagePreloader.class.php</file>

com.woltlab.wcf/objectType.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,6 @@
432432
<definitionname>com.woltlab.wcf.importer</definitionname>
433433
<classname>wcf\system\importer\UserOptionImporter</classname>
434434
</type>
435-
<type>
436-
<name>com.woltlab.wcf.user.avatar</name>
437-
<definitionname>com.woltlab.wcf.importer</definitionname>
438-
<classname>wcf\system\importer\UserAvatarImporter</classname>
439-
</type>
440435
<type>
441436
<name>com.woltlab.wcf.user.comment</name>
442437
<definitionname>com.woltlab.wcf.importer</definitionname>
@@ -1804,5 +1799,8 @@
18041799
<type name="com.woltlab.wcf.sitemap">
18051800
<definitionname>com.woltlab.wcf.rebuildData</definitionname>
18061801
</type>
1802+
<type name="com.woltlab.wcf.user.avatar">
1803+
<definitionname>com.woltlab.wcf.importer</definitionname>
1804+
</type>
18071805
</delete>
18081806
</data>

wcfsetup/install/files/lib/data/file/FileEditor.class.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ public static function createFromTemporary(FileTemporary $fileTemporary): File
117117
public static function createFromExistingFile(
118118
string $pathname,
119119
string $originalFilename,
120-
string $objectTypeName
120+
string $objectTypeName,
121+
bool $copy = false
121122
): ?File {
122123
if (!\is_readable($pathname)) {
123124
return null;
@@ -174,10 +175,11 @@ public static function createFromExistingFile(
174175
\mkdir($filePath, recursive: true);
175176
}
176177

177-
\rename(
178-
$pathname,
179-
$filePath . $file->getSourceFilename()
180-
);
178+
if ($copy) {
179+
\copy($pathname, $filePath . $file->getSourceFilename());
180+
} else {
181+
\rename($pathname, $filePath . $file->getSourceFilename());
182+
}
181183

182184
return $file;
183185
}

wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php

Lines changed: 0 additions & 89 deletions
This file was deleted.

wcfsetup/install/files/lib/system/importer/UserImporter.class.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace wcf\system\importer;
44

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

205+
if (!empty($additionalData['avatarLocation']) && \is_readable($additionalData['avatarLocation'])) {
206+
$avatarFile = FileEditor::createFromExistingFile(
207+
$additionalData['avatarLocation'],
208+
$additionalData['avatarFilename'] ?? \pathinfo($additionalData['avatarLocation'], \PATHINFO_BASENAME),
209+
'com.woltlab.wcf.user.avatar',
210+
true
211+
);
212+
if ($avatarFile !== null) {
213+
$data['avatarFileID'] = $avatarFile->fileID;
214+
}
215+
}
216+
204217
// create user
205218
$user = UserEditor::create($data);
206219
$userEditor = new UserEditor($user);

0 commit comments

Comments
 (0)