Skip to content

Commit

Permalink
[#534] draft for updater code
Browse files Browse the repository at this point in the history
  • Loading branch information
bjendres committed May 27, 2020
1 parent 5cd8658 commit a9ee878
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions CRM/Sepa/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,49 @@ public function upgrade_1506() {
$customData->syncOptionGroup(E::path('resources/formats_option_group.json'));
return TRUE;
}

/**
* remove SDD payment processors if not used,
* and disable/warn user if used
*
* @return TRUE on success
* @throws Exception
*/
public function upgrade_1507() {
$this->ctx->log->info("Dealing with migrated payment processor code...");

// get the IDs of the SDD processor types
$sdd_processor_type_ids = [];
$sdd_processor_type_query = civicrm_api3('PaymentProcessorType', 'get', [
'name' => ['IN' => ['SEPA_Direct_Debit', 'SEPA_Direct_Debit_NG']],
'return' => 'id',
'option.limit' => 0,
]);
foreach ($sdd_processor_type_query['values'] as $pp_type) {
$sdd_processor_type_ids[] = (int) $pp_type['id'];
}

// if there is SDD types registered (which should be the case), we have to deal with them
if (!empty($sdd_processor_type_ids)) {
// find out, if they're being used
$sdd_processor_type_id_list = implode(',', $sdd_processor_type_ids);
$use_count = CRM_Core_DAO::singleValueQuery("SELECT COUNT(id) FROM civicrm_payment_processor WHERE payment_processor_type_id IN ({$sdd_processor_type_id_list});");

if ($use_count) {
// if the payment processors are being used, divert them to the dummy processor
// and issue a warning to install the SDD PP extension
$message = E::ts("Your CiviSEPA payment processors have been disabled, the code was moved into a new extension. If you want to continue using your CiviSEPA payment processors, please install the latest version of the <a href=\"https://github.com/Project60/org.project60.sepapp/releases\">CiviSEPA Payment Processor</a> Extension.");
CRM_Core_DAO::executeQuery("UPDATE civicrm_payment_processor_type SET class_name='Payment_Dummy' WHERE id IN ({$sdd_processor_type_id_list});");
CRM_Core_Session::setStatus($message, E::ts("Warning: SDD Payment Processor Disabled!"), 'warn');
Civi::log()->warning($message);

} else {
// if they are _not_ used, we can simply delete them.
foreach ($sdd_processor_type_ids as $sdd_processor_type_id) {
civicrm_api3('PaymentProcessorType', 'delete', ['id' => $sdd_processor_type_id]);
}
}
}
return TRUE;
}
}

0 comments on commit a9ee878

Please sign in to comment.