From 00b871df5c5521194f4e7f99e0896d5d1c3029de Mon Sep 17 00:00:00 2001
From: m <m>
Date: Sat, 14 Apr 2018 08:48:24 +0200
Subject: [PATCH] =?UTF-8?q?nettoyage=20du=20sondage=20de=20d=C3=A9monstrat?=
 =?UTF-8?q?ion=20https://framagit.org/framasoft/framadate/issues/316?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/classes/Framadate/Services/PurgeService.php | 5 +++++
 create_classic_poll.php                         | 3 +--
 create_date_poll.php                            | 3 +--
 index.php                                       | 9 +++++++--
 tpl/admin/config.tpl                            | 7 +++++++
 tpl/index.tpl                                   | 4 ++--
 6 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/app/classes/Framadate/Services/PurgeService.php b/app/classes/Framadate/Services/PurgeService.php
index 2d92233d..e0a4aa74 100644
--- a/app/classes/Framadate/Services/PurgeService.php
+++ b/app/classes/Framadate/Services/PurgeService.php
@@ -23,6 +23,11 @@ class PurgeService {
         $this->commentRepository = RepositoryFactory::commentRepository();
     }
 
+    public function repeatedCleanings() {
+    	$this->purgeOldPolls();
+    	$this->cleanDemoPoll();
+    }
+    
     /**
      * This methode purges all old polls (the ones with end_date in past).
      *
diff --git a/create_classic_poll.php b/create_classic_poll.php
index 920b0aec..193b7c88 100644
--- a/create_classic_poll.php
+++ b/create_classic_poll.php
@@ -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);
diff --git a/create_date_poll.php b/create_date_poll.php
index a66330d7..69a5b93b 100644
--- a/create_date_poll.php
+++ b/create_date_poll.php
@@ -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);
diff --git a/index.php b/index.php
index 0052b983..4782288f 100644
--- a/index.php
+++ b/index.php
@@ -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'));
 
diff --git a/tpl/admin/config.tpl b/tpl/admin/config.tpl
index b0ae98f5..e3b22c04 100644
--- a/tpl/admin/config.tpl
+++ b/tpl/admin/config.tpl
@@ -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 */
diff --git a/tpl/index.tpl b/tpl/index.tpl
index 2524f1f7..1d3bafd0 100644
--- a/tpl/index.tpl
+++ b/tpl/index.tpl
@@ -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>
-- 
GitLab