Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-04-07-15-32-51
[civicrm-core.git] / CRM / Contact / BAO / ContactType.php
index e58e2ea5f4dbd78d898c7297365dc0e4e079da71..67524c32da96a16c374fcc854520a90cbbff8237 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -588,10 +588,10 @@ WHERE name = %1";
   static function add($params) {
 
     // label or name
-    if (!CRM_Utils_Array::value('label', $params)) {
+    if (empty($params['label'])) {
       return;
     }
-    if (CRM_Utils_Array::value('parent_id', $params) &&
+    if (!empty($params['parent_id']) &&
       !CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $params['parent_id'])
     ) {
       return;
@@ -602,8 +602,6 @@ WHERE name = %1";
     $contactType->id = CRM_Utils_Array::value('id', $params);
     $contactType->is_active = CRM_Utils_Array::value('is_active', $params, 0);
 
-
-
     $contactType->save();
     if ($contactType->find(TRUE)) {
       $contactName = $contactType->name;
@@ -611,7 +609,7 @@ WHERE name = %1";
       $active      = $contactType->is_active;
     }
 
-    if (CRM_Utils_Array::value('id', $params)) {
+    if (!empty($params['id'])) {
       $params = array('name' => "New $contactName");
       $newParams = array(
         'label' => "New $contact",
@@ -812,14 +810,16 @@ WHERE extends = %1 AND " . implode(" OR ", $subTypeClause);
    * @return void
    * @access public
    */
-  function deleteCustomRowsOfSubtype($gID, $subtypes = array(
-    )) {
+  public static function deleteCustomRowsOfSubtype($gID, $subtypes = array()) {
     if (!$gID or empty($subtypes)) {
       return FALSE;
     }
 
     $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $gID, 'table_name');
 
+    // drop triggers CRM-13587
+    CRM_Core_DAO::dropTriggers($tableName);
+
     $subtypeClause = array();
     foreach ($subtypes as $subtype) {
       $subtype = CRM_Utils_Type::escape($subtype, 'String');
@@ -831,7 +831,11 @@ WHERE extends = %1 AND " . implode(" OR ", $subTypeClause);
 FROM {$tableName} custom
 INNER JOIN civicrm_contact ON civicrm_contact.id = custom.entity_id
 WHERE ($subtypeClause)";
-    return CRM_Core_DAO::singleValueQuery($query);
+
+    CRM_Core_DAO::singleValueQuery($query);
+
+    // rebuild triggers CRM-13587
+    CRM_Core_DAO::triggerRebuild($tableName);
   }
 
   /**