Wall: Handle exception when posting a long post

This commit is contained in:
Maxim Leshchenko 2021-11-20 00:46:51 +02:00
parent b5d1384d08
commit 6562884af2
No known key found for this signature in database
GPG key ID: BB9C44A8733FBEEE

View file

@ -185,9 +185,6 @@ final class WallPresenter extends OpenVKPresenter
if(!$canPost) if(!$canPost)
$this->flashFail("err", "Ошибка доступа", "Вам нельзя писать на эту стену."); $this->flashFail("err", "Ошибка доступа", "Вам нельзя писать на эту стену.");
if(false)
$this->flashFail("err", "Не удалось опубликовать пост", "Пост слишком большой.");
$anon = OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["anonymousPosting"]["enable"]; $anon = OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["anonymousPosting"]["enable"];
if($wallOwner instanceof Club && $this->postParam("as_group") === "on" && $this->postParam("force_sign") !== "on" && $anon) { if($wallOwner instanceof Club && $this->postParam("as_group") === "on" && $this->postParam("force_sign") !== "on" && $anon) {
$manager = $wallOwner->getManager($this->user->identity); $manager = $wallOwner->getManager($this->user->identity);
@ -228,6 +225,7 @@ final class WallPresenter extends OpenVKPresenter
if(empty($this->postParam("text")) && !$photo && !$video) if(empty($this->postParam("text")) && !$photo && !$video)
$this->flashFail("err", "Не удалось опубликовать пост", "Пост пустой или слишком большой."); $this->flashFail("err", "Не удалось опубликовать пост", "Пост пустой или слишком большой.");
try {
$post = new Post; $post = new Post;
$post->setOwner($this->user->id); $post->setOwner($this->user->id);
$post->setWall($wall); $post->setWall($wall);
@ -237,6 +235,9 @@ final class WallPresenter extends OpenVKPresenter
$post->setFlags($flags); $post->setFlags($flags);
$post->setNsfw($this->postParam("nsfw") === "on"); $post->setNsfw($this->postParam("nsfw") === "on");
$post->save(); $post->save();
} catch (\LengthException $ex) {
$this->flashFail("err", "Не удалось опубликовать пост", "Пост слишком большой.");
}
if(!is_null($photo)) if(!is_null($photo))
$post->attach($photo); $post->attach($photo);