CRM-14028 - Workaround the number 0 == empty() php bug
authorColeman Watts <coleman@civicrm.org>
Thu, 16 Jan 2014 17:56:28 +0000 (09:56 -0800)
committerColeman Watts <coleman@civicrm.org>
Thu, 16 Jan 2014 17:56:28 +0000 (09:56 -0800)
CRM/Core/BAO/Tag.php
api/v3/Generic/Setvalue.php
api/v3/utils.php

index 3689539a98ff865e4d2ee6dcc1609efa47dcae2d..2ba2c9a1dd78123a0b7880746dcb350ac16cd352 100644 (file)
@@ -356,7 +356,9 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
    * @static
    */
   static function dataExists(&$params) {
-    if (!empty($params['name'])) {
+    // Disallow empty values except for the number zero.
+    // TODO: create a utility for this since it's needed in many places
+    if (!empty($params['name']) || (string) $params['name'] === '0') {
       return TRUE;
     }
 
index 471e700acae2c76136cd78d76bac4d732c11f203..9802d97bc594e56a18b0f7041f9d1b036194b62e 100644 (file)
@@ -26,7 +26,9 @@ function civicrm_api3_generic_setValue($apiRequest) {
   }
 
   $def = $fields[$field];
-  if (array_key_exists('required', $def) && empty($value)) {
+  // Disallow empty values except for the number zero.
+  // TODO: create a utility for this since it's needed in many places
+  if (array_key_exists('required', $def) && empty($value) && $value !== '0' && $value !== 0) {
     return civicrm_api3_create_error(ts("This can't be empty, please provide a value"), array("error_code" => "required", "field" => $field));
   }
 
index 59ba512613afc10d225161669b8c59d1a273b746..f810fcbf42505af0f47c9e5b031f98fe701b0ada 100644 (file)
@@ -116,7 +116,9 @@ function civicrm_api3_verify_mandatory($params, $daoName = NULL, $keys = array(
       }
     }
     else {
-      if (!array_key_exists($key, $params) || empty($params[$key])) {
+      // Disallow empty values except for the number zero.
+      // TODO: create a utility for this since it's needed in many places
+      if (!array_key_exists($key, $params) || (empty($params[$key]) && $params[$key] !== 0 && $params[$key] !== '0')) {
         $unmatched[] = $key;
       }
     }