Validate user input on stack size
authorNiels Heinemann <heinemann@kompetenzz.de>
Fri, 20 May 2016 12:29:42 +0000 (14:29 +0200)
committerNiels Heinemann <heinemann@kompetenzz.de>
Fri, 20 May 2016 12:59:02 +0000 (14:59 +0200)
CRM/Admin/Form/Setting/Miscellaneous.php
CRM/Utils/Recent.php
settings/Core.setting.php

index 9f8b189d841f067452a082c2d009ba74f02bb7b8..1a092f5b04b888dea7a989f6dc1b2549cd9dc359 100644 (file)
@@ -102,6 +102,11 @@ class CRM_Admin_Form_Setting_Miscellaneous extends CRM_Admin_Form_Setting {
       $errors['maxFileSize'] = ts("Maximum file size cannot exceed Upload max size ('upload_max_filesize') as defined in PHP.ini.");
     }
 
+    // validate recent items stack size
+    if ($fields['recentItemsMaxCount'] && ($fields['recentItemsMaxCount'] < 1 || $fields['recentItemsMaxCount'] > CRM_Utils_Recent::MAX_ITEMS)) { 
+      $errors['recentItemsMaxCount'] = ts("Illegal stack size. Use values between 1 and %1.", array( 1 => CRM_Utils_Recent::MAX_ITEMS));
+    }
+    
     if (!empty($fields['wkhtmltopdfPath'])) {
       // check and ensure that thi leads to the wkhtmltopdf binary
       // and it is a valid executable binary
index 659b67381f0198367eb978b16242418999d734f6..c596c7b8cb417edf4af0b9dc60ba9ecf51adde23 100644 (file)
@@ -40,7 +40,7 @@ class CRM_Utils_Recent {
    *
    * @var string
    */
-  const STORE_NAME = 'CRM_Utils_Recent';
+  const MAX_ITEMS = 30, STORE_NAME = 'CRM_Utils_Recent';
 
   /**
    * The list of recently viewed items.
@@ -53,14 +53,14 @@ class CRM_Utils_Recent {
    * Maximum stack size
    * @var int
    */
-  static private $_maxItems = 20;
+  static private $_maxItems = 10;
 
   /**
    * Initialize this class and set the static variables.
    */
   public static function initialize() {
     $maxItemsSetting = Civi::settings()->get('recentItemsMaxCount');
-    if (isset($maxItemsSetting) && $maxItemsSetting > 0 && $maxItemsSetting < 100) {
+    if (isset($maxItemsSetting) && $maxItemsSetting > 0 && $maxItemsSetting < self::MAX_ITEMS) {
       self::$_maxItems = $maxItemsSetting;
     }
     if (!self::$_recent) {
index cb6f090b2bda9e7877ad556e7f0bceda7a09d80b..4137ab7d625f3bce9f8dc4f2af43762fc8e51a20 100644 (file)
@@ -839,7 +839,6 @@ return array(
     'title' => 'Size of "Recent Items" stack',
     'is_domain' => 1,
     'is_contact' => 0,
-    'description' => 'How many items should CiviCRM store in it\'s "Recently viewed" list.',
     'help_text' => NULL,
   ),
   'recentItemsProviders' => array(