Favoriting a post automatically votes it up now
It's still possible for user to withdraw his vote afterwards for whatever reason.
This commit is contained in:
parent
72946c3922
commit
2aefafa473
3 changed files with 39 additions and 0 deletions
|
@ -346,6 +346,7 @@ class PostController
|
|||
if (!$this->context->loggedIn)
|
||||
throw new SimpleException('Not logged in');
|
||||
|
||||
UserModel::updateUserScore($this->context->user, $post, 1);
|
||||
UserModel::addToUserFavorites($this->context->user, $post);
|
||||
StatusHelper::success();
|
||||
}
|
||||
|
|
19
src/Upgrades/mysql/Upgrade11.sql
Normal file
19
src/Upgrades/mysql/Upgrade11.sql
Normal file
|
@ -0,0 +1,19 @@
|
|||
INSERT
|
||||
INTO post_score(user_id, post_id, score)
|
||||
SELECT user_id, favoritee.post_id, 1
|
||||
FROM favoritee WHERE NOT EXISTS
|
||||
(
|
||||
SELECT *
|
||||
FROM post_score ps2
|
||||
WHERE favoritee.post_id = ps2.post_id
|
||||
AND favoritee.user_id = ps2.user_id
|
||||
);
|
||||
|
||||
UPDATE post_score
|
||||
SET score = 1
|
||||
WHERE user_id IN
|
||||
(
|
||||
SELECT user_id
|
||||
FROM favoritee
|
||||
WHERE favoritee.post_id = post_score.post_id
|
||||
);
|
19
src/Upgrades/sqlite/Upgrade11.sql
Normal file
19
src/Upgrades/sqlite/Upgrade11.sql
Normal file
|
@ -0,0 +1,19 @@
|
|||
INSERT
|
||||
INTO post_score(user_id, post_id, score)
|
||||
SELECT user_id, favoritee.post_id, 1
|
||||
FROM favoritee WHERE NOT EXISTS
|
||||
(
|
||||
SELECT *
|
||||
FROM post_score ps2
|
||||
WHERE favoritee.post_id = ps2.post_id
|
||||
AND favoritee.user_id = ps2.user_id
|
||||
);
|
||||
|
||||
UPDATE post_score
|
||||
SET score = 1
|
||||
WHERE user_id IN
|
||||
(
|
||||
SELECT user_id
|
||||
FROM favoritee
|
||||
WHERE favoritee.post_id = post_score.post_id
|
||||
);
|
Loading…
Reference in a new issue