Skip to content

Commit

Permalink
Improvement: Change location of event observer code, resolves #26
Browse files Browse the repository at this point in the history
  • Loading branch information
abias committed Nov 12, 2024
1 parent 32a339e commit 7b96c2d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 56 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ moodle-auth_ldap_syncplus
Changes
-------

### Unreleased

* 2024-11-12 - Improvement: Change location of event observer code, resolves #26

### v4.5-r1

* 2024-10-14 - Upgrade: Adopt changes from MDL-81960 and use new \core\url class
Expand Down
65 changes: 65 additions & 0 deletions classes/eventobservers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Auth plugin "LDAP SyncPlus" - Event observers
*
* @package auth_ldap_syncplus
* @copyright 2014 Alexander Bias, Ulm University <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace auth_ldap_syncplus;

use moodle_exception;

/**
* Observer class containing methods monitoring various events.
*
* @package auth_ldap_syncplus
* @copyright 2014 Alexander Bias, Ulm University <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class eventobservers {
/**
* User created event observer.
*
* @param \core\event\base $event The event that triggered the handler.
*/
public static function user_created(\core\event\base $event) {
global $DB;

// Do only if user id is enclosed in $eventdata.
if (!empty($event->relateduserid)) {

// Get user data.
$user = $DB->get_record('user', ['id' => $event->relateduserid]);

// Do if user was found.
if (!empty($user->username)) {

// Do only if user has ldap_syncplus authentication.
if (isset($user->auth) && $user->auth == 'ldap_syncplus') {

// Update user.
// Actually, we would want to call auth_plugin_base::update_user_record()
// which is lighter, but this function is unfortunately protected since Moodle 3.5.
update_user_record($user->username);
}
}
}
}
}
3 changes: 1 addition & 2 deletions db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
$observers = [
[
'eventname' => '\core\event\user_created',
'includefile' => '/auth/ldap_syncplus/eventhandler.php',
'callback' => 'update_user_onevent',
'callback' => '\auth_ldap_syncplus\eventobservers::user_created',
],
];
53 changes: 0 additions & 53 deletions eventhandler.php

This file was deleted.

2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'auth_ldap_syncplus';
$plugin->version = 2024100700;
$plugin->version = 2024100701;
$plugin->release = 'v4.5-r1';
$plugin->requires = 2024100700;
$plugin->supported = [405, 405];
Expand Down

0 comments on commit 7b96c2d

Please sign in to comment.