Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20313,CRM-19357: Add index to civicrm_activity.status_id and unique index to civicrm_entity_financial_account table #10056

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:99d8fb551248e9033e030d7d05340a67)
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:b9e9a095e5a6631dd7104828d40ec55a)
*/
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_account_relationship' => array(
'name' => 'index_entity_id_entity_table_account_relationship',
'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;
}
}
11 changes: 10 additions & 1 deletion tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,17 @@ public function createFinancialAccount($financialAccountType, $relationType = NU
'entity_table' => 'civicrm_financial_type',
'entity_id' => $financialType->id,
'account_relationship' => array_search($relationType, $relationTypes),
'financial_account_id' => $financialAccount->id,
);

//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($financialParams);
$dao->find();
if ($dao->fetch()) {
$financialParams['id'] = $dao->id;
}
$financialParams['financial_account_id'] = $financialAccount->id;
$financialAccountType = CRM_Financial_BAO_FinancialTypeAccount::add($financialParams);
}
return array($financialAccount, $financialType, $financialAccountType);
Expand Down
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_account_relationship</name>
<fieldName>entity_id</fieldName>
<fieldName>entity_table</fieldName>
<fieldName>account_relationship</fieldName>
<unique>true</unique>
<add>4.7</add>
</index>
</table>