Do not store truncated JSon for NL.
authorStéphane Jacob <sj@m4x.org>
Mon, 28 Mar 2011 09:28:32 +0000 (11:28 +0200)
committerStéphane Jacob <sj@m4x.org>
Mon, 28 Mar 2011 11:39:36 +0000 (13:39 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
include/newsletter.inc.php
modules/newsletter.php

index 1097f59..623121f 100644 (file)
@@ -829,6 +829,7 @@ class NLIssue
 
     const ERROR_INVALID_SHORTNAME = 'invalid_shortname';
     const ERROR_INVALID_UFC = 'invalid_ufc';
+    const ERROR_TOO_LONG_UFC = 'too_long_ufc';
     const ERROR_SQL_SAVE = 'sql_error';
 
     /** Save the global properties of this NL issue (title&co).
@@ -854,6 +855,11 @@ class NLIssue
             }
             if ($this->sufb->isValid() || $this->sufb->isEmpty()) {
                 $fields['sufb_json'] = json_encode($this->sufb->export()->dict());
+                // If sufb_json is too long to be store, we do not store a truncated json and notify the user.
+                // The limit is LONGTEXT's one, ie 2^32 = 4294967296.
+                if (strlen($fields['sufb_json']) > 4294967295) {
+                    $errors[] = self::ERROR_TOO_LONG_UFC;
+                }
             } else {
                 $errors[] = self::ERROR_INVALID_UFC;
             }
index 5428466..a7d04ee 100644 (file)
@@ -238,6 +238,7 @@ class NewsletterModule extends PLModule
         $error_msgs = array(
             NLIssue::ERROR_INVALID_SHORTNAME => "Le nom court est invalide ou vide.",
             NLIssue::ERROR_INVALID_UFC => "Le filtre des destinataires est invalide.",
+            NLIssue::ERROR_TOO_LONG_UFC => "Le nombre de matricules AX renseigné est trop élevé."
             NLIssue::ERROR_SQL_SAVE => "Une erreur est survenue en tentant de sauvegarder la lettre, merci de réessayer.",
         );