admin: Add some logging on important actions (delete poll, clean votes, clean comments, drop column)
This commit is contained in:
parent
a5d1305535
commit
5d8e5362f9
@ -36,7 +36,7 @@ $editingVoteId = 0;
|
||||
/* Services */
|
||||
/*----------*/
|
||||
|
||||
$logService = new LogService();
|
||||
$logService = new LogService(LOG_FILE);
|
||||
$pollService = new PollService($connect);
|
||||
$adminPollService = new AdminPollService($connect, $pollService, $logService);
|
||||
$inputService = new InputService();
|
||||
@ -191,7 +191,6 @@ if (isset($_POST['remove_all_votes'])) {
|
||||
exit;
|
||||
}
|
||||
if (isset($_POST['confirm_remove_all_votes'])) {
|
||||
// TODO Add log
|
||||
if ($adminPollService->cleanVotes($poll_id)) {
|
||||
$message = new Message('success', _('All votes deleted.'));
|
||||
} else {
|
||||
@ -249,7 +248,6 @@ if (isset($_POST['remove_all_comments'])) {
|
||||
exit;
|
||||
}
|
||||
if (isset($_POST['confirm_remove_all_comments'])) {
|
||||
// TODO Add log
|
||||
if ($adminPollService->cleanComments($poll_id)) {
|
||||
$message = new Message('success', _('All comments deleted.'));
|
||||
} else {
|
||||
@ -287,7 +285,6 @@ if (isset($_POST['confirm_delete_poll'])) {
|
||||
// -------------------------------
|
||||
|
||||
if (!empty($_POST['delete_column'])) {
|
||||
// TODO Add log
|
||||
$column = filter_input(INPUT_POST, 'delete_column', FILTER_DEFAULT);
|
||||
|
||||
if ($adminPollService->deleteSlot($poll_id, $column)) {
|
||||
|
@ -42,6 +42,7 @@ class AdminPollService {
|
||||
* @return bool|null true is action succeeded
|
||||
*/
|
||||
function cleanComments($poll_id) {
|
||||
$this->logService->log("CLEAN_COMMENTS", "id:$poll_id");
|
||||
return $this->connect->deleteCommentsByPollId($poll_id);
|
||||
}
|
||||
|
||||
@ -63,6 +64,7 @@ class AdminPollService {
|
||||
* @return bool|null true is action succeeded
|
||||
*/
|
||||
function cleanVotes($poll_id) {
|
||||
$this->logService->log("CLEAN_VOTES", "id:$poll_id");
|
||||
return $this->connect->deleteVotesByPollId($poll_id);
|
||||
}
|
||||
|
||||
@ -74,7 +76,7 @@ class AdminPollService {
|
||||
*/
|
||||
function deleteEntirePoll($poll_id) {
|
||||
$poll = $this->connect->findPollById($poll_id);
|
||||
$this->logService->log("DELETE_POLL", "id$poll->poll_id, format:$poll->format, $poll->admin_name, $poll->admin_mail");
|
||||
$this->logService->log("DELETE_POLL", "id:$poll->poll_id, format:$poll->format, admin:$poll->admin_name, mail:$poll->admin_mail");
|
||||
/*$this->connect->deleteVotesByPollId($poll_id);
|
||||
$this->connect->deleteCommentsByPollId($poll_id);
|
||||
$this->connect->deleteSlotsByPollId($poll_id);
|
||||
@ -91,6 +93,7 @@ class AdminPollService {
|
||||
* @return bool true if action succeeded
|
||||
*/
|
||||
public function deleteSlot($poll_id, $slot) {
|
||||
$this->logService->log("DELETE_SLOT", "id:$poll_id, slot:" . json_encode($slot));
|
||||
$ex = explode('@', $slot);
|
||||
$datetime = $ex[0];
|
||||
$moment = $ex[1];
|
||||
|
@ -8,7 +8,14 @@ namespace Framadate\Services;
|
||||
*/
|
||||
class LogService {
|
||||
|
||||
function __construct() {
|
||||
private $output;
|
||||
|
||||
function __construct($output) {
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
function log($tag, $message) {
|
||||
error_log('[' . $tag . '] ' . $message, 3, $this->output);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,12 @@ class PollService {
|
||||
$this->connect = $connect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a poll from its ID.
|
||||
*
|
||||
* @param $poll_id int The ID of the poll
|
||||
* @return \stdClass|null The found poll, or null
|
||||
*/
|
||||
function findById($poll_id) {
|
||||
if (preg_match('/^[\w\d]{16}$/i', $poll_id)) {
|
||||
return $this->connect->findPollById($poll_id);
|
||||
|
Loading…
Reference in New Issue
Block a user