From a4592b1f6ba9635e634bc9817a65685efcca65d2 Mon Sep 17 00:00:00 2001
From: Jaap Jansma <jaap@edeveloper.nl>
Date: Thu, 15 Feb 2018 15:02:25 +0100
Subject: [PATCH] added delete api

---
 CRM/FormProcessor/BAO/FormProcessor.php | 24 ++++++++++++++++++++++++
 api/v3/FormProcessor/Delete.php         | 10 +++++++---
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/CRM/FormProcessor/BAO/FormProcessor.php b/CRM/FormProcessor/BAO/FormProcessor.php
index 0c1efbf..1d365ed 100644
--- a/CRM/FormProcessor/BAO/FormProcessor.php
+++ b/CRM/FormProcessor/BAO/FormProcessor.php
@@ -80,6 +80,30 @@
     return $result;
   }
 
+	/**
+   * Function to delete a FormProcessor with id
+   * 
+   * @param int $id
+   * @throws Exception when $id is empty
+   * @access public
+   * @static
+   */
+  public static function deleteWithId($id) {
+    if (empty($id)) {
+      throw new Exception('id can not be empty when attempting to delete a form processor');
+    }
+
+    CRM_Utils_Hook::pre('delete', 'FormProcessor', $id, CRM_Core_DAO::$_nullArray);
+
+    $rule = new FormProcessor();
+    $rule->id = $id;
+    $rule->delete();
+
+    CRM_Utils_Hook::post('delete', 'FormProcessor', $id, CRM_Core_DAO::$_nullArray);
+
+    return;
+  }
+
 	/**
    * Public function to generate name from label
    *
diff --git a/api/v3/FormProcessor/Delete.php b/api/v3/FormProcessor/Delete.php
index 0ad80a2..0bfeb6d 100644
--- a/api/v3/FormProcessor/Delete.php
+++ b/api/v3/FormProcessor/Delete.php
@@ -8,8 +8,12 @@
  * @return void
  * @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
  */
-function _civicrm_api3_civi_rule_rule_Delete_spec(&$spec) {
-  $spec['id']['api_required'] = 1;
+function _civicrm_api3_form_processor_Delete_spec(&$spec) {
+  $spec['id'] = array(
+		'title' => E::ts('ID'),
+		'type' => CRM_Utils_Type::T_INT,
+		'api_required' => true
+	);
 }
 
 /**
@@ -21,7 +25,7 @@ function _civicrm_api3_civi_rule_rule_Delete_spec(&$spec) {
  * @see civicrm_api3_create_error
  * @throws API_Exception
  */
-function civicrm_api3_civi_rule_rule_Delete($params) {
+function civicrm_api3_form_processor_Delete($params) {
   if (!array_key_exists('id', $params) || empty($params['id'])) {
     throw new API_Exception('Parameter id is mandatory and can not be empty in ' . __METHOD__, 0010);
   } else {
-- 
GitLab