Merge pull request #10487 from mfb/CRM-20713
[civicrm-core.git] / api / v3 / Case.php
index ddf3aead95c2667d3aac4ca701e01e8363f6c8ea..df6332a3eb258491d183aa39cba3c053bf60e271 100644 (file)
@@ -398,6 +398,42 @@ function _civicrm_api3_case_addtimeline_spec(&$params) {
   );
 }
 
+/**
+ * Merge 2 cases.
+ *
+ * @param array $params
+ *
+ * @throws API_Exception
+ * @return array
+ */
+function civicrm_api3_case_merge($params) {
+  $clients1 = CRM_Case_BAO_Case::getCaseClients($params['case_id_1']);
+  $clients2 = CRM_Case_BAO_Case::getCaseClients($params['case_id_2']);
+  CRM_Case_BAO_Case::mergeCases($clients1[0], $params['case_id_1'], $clients2[0], $params['case_id_2']);
+  return civicrm_api3_create_success();
+}
+
+/**
+ * Adjust Metadata for merge action.
+ *
+ * @param array $params
+ *   Array of parameters determined by getfields.
+ */
+function _civicrm_api3_case_merge_spec(&$params) {
+  $params['case_id_1'] = array(
+    'title' => 'Case ID 1',
+    'description' => 'Id of main case',
+    'type' => CRM_Utils_Type::T_INT,
+    'api.required' => 1,
+  );
+  $params['case_id_2'] = array(
+    'title' => 'Case ID 2',
+    'description' => 'Id of second case',
+    'type' => CRM_Utils_Type::T_INT,
+    'api.required' => 1,
+  );
+}
+
 /**
  * Declare deprecated api functions.
  *
@@ -492,8 +528,7 @@ function civicrm_api3_case_update($params) {
  * @endcode
  *
  * @throws API_Exception
- * @return bool
- *   true if success, else false
+ * @return mixed
  */
 function civicrm_api3_case_delete($params) {
   //check parameters
@@ -507,6 +542,33 @@ function civicrm_api3_case_delete($params) {
   }
 }
 
+/**
+ * Case.restore API specification
+ *
+ * @param array $spec description of fields supported by this API call
+ * @return void
+ */
+function _civicrm_api3_case_restore_spec(&$spec) {
+  $result = civicrm_api3('Case', 'getfields', array('api_action' => 'delete'));
+  $spec = array('id' => $result['values']['id']);
+}
+
+/**
+ * Restore a specified case from the trash.
+ *
+ * @param array $params
+ * @throws API_Exception
+ * @return mixed
+ */
+function civicrm_api3_case_restore($params) {
+  if (CRM_Case_BAO_Case::restoreCase($params['id'])) {
+    return civicrm_api3_create_success($params, $params, 'Case', 'restore');
+  }
+  else {
+    throw new API_Exception('Could not restore case.');
+  }
+}
+
 /**
  * Augment case results with extra data.
  *