Skip to content

Commit

Permalink
Bugfix: Fix events and make them more generic for better maintainabil…
Browse files Browse the repository at this point in the history
…ity. (Wunderbyte-GmbH/moodle-paygw_payone#6)
  • Loading branch information
ibernhardf committed Dec 3, 2024
1 parent ebb6b6d commit ccf7cf2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 57 deletions.
12 changes: 11 additions & 1 deletion classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public static function payment_completed() {
cache_helper::purge_by_event('setbackcachedpaymenttable');
}

/**
* Observer for the payment_successful event
*/
public static function payment_successful() {
cache_helper::purge_by_event('setbackcachedpaymenttable');
}

/**
* Observer for the bookingoption_updated event
*
Expand All @@ -65,7 +72,10 @@ public static function bookingoption_updated(\mod_booking\event\bookingoption_up

if (!empty($settings->teachers) && get_config('local_musi', 'autoaddtosubstitutionspool')) {
$teacherids = array_keys($settings->teachers);
if (isset($settings->customfieldsfortemplates['sport']) && isset ($settings->customfieldsfortemplates['sport']['value'])) {
if (
isset($settings->customfieldsfortemplates['sport'])
&& isset ($settings->customfieldsfortemplates['sport']['value'])
) {
$value = $settings->customfieldsfortemplates['sport']['value'];
// Depending on the type of customfield handle differently.
switch (gettype($value)) {
Expand Down
10 changes: 5 additions & 5 deletions db/caches.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

defined('MOODLE_INTERNAL') || die;

$definitions = array(
'cachedpaymenttable' => array(
$definitions = [
'cachedpaymenttable' => [
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => true,
'staticacceleration' => true,
'staticaccelerationsize' => 1,
'invalidationevents' => ['setbackcachedpaymenttable']
),
);
'invalidationevents' => ['setbackcachedpaymenttable'],
],
];

75 changes: 25 additions & 50 deletions db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,56 +26,31 @@

defined('MOODLE_INTERNAL') || die();

$observers = [

// Currently, we add all payment gateways separately.
// TODO: We should do this in a more generic way.
// For example, we could use a base class or wildcards.

// Payunity payment plugin.
[
'eventname' => '\paygw_payunity\event\payment_added',
'callback' => '\local_musi\observer::payment_added',
],
[
'eventname' => '\paygw_payunity\event\payment_completed',
'callback' => '\local_musi\observer::payment_completed',
],
[
'eventname' => '\paygw_payunity\event\payment_successful',
'callback' => '\local_musi\observer::payment_successful',
],
$pluginname = "local_musi";
$paymentplugins = [
"paygw_payunity",
"paygw_mpay24",
"paygw_unigraz",
"paygw_payone",
];
$events = [
"payment_added",
"payment_completed",
"payment_successful",
];

// Mpay24 payment plugin.
[
'eventname' => '\paygw_mpay24\event\payment_added',
'callback' => '\local_musi\observer::payment_added',
],
[
'eventname' => '\paygw_mpay24\event\payment_completed',
'callback' => '\local_musi\observer::payment_completed',
],
[
'eventname' => '\paygw_mpay24\event\payment_successful',
'callback' => '\local_musi\observer::payment_successful',
],
$observers = [];
foreach ($paymentplugins as $paymentplugin) {
foreach ($events as $event) {
$observers[] = [
'eventname' => "\\{$paymentplugin}\\event\\{$event}",
'callback' => "\\{$pluginname}\\observer::{$event}",
];
}
}

// Unigraz payment plugin.
[
'eventname' => '\paygw_unigraz\event\payment_added',
'callback' => '\local_musi\observer::payment_added',
],
[
'eventname' => '\paygw_unigraz\event\payment_completed',
'callback' => '\local_musi\observer::payment_completed',
],
[
'eventname' => '\paygw_unigraz\event\payment_successful',
'callback' => '\local_musi\observer::payment_successful',
],
// Other events.
[
'eventname' => '\mod_booking\event\bookingoption_updated',
'callback' => '\local_musi\observer::bookingoption_updated',
],
// Other events (non-generic) can be added here.
$observers[] = [
'eventname' => '\mod_booking\event\bookingoption_updated',
'callback' => '\local_musi\observer::bookingoption_updated',
];
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

$plugin->component = 'local_musi';
$plugin->release = '0.9.11';
$plugin->version = 2024112000;
$plugin->version = 2024112003;
$plugin->requires = 2022112800; // Requires this Moodle version. Current: Moodle 4.1.
$plugin->maturity = MATURITY_STABLE;
$plugin->dependencies = [
Expand Down

0 comments on commit ccf7cf2

Please sign in to comment.