From: Marcel Werk Date: Tue, 2 Jul 2013 22:31:22 +0000 (+0200) Subject: Fixed import issues X-Git-Tag: 2.0.0_Beta_5~110 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e1ad68de4eed58f24c70069813b4ac5482d220a3;p=GitHub%2FWoltLab%2FWCF.git Fixed import issues --- diff --git a/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php index 40a0a5d173..b0d0fe7266 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php @@ -27,7 +27,7 @@ class AbstractCommentResponseImporter implements IImporter { if (!$data['userID']) $data['userID'] = null; $data['commentID'] = ImportHandler::getInstance()->getNewID($this->objectTypeName, $data['commentID']); - if ($data['commentID']) return 0; + if (!$data['commentID']) return 0; $action = new CommentResponseAction(array(), 'create', array( 'data' => array_merge($data, array('objectTypeID' => $this->objectTypeID)) diff --git a/wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php index 10680c1437..e58daaff21 100644 --- a/wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php @@ -2,8 +2,9 @@ namespace wcf\system\importer; use wcf\data\user\avatar\UserAvatarAction; use wcf\data\user\avatar\UserAvatarEditor; -use wcf\util\FileUtil; +use wcf\system\exception\SystemException; use wcf\system\WCF; +use wcf\util\FileUtil; /** * Imports user avatars. @@ -23,13 +24,29 @@ class UserAvatarImporter implements IImporter { $fileLocation = $data['fileLocation']; unset($data['fileLocation']); - $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']); - if ($data['userID']) return 0; + // check file location + if (!@file_exists($fileLocation)) return 0; + + // get image size + $imageData = @getimagesize($fileLocation); + if ($imageData === false) return 0; + $data['width'] = $imageData[0]; + $data['height'] = $imageData[1]; + if ($data['width'] < 48 || $data['height'] < 48) return 0; // avatar too small + + // check image type + if ($imageData[2] != IMAGETYPE_GIF && $imageData[2] != IMAGETYPE_JPEG && $imageData[2] != IMAGETYPE_PNG) return 0; + // get file hash if (empty($data['fileHash'])) $data['fileHash'] = sha1_file($fileLocation); + // get user id + $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']); + if (!$data['userID']) return 0; + + $action = new UserAvatarAction(array(), 'create', array( - 'data' => $data + 'data' => $data )); $returnValues = $action->executeAction(); $avatar = $returnValues['returnValues']; @@ -42,7 +59,11 @@ class UserAvatarImporter implements IImporter { } // copy file - if (@copy($fileLocation, $avatar->getLocation())) { + try { + if (!copy($fileLocation, $avatar->getLocation())) { + throw new SystemException(); + } + // create thumbnails $action = new UserAvatarAction(array($avatar), 'generateThumbnails'); $action->executeAction(); @@ -56,7 +77,7 @@ class UserAvatarImporter implements IImporter { return $avatar->avatarID; } - else { + catch (SystemException $e) { // copy failed; delete avatar $editor = new UserAvatarEditor($avatar); $editor->delete();