From cebff0ef4e0f98cae379261f26899a0f94dbc19e Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 3 May 2014 19:51:26 +0200 Subject: [PATCH] Moved post featuring to API --- public_html/dispatch.php | 2 +- src/Controllers/PostController.php | 9 ++------ src/Jobs/FeaturePostJob.php | 37 ++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 src/Jobs/FeaturePostJob.php diff --git a/public_html/dispatch.php b/public_html/dispatch.php index ab005763..2d7808a4 100644 --- a/public_html/dispatch.php +++ b/public_html/dispatch.php @@ -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 = [ diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 74255872..970ca611 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -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) diff --git a/src/Jobs/FeaturePostJob.php b/src/Jobs/FeaturePostJob.php new file mode 100644 index 00000000..e40a8187 --- /dev/null +++ b/src/Jobs/FeaturePostJob.php @@ -0,0 +1,37 @@ +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; + } +}