From fa111ab04e29cc10825a7e0323922c9e3f334ed4 Mon Sep 17 00:00:00 2001
From: Antonin <zepcome@gmail.com>
Date: Fri, 29 May 2015 18:53:09 +0200
Subject: [PATCH] Prevent from deleting the last slot

	- Also fix the corresponding translation when a problem arise.
---
 adminstuds.php                                      | 2 +-
 app/classes/Framadate/Services/AdminPollService.php | 8 ++++++++
 locale/de.json                                      | 3 ++-
 locale/en.json                                      | 3 ++-
 locale/es.json                                      | 3 ++-
 locale/fr.json                                      | 3 ++-
 locale/it.json                                      | 3 ++-
 7 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/adminstuds.php b/adminstuds.php
index 0ccc5341..baf25c71 100644
--- a/adminstuds.php
+++ b/adminstuds.php
@@ -331,7 +331,7 @@ if (!empty($_GET['delete_column'])) {
     if ($result) {
         $message = new Message('success', __('adminstuds', 'Column removed'));
     } else {
-        $message = new Message('danger', __('Error', 'Failed to delete the column'));
+        $message = new Message('danger', __('Error', 'Failed to delete column'));
     }
 }
 
diff --git a/app/classes/Framadate/Services/AdminPollService.php b/app/classes/Framadate/Services/AdminPollService.php
index b4b47d56..4760f8a4 100644
--- a/app/classes/Framadate/Services/AdminPollService.php
+++ b/app/classes/Framadate/Services/AdminPollService.php
@@ -117,6 +117,10 @@ class AdminPollService {
 
         $slots = $this->pollService->allSlotsByPollId($poll_id);
 
+        if (count($slots) === 1) {
+            return false;
+        }
+
         $index = 0;
         $indexToDelete = -1;
         $newMoments = [];
@@ -155,6 +159,10 @@ class AdminPollService {
 
         $slots = $this->pollService->allSlotsByPollId($poll_id);
 
+        if (count($slots) === 1) {
+            return false;
+        }
+
         $index = 0;
         $indexToDelete = -1;
 
diff --git a/locale/de.json b/locale/de.json
index c0331193..6c831421 100644
--- a/locale/de.json
+++ b/locale/de.json
@@ -326,6 +326,7 @@
         "Update vote failed": "Update vote failed",
         "Adding vote failed": "Adding vote failed",
         "Comment failed": "Kommentar gescheitert",
-        "You can't create a poll with hidden results with the following edition option:": "Sie können nicht eine Umfrage erstellen mit versteckten Ergebnisse mit der folgenden Ausgabe-Option:"
+        "You can't create a poll with hidden results with the following edition option:": "Sie können nicht eine Umfrage erstellen mit versteckten Ergebnisse mit der folgenden Ausgabe-Option:",
+        "Failed to delete column": "Fehler beim Spalte löschen"
     }
 }
diff --git a/locale/en.json b/locale/en.json
index d63249cb..d731d3f2 100644
--- a/locale/en.json
+++ b/locale/en.json
@@ -326,6 +326,7 @@
     "Update vote failed": "Update vote failed",
     "Adding vote failed": "Adding vote failed",
     "Comment failed": "Comment failed",
-    "You can't create a poll with hidden results with the following edition option:": "You can't create a poll with hidden results with the following edition option: "
+    "You can't create a poll with hidden results with the following edition option:": "You can't create a poll with hidden results with the following edition option: ",
+    "Failed to delete column": "Failed to delete column"
   }
 }
diff --git a/locale/es.json b/locale/es.json
index 032e51fc..2150ff39 100644
--- a/locale/es.json
+++ b/locale/es.json
@@ -326,6 +326,7 @@
         "Update vote failed": "ES_Mise à jour du vote échoué",
         "Adding vote failed": "ES_Ajout d'un vote échoué",
         "Comment failed": "ES_Commentaire échoué",
-        "You can't create a poll with hidden results with the following edition option:": "ES_Vous ne pouvez pas créer de sondage avec résulats cachés avec les options d'éditions suivantes : "
+        "You can't create a poll with hidden results with the following edition option:": "ES_Vous ne pouvez pas créer de sondage avec résulats cachés avec les options d'éditions suivantes : ",
+        "Failed to delete column": "Error al eliminar la columna"
     }
 }
diff --git a/locale/fr.json b/locale/fr.json
index 368772c8..1f97f7e4 100644
--- a/locale/fr.json
+++ b/locale/fr.json
@@ -326,6 +326,7 @@
     "Update vote failed": "Mise à jour du vote échoué",
     "Adding vote failed": "Ajout d'un vote échoué",
     "Comment failed": "Commentaire échoué",
-    "You can't create a poll with hidden results with the following edition option:": "Vous ne pouvez pas créer de sondage avec résulats cachés avec les options d'éditions suivantes : "
+    "You can't create a poll with hidden results with the following edition option:": "Vous ne pouvez pas créer de sondage avec résulats cachés avec les options d'éditions suivantes : ",
+    "Failed to delete column": "Échec de la suppression de colonne"
   }
 }
diff --git a/locale/it.json b/locale/it.json
index fb123030..6ae7e6d8 100644
--- a/locale/it.json
+++ b/locale/it.json
@@ -326,6 +326,7 @@
     "Update vote failed": "IT_Mise à jour du vote échoué",
     "Adding vote failed": "IT_Ajout d'un vote échoué",
     "Comment failed": "IT_Commentaire échoué",
-    "You can't create a poll with hidden results with the following edition option:": "IT_Vous ne pouvez pas créer de sondage avec résulats cachés avec les options d'éditions suivantes : "
+    "You can't create a poll with hidden results with the following edition option:": "IT_Vous ne pouvez pas créer de sondage avec résulats cachés avec les options d'éditions suivantes : ",
+    "Failed to delete column": "Impossibile eliminare colonna"
   }
 }
\ No newline at end of file
-- 
GitLab