<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>
<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>
<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>
public static function createFromExistingFile(
string $pathname,
string $originalFilename,
- string $objectTypeName,
- bool $copy = false
+ string $objectTypeName
): ?File {
if (!\is_readable($pathname)) {
return null;
\mkdir($filePath, recursive: true);
}
- if ($copy) {
- \copy($pathname, $filePath . $file->getSourceFilename());
- } else {
- \rename($pathname, $filePath . $file->getSourceFilename());
- }
+ \rename(
+ $pathname,
+ $filePath . $file->getSourceFilename()
+ );
return $file;
}
--- /dev/null
+<?php
+
+namespace wcf\system\importer;
+
+use wcf\data\user\avatar\UserAvatar;
+use wcf\data\user\avatar\UserAvatarEditor;
+use wcf\system\exception\SystemException;
+use wcf\system\WCF;
+use wcf\util\FileUtil;
+use wcf\util\ImageUtil;
+
+/**
+ * Imports user avatars.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ */
+class UserAvatarImporter extends AbstractImporter
+{
+ /**
+ * @inheritDoc
+ */
+ protected $className = UserAvatar::class;
+
+ /**
+ * @inheritDoc
+ */
+ public function import($oldID, array $data, array $additionalData = [])
+ {
+ // check file location
+ if (!\is_readable($additionalData['fileLocation'])) {
+ return 0;
+ }
+
+ // get image size
+ $imageData = @\getimagesize($additionalData['fileLocation']);
+ if ($imageData === false) {
+ return 0;
+ }
+ $data['width'] = $imageData[0];
+ $data['height'] = $imageData[1];
+ $data['avatarExtension'] = ImageUtil::getExtensionByMimeType($imageData['mime']);
+ $data['fileHash'] = \sha1_file($additionalData['fileLocation']);
+
+ // check image type
+ if ($imageData[2] != \IMAGETYPE_GIF && $imageData[2] != \IMAGETYPE_JPEG && $imageData[2] != \IMAGETYPE_PNG) {
+ return 0;
+ }
+
+ // get user id
+ $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
+ if (!$data['userID']) {
+ return 0;
+ }
+
+ // save avatar
+ $avatar = UserAvatarEditor::create($data);
+
+ // check avatar directory
+ // and create subdirectory if necessary
+ $dir = \dirname($avatar->getLocation());
+ if (!@\file_exists($dir)) {
+ FileUtil::makePath($dir);
+ }
+
+ // copy file
+ try {
+ if (!\copy($additionalData['fileLocation'], $avatar->getLocation())) {
+ throw new SystemException();
+ }
+
+ // update owner
+ $sql = "UPDATE wcf1_user
+ SET avatarID = ?
+ WHERE userID = ?";
+ $statement = WCF::getDB()->prepare($sql);
+ $statement->execute([$avatar->avatarID, $data['userID']]);
+
+ return $avatar->avatarID;
+ } catch (SystemException $e) {
+ // copy failed; delete avatar
+ $editor = new UserAvatarEditor($avatar);
+ $editor->delete();
+ }
+
+ return 0;
+ }
+}
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;
// 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);