Skip to content

Commit

Permalink
CRM-20313,CRM-19357: Add index to civicrm_activity.status_id and uniq…
Browse files Browse the repository at this point in the history
…ue index to civicrm_entity_financial_account table
  • Loading branch information
JoeMurray authored and monishdeb committed Apr 12, 2017
1 parent 56a2c47 commit eaca7bc
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 7 deletions.
10 changes: 9 additions & 1 deletion CRM/Activity/DAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* Generated from xml/schema/CRM/Activity/Activity.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:b54cc88c35882c1870fcfe97d9a529bc)
* (GenCodeChecksum:1b8c64be69ce6eb0f73b6657c822cb39)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
Expand Down Expand Up @@ -718,6 +718,14 @@ public static function indices($localize = TRUE) {
'localizable' => false,
'sig' => 'civicrm_activity::0::activity_type_id',
) ,
'index_status_id' => array(
'name' => 'index_status_id',
'field' => array(
0 => 'status_id',
) ,
'localizable' => false,
'sig' => 'civicrm_activity::0::status_id',
) ,
'index_medium_id' => array(
'name' => 'index_medium_id',
'field' => array(
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/DAO/AllCoreTables.data.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
// (GenCodeChecksum:de6dc96f4442bc90970f8e8c26b1c802)
// (GenCodeChecksum:75fd93179ce06b6291a503a0d0668aca)
return array(
'CRM_Core_DAO_AddressFormat' => array(
'name' => 'AddressFormat',
Expand Down
16 changes: 14 additions & 2 deletions CRM/Financial/DAO/EntityFinancialAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* Generated from xml/schema/CRM/Financial/EntityFinancialAccount.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:227febd12437c66f2e3ef5b3689f9901)
* (GenCodeChecksum:e465d92f1aeb4c8c943fbc161a0e2ef7)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
Expand Down Expand Up @@ -247,7 +247,19 @@ static function &export($prefix = false) {
* Returns the list of indices
*/
public static function indices($localize = TRUE) {
$indices = array();
$indices = array(
'index_entity_id_entity_table' => array(
'name' => 'index_entity_id_entity_table',
'field' => array(
0 => 'entity_id',
1 => 'entity_table',
2 => 'account_relationship',
) ,
'localizable' => false,
'unique' => true,
'sig' => 'civicrm_entity_financial_account::1::entity_id::entity_table::account_relationship',
) ,
);
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
}
14 changes: 12 additions & 2 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3689,10 +3689,20 @@ protected function relationForFinancialTypeWithFinancialAccount($financialTypeId
$account = CRM_Financial_BAO_FinancialAccount::add($params);
$entityParams = array(
'entity_table' => 'civicrm_financial_type',
'account_relationship' => key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Sales Tax Account is' ")),
'entity_id' => $financialTypeId,
'financial_account_id' => $account->id,
'account_relationship' => key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Sales Tax Account is' ")),
);

//CRM-20313: As per unique index added in civicrm_entity_financial_account table,
// first check if there's any record on basis of unique key (entity_table, account_relationship, entity_id)
$dao = new CRM_Financial_DAO_EntityFinancialAccount();
$dao->copyValues($entityParams);
$dao->find();
if ($dao->fetch()) {
$entityParams['id'] = $dao->id;
}
$entityParams['financial_account_id'] = $account->id;

return CRM_Financial_BAO_FinancialTypeAccount::add($entityParams);
}

Expand Down
5 changes: 5 additions & 0 deletions xml/schema/Activity/Activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@
<type>Select</type>
</html>
</field>
<index>
<name>index_status_id</name>
<fieldName>status_id</fieldName>
<add>4.7</add>
</index>
<field>
<name>priority_id</name>
<type>int unsigned</type>
Expand Down
9 changes: 8 additions & 1 deletion xml/schema/Financial/EntityFinancialAccount.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,12 @@
<add>4.3</add>
<onDelete>RESTRICT</onDelete>
</foreignKey>
<index>
<name>index_entity_id_entity_table</name>
<fieldName>entity_id</fieldName>
<fieldName>entity_table</fieldName>
<fieldName>account_relationship</fieldName>
<unique>true</unique>
<add>4.7</add>
</index>
</table>

0 comments on commit eaca7bc

Please sign in to comment.