user deletion event, with vote deletion
This commit is contained in:
parent
ed4dc632e6
commit
b628bcfa86
@ -93,14 +93,7 @@ class NumericScore extends Extension {
|
|||||||
}
|
}
|
||||||
if($event->page_matches("numeric_score/remove_votes_by") && $user->check_auth_token()) {
|
if($event->page_matches("numeric_score/remove_votes_by") && $user->check_auth_token()) {
|
||||||
if($user->is_admin()) {
|
if($user->is_admin()) {
|
||||||
$user_id = int_escape($_POST['user_id']);
|
$this->delete_votes_by(int_escape($_POST['user_id']));
|
||||||
$image_ids = $database->get_col("SELECT image_id FROM numeric_score_votes WHERE user_id=?", array($user_id));
|
|
||||||
|
|
||||||
$database->execute(
|
|
||||||
"DELETE FROM numeric_score_votes WHERE user_id=? AND image_id IN (".implode(",", $image_ids).")",
|
|
||||||
array($user_id));
|
|
||||||
$database->execute(
|
|
||||||
"UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=images.id) WHERE images.id IN (".implode(",", $image_ids).")");
|
|
||||||
$page->set_mode("redirect");
|
$page->set_mode("redirect");
|
||||||
$page->set_redirect(make_link());
|
$page->set_redirect(make_link());
|
||||||
}
|
}
|
||||||
@ -190,6 +183,22 @@ class NumericScore extends Extension {
|
|||||||
$database->execute("DELETE FROM numeric_score_votes WHERE image_id=:id", array("id" => $event->image->id));
|
$database->execute("DELETE FROM numeric_score_votes WHERE image_id=:id", array("id" => $event->image->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onUserDeletion(UserDeletionEvent $event) {
|
||||||
|
$this->delete_votes_by($event->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete_votes_by(/*int*/ $user_id) {
|
||||||
|
global $database;
|
||||||
|
|
||||||
|
$image_ids = $database->get_col("SELECT image_id FROM numeric_score_votes WHERE user_id=?", array($user_id));
|
||||||
|
|
||||||
|
$database->execute(
|
||||||
|
"DELETE FROM numeric_score_votes WHERE user_id=? AND image_id IN (".implode(",", $image_ids).")",
|
||||||
|
array($user_id));
|
||||||
|
$database->execute(
|
||||||
|
"UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=images.id) WHERE images.id IN (".implode(",", $image_ids).")");
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: on user deletion
|
// FIXME: on user deletion
|
||||||
// FIXME: on user vote nuke
|
// FIXME: on user vote nuke
|
||||||
|
|
||||||
|
@ -40,6 +40,14 @@ class UserCreationEvent extends Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UserDeletionEvent extends Event {
|
||||||
|
var $id;
|
||||||
|
|
||||||
|
public function __construct($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class UserCreationException extends SCoreException {}
|
class UserCreationException extends SCoreException {}
|
||||||
|
|
||||||
class UserPage extends Extension {
|
class UserPage extends Extension {
|
||||||
@ -511,6 +519,8 @@ class UserPage extends Extension {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
send_event(new UserDeletionEvent($_POST['id']));
|
||||||
|
|
||||||
$database->execute(
|
$database->execute(
|
||||||
"DELETE FROM users WHERE id = :id",
|
"DELETE FROM users WHERE id = :id",
|
||||||
array("id" => $_POST['id'])
|
array("id" => $_POST['id'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user