CMS MADE SIMPLE FORGE

CMS Made Simple Core

 

[#8664] Site preferences "exists" mechanism fail

avatar
Created By: Jean-Christophe Cuvelier (totophe)
Date Submitted: Thu Nov 22 11:00:04 -0500 2012

Assigned To: Robert Campbell (calguy1000)
Version: 1.11.3
CMSMS Version: None
Severity: Trivial
Resolution: Fixed
State: Closed
Summary:
Site preferences "exists" mechanism fail
Detailed Description:
In some cases, the site_prefs database contain entries with empty value. In this
case, the mechanism to choose between insert and update is dislfunctionning. 
Here is a patch with the suggestion on how to deal with it:

Patch:
-------------------------

Index: lib/classes/class.cms_siteprefs.php
===================================================================
--- lib/classes/class.cms_siteprefs.php	(revision 8498)
+++ lib/classes/class.cms_siteprefs.php	(working copy)
@@ -32,6 +32,7 @@
 final class cms_siteprefs
 {
   private static $_prefs;
+  private static $_prefs_keys;
 
   private function __construct() {}
 
@@ -48,6 +49,7 @@
 		for( $i = 0; $i < count($dbr); $i++ ) {
 			$row = $dbr[$i];
 			self::$_prefs[$row['sitepref_name']] = $row['sitepref_value'];
+			self::$_prefs_keys[] = $row['sitepref_name']; // For existing keys with
empty values
 		}
 	}
   }
@@ -82,10 +84,7 @@
   public static function exists($key)
   {
     self::_read();
-    if( in_array($key,array_keys(self::$_prefs)) ) {
-		return TRUE;
-	}
-    return FALSE;
+    return (bool) in_array($key,self::$_prefs_keys);
   }
 
 


History

Comments
avatar
Date: 2012-11-22 11:01
Posted By: Jean-Christophe Cuvelier (totophe)

Updated line +    return (bool) in_array($key,self::$_prefs_keys); (forgot the
_keys)
      
avatar
Date: 2012-11-22 11:22
Posted By: Jean-Christophe Cuvelier (totophe)

Sorry, the line 

self::$_prefs_keys[] = $row['sitepref_name']; // For existing keys with empty
values

was also wrong...
      
avatar
Date: 2013-01-28 14:18
Posted By: Robert Campbell (calguy1000)

Need a specifc test case... as I can't see any problem with the code, and have
never had problems with empty values being inserted or updated.
      
avatar
Date: 2013-03-17 00:00
Posted By: Robert Campbell (calguy1000)

Fixed for 2.0
I actually found a specific case to reproduce this.
      
avatar
Date: 2015-09-06 13:08
Posted By: Rolf (rolf1)

CMS Made Simple 2.0 is released
      
Updates

Updated: 2015-09-06 13:08
cmsms_version_id: 29850 => -1
state: Open => Closed

Updated: 2013-03-17 00:00
resolution_id: 5 => 7

Updated: 2012-11-22 11:22
description: In some cases, the site_prefs database contain entries with empty value. In this case, the mechanism to choose between insert and update is dislfunctionning. Here is a patch with the suggestion on how to deal with it: Patch: ------------------------- => In some cases, the site_prefs database contain entries with empty value. In this case, the mechanism to choose between insert and update is dislfunctionning. Here is a patch with the suggestion on how to deal with it: Patch: -------------------------

Updated: 2012-11-22 11:00
description: In some cases, the site_prefs database contain entries with empty value. In this case, the mechanism to choose between insert and update is dislfunctionning. Here is a patch with the suggestion on how to deal with it: Patch: ------------------------- => In some cases, the site_prefs database contain entries with empty value. In this case, the mechanism to choose between insert and update is dislfunctionning. Here is a patch with the suggestion on how to deal with it: Patch: -------------------------
resolution_id: => 5