1414| written permission from the original author(s). |
1515+--------------------------------------------------------*/
1616
17+ use Civi \Api4 \BankTransaction ;
1718use CRM_Banking_ExtensionUtil as E ;
1819
1920
@@ -51,28 +52,18 @@ public function run($context)
5152 }
5253
5354 // run a query to the the suggestion strings
54- $ batch = CRM_Core_DAO::executeQuery (
55- "
56- SELECT
57- id AS tx_id,
58- suggestions AS suggestions
59- FROM civicrm_bank_tx bank_tx
60- WHERE bank_tx.id >= %1
61- AND bank_tx.id <= %2
62- AND bank_tx.status_id IN (%3)
63- " ,
64- [
65- 1 => [(int ) $ this ->from_tx_id , 'Integer ' ],
66- 2 => [(int ) $ this ->to_tx_id , 'Integer ' ],
67- 3 => [$ this ->status_ids , 'CommaSeparatedIntegers ' ],
68- ]
69- );
55+ $ transactions = BankTransaction::get ()
56+ ->addSelect ('id ' , 'suggestions ' )
57+ ->addWhere ('id ' , '>= ' , (int ) $ this ->from_tx_id )
58+ ->addWhere ('id ' , '<= ' , (int ) $ this ->to_tx_id )
59+ ->addWhere ('status_id ' , 'IN ' , explode (', ' , $ this ->status_ids ))
60+ ->execute ();
7061
7162 // migrate all of them. We have to use a heuristic to extract the linked
7263 // contributions, because each matcher could do their own thing...
7364 $ contribution_id_parameters = ['contribution_id ' , 'contribution_ids ' ];
74- while ($ batch -> fetch () ) {
75- $ suggestions = json_decode ($ batch -> suggestions , true );
65+ foreach ($ transactions as $ transaction ) {
66+ $ suggestions = json_decode ($ transaction [ ' suggestions ' ] , true );
7667 foreach ($ suggestions as $ suggestion ) {
7768 if (!empty ($ suggestion ['executed ' ])) {
7869 // this suggestion has been executed -> find contribution_ids
@@ -85,7 +76,7 @@ public function run($context)
8576 foreach ($ contribution_ids as $ contribution_id ) {
8677 $ contribution_id = (int ) $ contribution_id ;
8778 if ($ contribution_id ) {
88- CRM_Banking_BAO_BankTransactionContribution::linkContribution ($ batch -> tx_id , $ contribution_id );
79+ CRM_Banking_BAO_BankTransactionContribution::linkContribution ($ transaction [ ' id ' ] , $ contribution_id );
8980 }
9081 }
9182 }
0 commit comments