--fixed for CRM-12141
authorPradeep Nayak <pradeep@pradeep.(none)>
Thu, 21 Mar 2013 15:57:47 +0000 (21:27 +0530)
committerPradeep Nayak <pradeep@pradeep.(none)>
Thu, 21 Mar 2013 15:57:47 +0000 (21:27 +0530)
CRM/Upgrade/Incremental/php/FourThree.php
xml/schema/Financial/EntityFinancialTrxn.xml

index c1a9c93cfb8d2365296633334eeb9722a647b198..c1866a363fee817b1791b16bb14d0f83c9bb7e8d 100644 (file)
@@ -139,6 +139,9 @@ WHERE    entity_value = '' OR entity_value IS NULL
   function upgrade_4_3_alpha1($rev) {
     self::task_4_3_alpha1_checkDBConstraints();
 
+    // add indexes for civicrm_entity_financial_trxn
+    // CRM-12141
+    $this->addTask(ts('Check/Add indexes for civicrm_entity_financial_trxn'), 'task_4_3_x_checkIndexes', $rev);
     // task to process sql
     $this->addTask(ts('Upgrade DB to 4.3.alpha1: SQL'), 'task_4_3_x_runSql', $rev);
 
@@ -206,6 +209,9 @@ WHERE    entity_value = '' OR entity_value IS NULL
 
   function upgrade_4_3_beta4($rev) {
     $this->addTask(ts('Upgrade DB to 4.3.beta4: SQL'), 'task_4_3_x_runSql', $rev);
+    // add indexes for civicrm_entity_financial_trxn
+    // CRM-12141
+    $this->addTask(ts('Check/Add indexes for civicrm_entity_financial_trxn'), 'task_4_3_x_checkIndexes', $rev);
   }
 
   //CRM-11636
@@ -348,6 +354,9 @@ FROM civicrm_entity_financial_account ceft
      INNER JOIN civicrm_option_group cog ON cog.id = cov.option_group_id
 WHERE cog.name = 'payment_instrument'";
     CRM_Core_DAO::executeQuery($sql);
+    //CRM-12141
+    $sql = "ALTER TABLE {$tempTableName1} ADD INDEX index_instrument_id (instrument_id);";
+    CRM_Core_DAO::executeQuery($sql);
 
     //create temp table to process completed / cancelled contribution
     $tempTableName2 = CRM_Core_DAO::createTempTableName();
@@ -379,6 +388,9 @@ FROM   civicrm_contribution con
               ON con.payment_instrument_id = tpi.instrument_id
 WHERE con.contribution_status_id IN ({$completedStatus}, {$cancelledStatus})";
     CRM_Core_DAO::executeQuery($sql);
+    // CRM-12141
+    $sql = "ALTER TABLE {$tempTableName2} ADD INDEX index_action (action);";
+    CRM_Core_DAO::executeQuery($sql);
 
     //handling for completed contribution and cancelled contribution
     //insertion of new records
@@ -771,6 +783,23 @@ AND TABLE_SCHEMA = '{$dbUf['database']}'";
     return TRUE;
   }
 
+  /**
+   * Check/Add INDEX CRM-12141
+   *
+   * @return bool TRUE for success
+   */
+  function task_4_3_x_checkIndexes(CRM_Queue_TaskContext $ctx) {
+    $query = "SHOW KEYS FROM  `civicrm_entity_financial_trxn` 
+WHERE key_name IN ('UI_entity_financial_trxn_entity_table', 'UI_entity_financial_trxn_entity_id');";
+    $dao = CRM_Core_DAO::executeQuery($query);
+    if (!$dao->N) {
+      CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_entity_financial_trxn
+ADD INDEX UI_entity_financial_trxn_entity_table (entity_table),
+ADD INDEX UI_entity_financial_trxn_entity_id (entity_id);");
+    }
+    return TRUE;
+  }
+
   /**
    * Update phones CRM-11292
    *
index 1ff8767730812a8f5648fc98eba805b4c8421866..4df52724153c38c95eb0a8de18ceeb754977cf42 100755 (executable)
     <add>3.2</add>
     <drop>4.3</drop>
   </field>
+  <index>
+    <name>UI_entity_financial_trxn_entity_table</name>
+    <fieldName>entity_table</fieldName>
+    <add>4.3</add>
+  </index> 
+  <index>
+    <name>UI_entity_financial_trxn_entity_id</name>
+    <fieldName>entity_id</fieldName>
+    <add>4.3</add>
+  </index> 
 </table>