Moved post featuring to API
This commit is contained in:
parent
ee79e1753e
commit
cebff0ef4e
3 changed files with 40 additions and 8 deletions
|
@ -94,6 +94,7 @@ $postValidation =
|
|||
\Chibi\Router::register(['PostController', 'removeFavoriteAction'], 'POST', '/post/{id}/rem-fav', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'addFavoriteAction'], 'POST', '/post/{id}/add-fav', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'scoreAction'], 'POST', '/post/{id}/score/{score}', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'featureAction'], 'POST', '/post/{id}/feature', $postValidation);
|
||||
|
||||
\Chibi\Router::register(['CommentController', 'listView'], 'GET', '/comments');
|
||||
\Chibi\Router::register(['CommentController', 'listView'], 'GET', '/comments/{page}', ['page' => '\d+']);
|
||||
|
@ -107,7 +108,6 @@ foreach (['GET', 'POST'] as $method)
|
|||
\Chibi\Router::register(['PostController', 'viewAction'], $method, '/post/{id}', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'retrieveAction'], $method, '/post/{name}/retrieve', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'thumbAction'], $method, '/post/{name}/thumb', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'featureAction'], $method, '/post/{id}/feature', $postValidation);
|
||||
|
||||
$tagValidation =
|
||||
[
|
||||
|
|
|
@ -214,13 +214,8 @@ class PostController
|
|||
|
||||
public function featureAction($id)
|
||||
{
|
||||
$context = getContext();
|
||||
$post = PostModel::findByIdOrName($id);
|
||||
Access::assert(Privilege::FeaturePost, Access::getIdentity($post->getUploader()));
|
||||
PropertyModel::set(PropertyModel::FeaturedPostId, $post->id);
|
||||
PropertyModel::set(PropertyModel::FeaturedPostDate, time());
|
||||
PropertyModel::set(PropertyModel::FeaturedPostUserName, Auth::getCurrentUser()->name);
|
||||
LogHelper::log('{user} featured {post} on main page', ['post' => TextHelper::reprPost($post)]);
|
||||
Api::run(new FeaturePostJob(), [
|
||||
FeaturePostJob::POST_ID => $id]);
|
||||
}
|
||||
|
||||
public function viewAction($id)
|
||||
|
|
37
src/Jobs/FeaturePostJob.php
Normal file
37
src/Jobs/FeaturePostJob.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
class FeaturePostJob extends AbstractPostEditJob
|
||||
{
|
||||
public function execute()
|
||||
{
|
||||
$post = $this->post;
|
||||
|
||||
PropertyModel::set(PropertyModel::FeaturedPostId, $post->id);
|
||||
PropertyModel::set(PropertyModel::FeaturedPostDate, time());
|
||||
PropertyModel::set(PropertyModel::FeaturedPostUserName, Auth::getCurrentUser()->name);
|
||||
|
||||
LogHelper::log('{user} featured {post} on main page', [
|
||||
'user' => TextHelper::reprPost(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($post)]);
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
public function requiresPrivilege()
|
||||
{
|
||||
return
|
||||
[
|
||||
Privilege::FeaturePost,
|
||||
Access::getIdentity($this->post->getUploader())
|
||||
];
|
||||
}
|
||||
|
||||
public function requiresAuthentication()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function requiresConfirmedEmail()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue