SchemaHandler - Add IF EXISTS to dropTable function
authorColeman Watts <coleman@civicrm.org>
Mon, 20 Mar 2023 15:57:32 +0000 (11:57 -0400)
committerColeman Watts <coleman@civicrm.org>
Mon, 20 Mar 2023 18:49:15 +0000 (14:49 -0400)
CRM/Core/BAO/SchemaHandler.php
api/v3/CustomGroup.php

index 03f39c2decd620e37d581d530f4209e065793c94..62fe656602a83bc6519facd957cb3ca088770c2d 100644 (file)
@@ -268,13 +268,13 @@ ALTER TABLE {$tableName}
   }
 
   /**
-   * Delete a CiviCRM-table.
+   * Drop a table if it exists.
    *
    * @param string $tableName
-   *   Name of the table to be created.
+   * @throws \Civi\Core\Exception\DBQueryException
    */
-  public static function dropTable($tableName) {
-    $sql = "DROP TABLE $tableName";
+  public static function dropTable(string $tableName): void {
+    $sql = "DROP TABLE IF EXISTS $tableName";
     CRM_Core_DAO::executeQuery($sql);
   }
 
index e80f23248021082ddfd8c8fc3663ab02391cf42b..55d5f51774edf85492d65bad6874746e6ac46d60 100644 (file)
@@ -88,8 +88,9 @@ function _civicrm_api3_custom_group_create_spec(&$params) {
 function civicrm_api3_custom_group_delete($params) {
   $values = new CRM_Core_DAO_CustomGroup();
   $values->id = $params['id'];
-  $values->find(TRUE);
-
+  if (!$values->find(TRUE)) {
+    return civicrm_api3_create_error('Error while deleting custom group');
+  }
   $result = CRM_Core_BAO_CustomGroup::deleteGroup($values, TRUE);
   return $result ? civicrm_api3_create_success() : civicrm_api3_create_error('Error while deleting custom group');
 }