forked from ILIAS-eLearning/ILIAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Badge: Show error message on badge image upload error (ILIAS-eLearnin…
- Loading branch information
1 parent
ed99077
commit e9ee5c1
Showing
5 changed files
with
105 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
* | ||
*********************************************************************/ | ||
|
||
use ILIAS\Services\Badge\BadgeException; | ||
|
||
/** | ||
* @author Jörg Lützenkirchen <[email protected]> | ||
*/ | ||
|
@@ -317,7 +319,7 @@ public function getImage(): string | |
} | ||
|
||
/** | ||
* @throws ilException | ||
* @throws BadgeException | ||
*/ | ||
public function uploadImage( | ||
array $a_upload_meta | ||
|
@@ -327,12 +329,20 @@ public function uploadImage( | |
$this->setImage($a_upload_meta["name"]); | ||
$path = $this->getImagePath(); | ||
|
||
if (ilFileUtils::moveUploadedFile($a_upload_meta["tmp_name"], $this->getImagePath(false), $path)) { | ||
$this->update(); | ||
try { | ||
if (ilFileUtils::moveUploadedFile($a_upload_meta['tmp_name'], $this->getImagePath(false), $path)) { | ||
$this->update(); | ||
} | ||
} catch (ilException $e) { | ||
throw BadgeException::moveUploadedBadgeImageFailed($this, $e); | ||
} | ||
|
||
} | ||
} | ||
|
||
/** | ||
* @throws BadgeException | ||
*/ | ||
public function importImage( | ||
string $a_name, | ||
string $a_file | ||
|
@@ -342,6 +352,8 @@ public function importImage( | |
copy($a_file, $this->getImagePath()); // #18280 | ||
|
||
$this->update(); | ||
} else { | ||
throw BadgeException::uploadedBadgeImageFileNotFound($this); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*********************************************************************/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ILIAS\Services\Badge; | ||
|
||
use ilBadge; | ||
use ilException; | ||
|
||
class BadgeException extends ilException | ||
{ | ||
public const EXCEPTION_FILE_NOT_FOUND = 1; | ||
public const EXCEPTION_MOVE_UPLOADED_IMAGE_FAILED = 2; | ||
|
||
private ilBadge $badge; | ||
|
||
public function __construct(int $code, ilBadge $badge, ?ilException $previous_exception = null) | ||
{ | ||
parent::__construct('', $code, $previous_exception); | ||
$this->badge = $badge; | ||
|
||
} | ||
|
||
public static function uploadedBadgeImageFileNotFound(ilBadge $badge, ?ilException $previous_exception = null): self | ||
{ | ||
return new self(self::EXCEPTION_FILE_NOT_FOUND, $badge, $previous_exception); | ||
} | ||
|
||
public static function moveUploadedBadgeImageFailed(ilBadge $badge, ?ilException $previous_exception = null): self | ||
{ | ||
return new self(self::EXCEPTION_MOVE_UPLOADED_IMAGE_FAILED, $badge, $previous_exception); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters