[MEDIA][EXCEPTIONS] Fix errors and deprecations
This commit is contained in:
parent
08e5b313ce
commit
4128a5403d
@ -49,7 +49,7 @@ class Avatar extends Controller
|
||||
}
|
||||
|
||||
$res = $result[0];
|
||||
return Media::sendFile(EAvatar::getFilePath($res['file_hash']), $res['mimetype'], $res['title']);
|
||||
return Media::sendFile(EAvatar::getFilePathStatic($res['file_hash']), $res['mimetype'], $res['title']);
|
||||
default:
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ use App\Core\Log;
|
||||
use App\Core\Module;
|
||||
use App\Entity\File;
|
||||
use App\Util\Common;
|
||||
use App\Util\Exception\ClientException;
|
||||
use App\Util\Nickname;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
||||
|
@ -62,7 +62,7 @@ class Controller extends AbstractController implements EventSubscriberInterface
|
||||
$controller = $event->getController();
|
||||
$request = $event->getRequest();
|
||||
|
||||
if (($avatar = DB::find('avatar', ['profile_id' => Common::profile()->getId()])) != null) {
|
||||
if (($user = Common::user()) !== null && ($avatar = DB::find('avatar', ['profile_id' => $user->getProfile()->getId()])) != null) {
|
||||
$avatar_filename = $avatar->getUrl();
|
||||
} else {
|
||||
$avatar_filename = '/public/assets/default_avatar.svg';
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
// {{{ License
|
||||
|
||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||
//
|
||||
// GNU social is free software: you can redistribute it and/or modify
|
||||
@ -15,6 +16,7 @@
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// }}}
|
||||
|
||||
namespace App\Entity;
|
||||
@ -107,9 +109,14 @@ class Avatar extends Entity
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
public function getFilePath(?string $filename = null): string
|
||||
public static function getFilePathStatic(string $filename): string
|
||||
{
|
||||
return Common::config('avatar', 'dir') . '/' . $filename ?: $this->getFile()->getFileName();
|
||||
return Common::config('avatar', 'dir') . '/' . $filename;
|
||||
}
|
||||
|
||||
public function getFilePath(): string
|
||||
{
|
||||
return Common::config('avatar', 'dir') . '/' . $this->getFile()->getFileName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -202,12 +202,12 @@ class Profile extends Entity
|
||||
|
||||
// }}} Autocode
|
||||
|
||||
public function getFromId(int $id): ?self
|
||||
public static function getFromId(int $id): ?self
|
||||
{
|
||||
return DB::find('profile', ['id' => $id]);
|
||||
}
|
||||
|
||||
public function getFromNickname(string $nickname): ?self
|
||||
public static function getFromNickname(string $nickname): ?self
|
||||
{
|
||||
return DB::findOneBy('profile', ['nickname' => $nickname]);
|
||||
}
|
||||
|
@ -70,12 +70,12 @@ abstract class Common
|
||||
DB::flush();
|
||||
}
|
||||
|
||||
public static function user(): LocalUser
|
||||
public static function user(): ?LocalUser
|
||||
{
|
||||
return Security::getUser();
|
||||
}
|
||||
|
||||
public static function profile(): Profile
|
||||
public static function profile(): ?Profile
|
||||
{
|
||||
return self::user()->getProfile();
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
namespace App\Util\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Client exception. Indicates a client request contains some sort of
|
||||
* error. HTTP code 400
|
||||
|
@ -40,7 +40,7 @@ namespace App\Util\Exception;
|
||||
*/
|
||||
class NicknameInvalidException extends NicknameException
|
||||
{
|
||||
protected function defaultMessage()
|
||||
protected function defaultMessage(): string
|
||||
{
|
||||
// TRANS: Validation error in form for registration, profile and group settings, etc.
|
||||
return _m('Nickname must have only lowercase letters and numbers and no spaces.');
|
||||
|
@ -40,7 +40,7 @@ namespace App\Util\Exception;
|
||||
*/
|
||||
class NicknameReservedException extends NicknameException
|
||||
{
|
||||
protected function defaultMessage()
|
||||
protected function defaultMessage(): string
|
||||
{
|
||||
// TRANS: Validation error in form for registration, profile and group settings, etc.
|
||||
return _m('Nickname is reserved.');
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
// {{{ License
|
||||
|
||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||
//
|
||||
// GNU social is free software: you can redistribute it and/or modify
|
||||
@ -15,6 +16,7 @@
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// }}}
|
||||
|
||||
namespace App\Util\Exception;
|
||||
@ -48,7 +50,7 @@ class NicknameTakenException extends NicknameException
|
||||
parent::__construct($msg, $code);
|
||||
}
|
||||
|
||||
protected function defaultMessage()
|
||||
protected function defaultMessage(): string
|
||||
{
|
||||
// TRANS: Validation error in form for registration, profile and group settings, etc.
|
||||
return _m('Nickname is already in use on this server.');
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
// {{{ License
|
||||
|
||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||
//
|
||||
// GNU social is free software: you can redistribute it and/or modify
|
||||
@ -15,6 +16,7 @@
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// }}}
|
||||
|
||||
namespace App\Util\Exception;
|
||||
@ -42,7 +44,7 @@ use App\Util\Nickname;
|
||||
*/
|
||||
class NicknameTooLongException extends NicknameInvalidException
|
||||
{
|
||||
protected function defaultMessage()
|
||||
protected function defaultMessage(): string
|
||||
{
|
||||
// TRANS: Validation error in form for registration, profile and group settings, etc.
|
||||
return _m('Nickname cannot be more than # character long.', ['count' => Nickname::MAX_LEN]);
|
||||
|
Loading…
Reference in New Issue
Block a user