Website api - fix nonstandard BAO delete method
authorColeman Watts <coleman@civicrm.org>
Sat, 3 Feb 2018 23:39:19 +0000 (18:39 -0500)
committerColeman Watts <coleman@civicrm.org>
Sat, 3 Feb 2018 23:39:19 +0000 (18:39 -0500)
CRM/Core/BAO/Website.php
api/v3/Website.php

index 3094bf73cc4bdff612fbd45c57e61c50dc0f6528..9f50a5f85a3e3a7fcef79e43a311c1c916f67418 100644 (file)
@@ -79,7 +79,7 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website {
         self::add($values);
       }
       elseif ($skipDelete && !empty($values['id'])) {
-        self::del(array($values['id']));
+        self::del($values['id']);
       }
     }
   }
@@ -87,15 +87,24 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website {
   /**
    * Delete website.
    *
-   * @param array $ids
-   *   Website ids.
+   * @param int $id
    *
    * @return bool
    */
-  public static function del($ids) {
-    $query = 'DELETE FROM civicrm_website WHERE id IN ( ' . implode(',', $ids) . ')';
-    CRM_Core_DAO::executeQuery($query);
-    // FIXME: we should return false if the del was unsuccessful
+  public static function del($id) {
+    $obj = new self();
+    $obj->id = $id;
+    $obj->find();
+    if ($obj->fetch()) {
+      $params = [];
+      CRM_Utils_Hook::pre('delete', 'Website', $id, $params);
+      $obj->delete();
+    }
+    else {
+      return FALSE;
+    }
+    CRM_Utils_Hook::post('delete', 'Website', $id, $obj);
+    $obj->free();
     return TRUE;
   }
 
index d087858045fb6512022ece81aeda31c7f9aecb4b..34735609db4498000c0a9298c2c1e1bd1df0c9c4 100644 (file)
@@ -64,8 +64,6 @@ function _civicrm_api3_website_create_spec(&$params) {
 /**
  * Deletes an existing Website.
  *
- * @todo convert to using Basic delete - BAO function non standard
- *
  * @param array $params
  *
  * @return array
@@ -73,20 +71,7 @@ function _civicrm_api3_website_create_spec(&$params) {
  * @throws \API_Exception
  */
 function civicrm_api3_website_delete($params) {
-  //DO NOT USE THIS FUNCTION AS THE BASIS FOR A NEW API http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
-  civicrm_api3_verify_mandatory($params, NULL, array('id'));
-  _civicrm_api3_check_edit_permissions('CRM_Core_BAO_Website', array('id' => $params['id']));
-  $websiteDAO = new CRM_Core_DAO_Website();
-  $websiteDAO->id = $params['id'];
-  if ($websiteDAO->find()) {
-    while ($websiteDAO->fetch()) {
-      $websiteDAO->delete();
-      return civicrm_api3_create_success(1, $params, 'Website', 'delete');
-    }
-  }
-  else {
-    throw new API_Exception('Could not delete Website with id ' . $params['id']);
-  }
+  return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
 }
 
 /**