nettoyage du sondage de démonstration

https://framagit.org/framasoft/framadate/issues/316
This commit is contained in:
m 2018-04-13 21:24:43 +02:00
parent f9c3cde701
commit 6455f4be87
3 changed files with 58 additions and 1 deletions

30
admin/cleanDemo.php Normal file
View File

@ -0,0 +1,30 @@
<?php
/**
* This software is governed by the CeCILL-B license. If a copy of this license
* is not distributed with this file, you can obtain one at
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
*
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
* Authors of Framadate/OpenSondage: Framasoft (https://github.com/framasoft)
*
* =============================
*
* Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
* ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
*
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/
use Framadate\Services\LogService;
use Framadate\Services\PurgeService;
include_once __DIR__ . '/../app/inc/init.php';
$logService = new LogService();
$purgeService = new PurgeService($connect, $logService);
$purgeService->cleanDemoPoll();

View File

@ -41,7 +41,13 @@ class VoteRepository extends AbstractRepository {
return $prepared->execute([$poll_id, $vote_id]);
}
public function deleteOldVotesByPollId($poll_id, $votesToDelete) {
$prepared = $this->prepare('DELETE FROM `' . Utils::table('vote') . '` WHERE poll_id = ? ORDER BY `poll_id` ASC LIMIT ' . $votesToDelete);
return $prepared->execute([$poll_id]);
}
/**
* Delete all votes of a given poll.
*

View File

@ -46,7 +46,28 @@ class PurgeService {
return $count;
}
public function cleanDemoPoll() {
if ( !defined("DEMO_POLL_ID")
|| !defined("DEMO_POLL_NUMBER_VOTES")
) {
return;
}
$this->voteRepository->beginTransaction();
$demoVotes = $this->voteRepository->allUserVotesByPollId(DEMO_POLL_ID);
$votesToDelete = count($demoVotes) - DEMO_POLL_NUMBER_VOTES;
if ($votesToDelete > 0) {
$this->voteRepository->deleteOldVotesByPollId(DEMO_POLL_ID, $votesToDelete);
}
$this->voteRepository->commit();
}
/**
* This methode delete all data about a poll.
*