Merge branch 'feature/clean-demo-poll' into 'develop'
Feature/clean demo poll See merge request framasoft/framadate!297
This commit is contained in:
commit
6dd8fb1723
29
admin/cleanDemo.php
Normal file
29
admin/cleanDemo.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?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();
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -23,6 +23,14 @@ class PurgeService {
|
||||
$this->commentRepository = RepositoryFactory::commentRepository();
|
||||
}
|
||||
|
||||
public function repeatedCleanings() {
|
||||
$this->purgeOldPolls();
|
||||
|
||||
if (0 === time() % 10) {
|
||||
$this->cleanDemoPoll();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This methode purges all old polls (the ones with end_date in past).
|
||||
*
|
||||
@ -46,7 +54,24 @@ 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.
|
||||
*
|
||||
|
@ -107,8 +107,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
|
||||
// Clean Form data in $_SESSION
|
||||
unset($_SESSION['form']);
|
||||
|
||||
// Delete old polls
|
||||
$purgeService->purgeOldPolls();
|
||||
$purgeService->repeatedCleanings();
|
||||
|
||||
// creation message
|
||||
$sessionService->set("Framadate", "messagePollCreated", TRUE);
|
||||
|
@ -231,8 +231,7 @@ switch ($step) {
|
||||
// Clean Form data in $_SESSION
|
||||
unset($_SESSION['form']);
|
||||
|
||||
// Delete old polls
|
||||
$purgeService->purgeOldPolls();
|
||||
$purgeService->repeatedCleanings();
|
||||
|
||||
// creation message
|
||||
$sessionService->set("Framadate", "messagePollCreated", TRUE);
|
||||
|
@ -35,14 +35,19 @@ $pollService = new PollService($connect, new $logService());
|
||||
/* PAGE */
|
||||
/* ---- */
|
||||
|
||||
$demoPoll = $pollService->findById('aqg259dth55iuhwm');
|
||||
$demoPollURL = "";
|
||||
|
||||
if (defined("DEMO_POLL_ID")) {
|
||||
$demoPollURL = Utils::getUrlSondage(DEMO_POLL_ID);
|
||||
}
|
||||
|
||||
$nbcol = max( $config['show_what_is_that'] + $config['show_the_software'] + $config['show_cultivate_your_garden'], 1 );
|
||||
|
||||
$smarty->assign('show_what_is_that', $config['show_what_is_that']);
|
||||
$smarty->assign('show_the_software', $config['show_the_software']);
|
||||
$smarty->assign('show_cultivate_your_garden', $config['show_cultivate_your_garden']);
|
||||
$smarty->assign('col_size', 12 / $nbcol);
|
||||
$smarty->assign('demo_poll', $demoPoll);
|
||||
$smarty->assign('demo_poll_url', $demoPollURL);
|
||||
|
||||
$smarty->assign('title', __('Generic', 'Make your polls'));
|
||||
|
||||
|
@ -82,6 +82,13 @@ const MAX_SLOTS_PER_POLL = 366;
|
||||
// Number of seconds before we allow to resend an "Remember Edit Link" email.
|
||||
const TIME_EDIT_LINK_EMAIL = 60;
|
||||
|
||||
// uncomment to display a link to the demo poll at the home page
|
||||
//const DEMO_POLL_ID = "aqg259dth55iuhwm";
|
||||
|
||||
// number of recent votes that are not deleted
|
||||
const DEMO_POLL_NUMBER_VOTES = 10;
|
||||
|
||||
|
||||
// Config
|
||||
$config = [
|
||||
/* general config */
|
||||
|
@ -58,10 +58,10 @@
|
||||
<li>{__('1st section', 'Discuss and make a decision')}</li>
|
||||
</ol>
|
||||
|
||||
{if $demo_poll != null}
|
||||
{if $demo_poll_url}
|
||||
<p>
|
||||
{__('1st section', 'Do you want to')}
|
||||
<a href="{poll_url id='aqg259dth55iuhwm'}">{__('1st section', 'view an example?')}</a>
|
||||
<a href="{$demo_poll_url|html}">{__('1st section', 'view an example?')}</a>
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user