public function updateAction()
{
$usersId = $this->session->get('identity');
if (!$usersId) {
return $this->response->redirect();
}
if (!$this->request->isPost()) {
return $this->response->redirect();
}
$parametersReply = ['id = ?0 AND (users_id = ?1 OR "Y" = ?2)', 'bind' => [$this->request->getPost('id'), $usersId, $this->session->get('identity-moderator')]];
$postReply = PostsReplies::findFirst($parametersReply);
if (!$postReply) {
return $this->response->redirect();
}
if (!$this->security->checkToken('post-' . $postReply->post->id)) {
$this->flashSession->error('This post is outdated. Please try to update reply again.');
return $this->response->redirect();
}
$content = $this->request->getPost('content');
if (trim($content)) {
$postReply->content = $content;
$postReply->edited_at = time();
if ($postReply->save()) {
if ($usersId != $postReply->users_id) {
$user = Users::findFirstById($usersId);
if ($user) {
if ($user->moderator == 'Y') {
$user->increaseKarma(Karma::MODERATE_REPLY);
$user->save();
}
}
}
}
}
$href = 'discussion/' . $postReply->post->id . '/' . $postReply->post->slug . '#C' . $postReply->id;
return $this->response->redirect($href);
}