This commit is contained in:
Jun Pataleta 2024-04-17 23:42:22 +08:00
commit 9966241efb
No known key found for this signature in database
GPG key ID: F83510526D99E2C7
35 changed files with 127 additions and 204 deletions

View file

@ -0,0 +1,34 @@
<?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/>.
namespace core_user\hook;
use core\hook\stoppable_trait;
/**
* Allow plugins to callback as soon possible after user has completed login.
*
* @package core_user
* @copyright 2024 Juan Leyva
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
#[\core\attribute\label('Allow plugins to callback as soon possible after user has completed login.')]
#[\core\attribute\tags('user', 'login')]
class after_login_completed implements
\Psr\EventDispatcher\StoppableEventInterface
{
use stoppable_trait;
}

View file

@ -29,12 +29,9 @@ use Psr\EventDispatcher\StoppableEventInterface;
#[\core\attribute\label('Allows plugins or features to perform actions before a user is deleted.')]
#[\core\attribute\tags('user')]
class before_user_deleted implements
StoppableEventInterface {
/**
* @var bool Whether the propagation of this event has been stopped.
*/
protected bool $stopped = false;
StoppableEventInterface
{
use \core\hook\stoppable_trait;
/**
* Constructor for the hook.
@ -42,18 +39,8 @@ class before_user_deleted implements
* @param stdClass $user The user instance
*/
public function __construct(
/** @var stdClass The user instance */
public readonly stdClass $user,
) {
}
public function isPropagationStopped(): bool {
return $this->stopped;
}
/**
* Stop the propagation of this event.
*/
public function stop(): void {
$this->stopped = true;
}
}

View file

@ -27,8 +27,7 @@ use stdClass;
*/
#[\core\attribute\label('Allows plugins or features to perform actions before a user is updated.')]
#[\core\attribute\tags('user')]
class before_user_update {
class before_user_updated {
/**
* Constructor for the hook.
*
@ -36,7 +35,9 @@ class before_user_update {
* @param stdClass $currentuserdata The old user instance
*/
public function __construct(
/** @var stdClass The user instance */
public readonly stdClass $user,
/** @var stdClass The old user instance */
public readonly stdClass $currentuserdata,
) {
}

View file

@ -27,8 +27,7 @@ use core\hook\deprecated_callback_replacement;
* @copyright 2024 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class extend_bulk_user_actions implements described_hook, deprecated_callback_replacement {
class extend_bulk_user_actions implements deprecated_callback_replacement, described_hook {
/**
* Describes the hook purpose.
*
@ -56,7 +55,7 @@ class extend_bulk_user_actions implements described_hook, deprecated_callback_re
return ['bulk_user_actions'];
}
/** @var array $actions Stores all added user actions */
/** @var array Stores all added user actions */
private $actions = [];
/**

View file

@ -160,7 +160,7 @@ function user_update_user($user, $updatepassword = true, $triggerevent = true) {
$currentrecord = $DB->get_record('user', ['id' => $user->id]);
// Dispatch the hook for pre user update actions.
$hook = new \core_user\hook\before_user_update(
$hook = new \core_user\hook\before_user_updated(
user: $user,
currentuserdata: $currentrecord,
);