-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade: Adopt changes from MDL-73703 and break the sync task user up…
…dates into chunks.
- Loading branch information
Showing
7 changed files
with
143 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?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" - Ad-hoc task definition | ||
* | ||
* @package auth_ldap_syncplus | ||
* @copyright 2024 Alexander Bias, ssystems GmbH <[email protected]> | ||
* based on code by Catalyst IT | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace auth_ldap_syncplus\task; | ||
|
||
use core\task\adhoc_task; | ||
|
||
/** | ||
* The auth_ldap_syncplus ad-hoc task class for LDAP user update | ||
* | ||
* @package auth_ldap_syncplus | ||
* @copyright 2024 Alexander Bias, ssystems GmbH <[email protected]> | ||
* based on code by Catalyst IT | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class asynchronous_sync_task extends adhoc_task { | ||
/** @var string Message prefix for mtrace */ | ||
protected const MTRACE_MSG = 'Synced LDAP (Sync Plus) users'; | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
public function __construct() { | ||
$this->set_component('auth_ldap_syncplus'); | ||
} | ||
|
||
/** | ||
* Run users sync. | ||
*/ | ||
public function execute() { | ||
$data = $this->get_custom_data(); | ||
|
||
/** @var auth_plugin_ldap $auth */ | ||
$auth = get_auth_plugin('ldap_syncplus'); | ||
$auth->update_users($data->users, $data->updatekeys); | ||
|
||
mtrace(sprintf(" %s (%d)", self::MTRACE_MSG, count($data->users))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ | |
* Auth plugin "LDAP SyncPlus" - Task definition | ||
* | ||
* @package auth_ldap_syncplus | ||
* @copyright 2014 Alexander Bias, Ulm University <[email protected]> | ||
* @copyright 2024 Alexander Bias, ssystems GmbH <[email protected]> | ||
* based on code by Catalyst IT | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
|
@@ -28,10 +29,13 @@ | |
* The auth_ldap_syncplus scheduled task class for LDAP user sync | ||
* | ||
* @package auth_ldap_syncplus | ||
* @copyright 2014 Alexander Bias, Ulm University <[email protected]> | ||
* @copyright 2024 Alexander Bias, ssystems GmbH <[email protected]> | ||
* based on code by Catalyst IT | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class sync_task extends \core\task\scheduled_task { | ||
/** @var string Message prefix for mtrace */ | ||
protected const MTRACE_MSG = 'Synced LDAP (Sync Plus) users'; | ||
|
||
/** | ||
* Return localised task name. | ||
|
@@ -48,11 +52,22 @@ public function get_name() { | |
* @return boolean | ||
*/ | ||
public function execute() { | ||
global $CFG; | ||
if (is_enabled_auth('ldap_syncplus')) { | ||
/** @var auth_plugin_ldap_syncplus $auth */ | ||
$auth = get_auth_plugin('ldap_syncplus'); | ||
$auth->sync_users(true); | ||
$count = 0; | ||
$auth->sync_users_update_callback(function ($users, $updatekeys) use (&$count) { | ||
$asynctask = new asynchronous_sync_task(); | ||
$asynctask->set_custom_data([ | ||
'users' => $users, | ||
'updatekeys' => $updatekeys, | ||
]); | ||
\core\task\manager::queue_adhoc_task($asynctask); | ||
|
||
$count++; | ||
mtrace(sprintf(" %s (%d)", self::MTRACE_MSG, $count)); | ||
sleep(1); | ||
}); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters