nettoyage du sondage de démonstration
https://framagit.org/framasoft/framadate/issues/316
This commit is contained in:
parent
f9c3cde701
commit
6455f4be87
30
admin/cleanDemo.php
Normal file
30
admin/cleanDemo.php
Normal 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();
|
||||||
|
|
||||||
|
|
@ -42,6 +42,12 @@ class VoteRepository extends AbstractRepository {
|
|||||||
return $prepared->execute([$poll_id, $vote_id]);
|
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.
|
* Delete all votes of a given poll.
|
||||||
*
|
*
|
||||||
|
@ -47,6 +47,27 @@ class PurgeService {
|
|||||||
return $count;
|
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.
|
* This methode delete all data about a poll.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user