Merge pull request #3749 from civicrm/4.4
[civicrm-core.git] / CRM / Utils / API / ReloadOption.php
index 92e9e55b0b3599011727224fa3d3799c303fae62..c1fa5583aee109b5d01e95fd14ecafbba99f7e15 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -26,8 +26,8 @@
 */
 
 /**
- * Implement the "api.reload" option. This option can be used with "create" to
- * force the API to reload a clean copy of the entity before returning the result.
+ * Implement the "reload" option. This option can be used with "create" to force
+ * the API to reload a clean copy of the entity before returning the result.
  *
  * @code
  * $clean = civicrm_api('myentity', 'create', array(
  * @endcode
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  */
 
 require_once 'api/Wrapper.php';
+
+/**
+ * Class CRM_Utils_API_ReloadOption
+ */
 class CRM_Utils_API_ReloadOption implements API_Wrapper {
 
   /**
@@ -72,7 +76,7 @@ class CRM_Utils_API_ReloadOption implements API_Wrapper {
    */
   public function toApiOutput($apiRequest, $result) {
     $reloadMode = NULL;
-    if ($apiRequest['action'] === 'create' && isset($apiRequest['params'], $apiRequest['params']['options']$apiRequest['params']['options']['reload'])) {
+    if ($apiRequest['action'] === 'create' && isset($apiRequest['params'], $apiRequest['params']['options']) && is_array($apiRequest['params']['options']) && isset($apiRequest['params']['options']['reload'])) {
       if (!CRM_Utils_Array::value('is_error', $result, FALSE)) {
         $reloadMode = $apiRequest['params']['options']['reload'];
       }
@@ -82,6 +86,7 @@ class CRM_Utils_API_ReloadOption implements API_Wrapper {
       case NULL:
       case '0':
       case 'null':
+      case '':
         return $result;
 
       case '1':
@@ -106,7 +111,7 @@ class CRM_Utils_API_ReloadOption implements API_Wrapper {
         return $result;
 
       default:
-        throw new API_Exception("Unknown reload mode");
+        throw new API_Exception("Unknown reload mode " . $reloadMode);
     }
   }