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

@ -184,9 +184,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) {
@ -228,15 +225,19 @@ 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", "Не удалось опубликовать пост", "Пост пустой или слишком большой.");
$post = new Post; try {
$post->setOwner($this->user->id); $post = new Post;
$post->setWall($wall); $post->setOwner($this->user->id);
$post->setCreated(time()); $post->setWall($wall);
$post->setContent($this->postParam("text")); $post->setCreated(time());
$post->setAnonymous($anon); $post->setContent($this->postParam("text"));
$post->setFlags($flags); $post->setAnonymous($anon);
$post->setNsfw($this->postParam("nsfw") === "on"); $post->setFlags($flags);
$post->save(); $post->setNsfw($this->postParam("nsfw") === "on");
$post->save();
} catch (\LengthException $ex) {
$this->flashFail("err", "Не удалось опубликовать пост", "Пост слишком большой.");
}
if(!is_null($photo)) if(!is_null($photo))
$post->attach($photo); $post->attach($photo);