date.chapril.org-framadate/app/classes/Framadate/Services/PurgeService.php

61 lines
1.8 KiB
PHP
Raw Normal View History

2014-12-28 23:43:47 +01:00
<?php
namespace Framadate\Services;
use Framadate\FramaDB;
/**
2014-12-29 21:54:07 +01:00
* This service helps to purge data.
2014-12-28 23:43:47 +01:00
*
* @package Framadate\Services
*/
class PurgeService {
private $connect;
2014-12-29 21:54:07 +01:00
private $logService;
2014-12-28 23:43:47 +01:00
2014-12-29 21:54:07 +01:00
function __construct(FramaDB $connect, LogService $logService) {
2014-12-28 23:43:47 +01:00
$this->connect = $connect;
2014-12-29 21:54:07 +01:00
$this->logService = $logService;
2014-12-28 23:43:47 +01:00
}
/**
* This methode purges all old polls (the ones with end_date in past).
*
* @return bool true is action succeeded
*/
function purgeOldPolls() {
2014-12-29 21:54:07 +01:00
$oldPolls = $this->connect->findOldPolls();
$count = count($oldPolls);
if ($count > 0) {
$this->logService->log('EXPIRATION', 'Going to purge ' . $count . ' poll(s)...');
foreach ($oldPolls as $poll) {
if ($this->purgePollById($poll->poll_id)) {
$this->logService->log('EXPIRATION_SUCCESS', 'id: ' . $poll->poll_id . ', title:' . $poll->title . ', format: '.$poll->format . ', admin: ' . $poll->admin_name);
} else {
$this->logService->log('EXPIRATION_FAILED', 'id: ' . $poll->poll_id . ', title:' . $poll->title . ', format: '.$poll->format . ', admin: ' . $poll->admin_name);
}
}
}
2014-12-28 23:43:47 +01:00
return false;
}
/**
* This methode delete all data about a poll.
*
* @param $poll_id int The ID of the poll
* @return bool true is action succeeded
*/
function purgePollById($poll_id) {
2014-12-29 21:54:07 +01:00
$done = false;
$done |= $this->connect->deleteCommentsByPollId($poll_id);
$done |= $this->connect->deleteVotesByPollId($poll_id);
$done |= $this->connect->deleteSlotsByPollId($poll_id);
$done |= $this->connect->deletePollById($poll_id);
return $done;
2014-12-28 23:43:47 +01:00
}
}