Skip to content
Snippets Groups Projects
Commit 78c533ae authored by Alexander Bias's avatar Alexander Bias
Browse files

Change line breaks to mtrace() (MDL-30589)

parent 43dfece6
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ This plugin requires Moodle 2.7+ ...@@ -10,6 +10,7 @@ This plugin requires Moodle 2.7+
Changes Changes
======= =======
2014-08-27 - Change line breaks to mtrace() (MDL-30589)
2014-08-25 - Support new event API, remove legacy event handling 2014-08-25 - Support new event API, remove legacy event handling
2014-07-31 - Add event handler for "user_created" event (see "Fetching user details from LDAP on manual user creation" below for details) 2014-07-31 - Add event handler for "user_created" event (see "Fetching user details from LDAP on manual user creation" below for details)
2014-06-30 - Check compatibility for Moodle 2.7, no functionality change 2014-06-30 - Check compatibility for Moodle 2.7, no functionality change
......
...@@ -57,7 +57,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -57,7 +57,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
function sync_users($do_updates=true) { function sync_users($do_updates=true) {
global $CFG, $DB; global $CFG, $DB;
print_string('connectingldap', 'auth_ldap'); echo "\n"; mtrace(get_string('connectingldap', 'auth_ldap'));
$ldapconnection = $this->ldap_connect(); $ldapconnection = $this->ldap_connect();
$dbman = $DB->get_manager(); $dbman = $DB->get_manager();
...@@ -70,7 +70,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -70,7 +70,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_index('username', XMLDB_INDEX_UNIQUE, array('mnethostid', 'username')); $table->add_index('username', XMLDB_INDEX_UNIQUE, array('mnethostid', 'username'));
print_string('creatingtemptable', 'auth_ldap', 'tmp_extuser'); echo "\n"; mtrace(get_string('creatingtemptable', 'auth_ldap', 'tmp_extuser'));
$dbman->create_temp_table($table); $dbman->create_temp_table($table);
//// ////
...@@ -133,10 +133,10 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -133,10 +133,10 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
/// so as to avoid mass deletion of users; which is hard to undo /// so as to avoid mass deletion of users; which is hard to undo
$count = $DB->count_records_sql('SELECT COUNT(username) AS count, 1 FROM {tmp_extuser}'); $count = $DB->count_records_sql('SELECT COUNT(username) AS count, 1 FROM {tmp_extuser}');
if ($count < 1) { if ($count < 1) {
print_string('didntgetusersfromldap', 'auth_ldap'); echo "\n"; mtrace(get_string('didntgetusersfromldap', 'auth_ldap'));
exit; exit;
} else { } else {
print_string('gotcountrecordsfromldap', 'auth_ldap', $count); echo "\n"; mtrace(get_string('gotcountrecordsfromldap', 'auth_ldap', $count));
} }
...@@ -157,16 +157,17 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -157,16 +157,17 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
$remove_users = $DB->get_records_sql($sql, array('auth'=>$this->authtype)); $remove_users = $DB->get_records_sql($sql, array('auth'=>$this->authtype));
if (!empty($remove_users)) { if (!empty($remove_users)) {
print_string('userentriestoremove', 'auth_ldap', count($remove_users)); echo "\n"; mtrace(get_string('userentriestoremove', 'auth_ldap', count($remove_users)));
foreach ($remove_users as $user) { foreach ($remove_users as $user) {
if (delete_user($user)) { if (delete_user($user)) {
echo "\t"; print_string('auth_dbdeleteuser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n"; mtrace("\t".get_string('auth_dbdeleteuser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)));
} else { } else {
echo "\t"; print_string('auth_dbdeleteusererror', 'auth_db', $user->username); echo "\n"; mtrace("\t".get_string('auth_dbdeleteusererror', 'auth_db', $user->username));
} }
} }
} else { } else {
print_string('nouserentriestoremove', 'auth_ldap'); echo "\n"; mtrace(get_string('nouserentriestoremove', 'auth_ldap'));
} }
unset($remove_users); // Free mem! unset($remove_users); // Free mem!
...@@ -181,18 +182,18 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -181,18 +182,18 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
$remove_users = $DB->get_records_sql($sql, array('auth'=>$this->authtype)); $remove_users = $DB->get_records_sql($sql, array('auth'=>$this->authtype));
if (!empty($remove_users)) { if (!empty($remove_users)) {
print_string('userentriestoremove', 'auth_ldap', count($remove_users)); echo "\n"; mtrace(get_string('userentriestoremove', 'auth_ldap', count($remove_users)));
foreach ($remove_users as $user) { foreach ($remove_users as $user) {
$updateuser = new stdClass(); $updateuser = new stdClass();
$updateuser->id = $user->id; $updateuser->id = $user->id;
$updateuser->suspended = 1; $updateuser->suspended = 1;
user_update_user($updateuser, false); user_update_user($updateuser, false);
echo "\t"; print_string('auth_dbsuspenduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n"; mtrace("\t".get_string('auth_dbsuspenduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)));
\core\session\manager::kill_user_sessions($user->id); \core\session\manager::kill_user_sessions($user->id);
} }
} else { } else {
print_string('nouserentriestoremove', 'auth_ldap'); echo "\n"; mtrace(get_string('nouserentriestoremove', 'auth_ldap'));
} }
unset($remove_users); // Free mem! unset($remove_users); // Free mem!
} }
...@@ -207,7 +208,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -207,7 +208,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
$revive_users = $DB->get_records_sql($sql, array($this->authtype)); $revive_users = $DB->get_records_sql($sql, array($this->authtype));
if (!empty($revive_users)) { if (!empty($revive_users)) {
print_string('userentriestorevive', 'auth_ldap', count($revive_users)); echo "\n"; mtrace(get_string('userentriestorevive', 'auth_ldap', count($revive_users)));
foreach ($revive_users as $user) { foreach ($revive_users as $user) {
$updateuser = new stdClass(); $updateuser = new stdClass();
...@@ -215,10 +216,10 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -215,10 +216,10 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
$updateuser->auth = $this->authtype; $updateuser->auth = $this->authtype;
$updateuser->suspended = 0; $updateuser->suspended = 0;
user_update_user($updateuser, false); user_update_user($updateuser, false);
echo "\t"; print_string('auth_dbreviveduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n"; mtrace("\t".get_string('auth_dbreviveduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)));
} }
} else { } else {
print_string('nouserentriestorevive', 'auth_ldap'); echo "\n"; mtrace(get_string('nouserentriestorevive', 'auth_ldap'));
} }
unset($revive_users); unset($revive_users);
...@@ -237,7 +238,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -237,7 +238,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
$revive_users = $DB->get_records_sql($sql, array($this->authtype)); $revive_users = $DB->get_records_sql($sql, array($this->authtype));
if (!empty($revive_users)) { if (!empty($revive_users)) {
print_string('userentriestorevive', 'auth_ldap', count($revive_users)); echo "\n"; mtrace(get_string('userentriestorevive', 'auth_ldap', count($revive_users)));
foreach ($revive_users as $user) { foreach ($revive_users as $user) {
$updateuser = new stdClass(); $updateuser = new stdClass();
...@@ -245,10 +246,10 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -245,10 +246,10 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
$updateuser->auth = $this->authtype; $updateuser->auth = $this->authtype;
$updateuser->suspended = 0; $updateuser->suspended = 0;
user_update_user($updateuser, false); user_update_user($updateuser, false);
echo "\t"; print_string('auth_dbreviveduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n"; mtrace("\t".get_string('auth_dbreviveduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)));
} }
} else { } else {
print_string('nouserentriestorevive', 'auth_ldap'); echo "\n"; mtrace(get_string('nouserentriestorevive', 'auth_ldap'));
} }
unset($revive_users); unset($revive_users);
...@@ -263,7 +264,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -263,7 +264,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
$remove_users = $DB->get_records_sql($sql, array('auth'=>$this->authtype)); $remove_users = $DB->get_records_sql($sql, array('auth'=>$this->authtype));
if (!empty($remove_users)) { if (!empty($remove_users)) {
print_string('userentriestosuspend', 'auth_ldap_syncplus', count($remove_users)); echo "\n"; mtrace(get_string('userentriestosuspend', 'auth_ldap_syncplus', count($remove_users)));
foreach ($remove_users as $user) { foreach ($remove_users as $user) {
$updateuser = new stdClass(); $updateuser = new stdClass();
...@@ -271,11 +272,11 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -271,11 +272,11 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
$updateuser->suspended = 1; $updateuser->suspended = 1;
$updateuser->timemodified = time(); // Remember suspend time, abuse timemodified column for this $updateuser->timemodified = time(); // Remember suspend time, abuse timemodified column for this
user_update_user($updateuser, false); user_update_user($updateuser, false);
echo "\t"; print_string('auth_dbsuspenduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n"; mtrace("\t".get_string('auth_dbsuspenduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)));
\core\session\manager::kill_user_sessions($user->id); \core\session\manager::kill_user_sessions($user->id);
} }
} else { } else {
print_string('nouserentriestosuspend', 'auth_ldap_syncplus'); echo "\n"; mtrace(get_string('nouserentriestosuspend', 'auth_ldap_syncplus'));
} }
unset($remove_users); // Free mem! unset($remove_users); // Free mem!
...@@ -289,25 +290,25 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -289,25 +290,25 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
$remove_users = $DB->get_records_sql($sql, array('auth'=>$this->authtype)); $remove_users = $DB->get_records_sql($sql, array('auth'=>$this->authtype));
if (!empty($remove_users)) { if (!empty($remove_users)) {
print_string('userentriestoremove', 'auth_ldap', count($remove_users)); echo "\n"; mtrace(get_string('userentriestoremove', 'auth_ldap', count($remove_users)));
foreach ($remove_users as $user) { foreach ($remove_users as $user) {
// Do only if user was suspended before grace period // Do only if user was suspended before grace period
$graceperiod = max(intval($this->config->removeuser_graceperiod),0); // Fix problems if grace period setting was negative or no number $graceperiod = max(intval($this->config->removeuser_graceperiod),0); // Fix problems if grace period setting was negative or no number
if (time() - $user->timemodified >= $graceperiod * 24 * 3600) { if (time() - $user->timemodified >= $graceperiod * 24 * 3600) {
if (delete_user($user)) { if (delete_user($user)) {
echo "\t"; print_string('auth_dbdeleteuser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n"; mtrace("\t".get_string('auth_dbdeleteuser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)));
} else { } else {
echo "\t"; print_string('auth_dbdeleteusererror', 'auth_db', $user->username); echo "\n"; mtrace("\t".get_string('auth_dbdeleteusererror', 'auth_db', $user->username));
} }
} }
// Otherwise inform about ongoing grace period // Otherwise inform about ongoing grace period
else { else {
echo "\t"; print_string('waitinginremovalqueue', 'auth_ldap_syncplus', array('days'=>$graceperiod, 'name'=>$user->username, 'id'=>$user->id)); echo "\n"; mtrace("\t".get_string('waitinginremovalqueue', 'auth_ldap_syncplus', array('days'=>$graceperiod, 'name'=>$user->username, 'id'=>$user->id)));
} }
} }
} else { } else {
print_string('nouserentriestoremove', 'auth_ldap'); echo "\n"; mtrace(get_string('nouserentriestoremove', 'auth_ldap'));
} }
unset($remove_users); // Free mem! unset($remove_users); // Free mem!
} }
...@@ -329,9 +330,8 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -329,9 +330,8 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
} }
} }
unset($all_keys); unset($key); unset($all_keys); unset($key);
} else { } else {
print_string('noupdatestobedone', 'auth_ldap'); echo "\n"; mtrace(get_string('noupdatestobedone', 'auth_ldap'));
} }
if ($do_updates and !empty($updatekeys)) { // run updates only if relevant if ($do_updates and !empty($updatekeys)) { // run updates only if relevant
$users = $DB->get_records_sql('SELECT u.username, u.id $users = $DB->get_records_sql('SELECT u.username, u.id
...@@ -339,7 +339,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -339,7 +339,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
WHERE u.deleted = 0 AND u.auth = ? AND u.mnethostid = ?', WHERE u.deleted = 0 AND u.auth = ? AND u.mnethostid = ?',
array($this->authtype, $CFG->mnet_localhost_id)); array($this->authtype, $CFG->mnet_localhost_id));
if (!empty($users)) { if (!empty($users)) {
print_string('userentriestoupdate', 'auth_ldap', count($users)); echo "\n"; mtrace(get_string('userentriestoupdate', 'auth_ldap', count($users)));
$sitecontext = context_system::instance(); $sitecontext = context_system::instance();
if (!empty($this->config->creators) and !empty($this->config->memberattribute) if (!empty($this->config->creators) and !empty($this->config->memberattribute)
...@@ -354,11 +354,13 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -354,11 +354,13 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
$maxxcount = 100; $maxxcount = 100;
foreach ($users as $user) { foreach ($users as $user) {
echo "\t"; print_string('auth_dbupdatinguser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id));
if (!$this->update_user_record($user->username, $updatekeys)) { // user_updated event is fired hereby if (!$this->update_user_record($user->username, $updatekeys)) { // user_updated event is fired hereby
echo ' - '.get_string('skipped'); $skipped = ' - '.get_string('skipped');
}
else {
$skipped = '';
} }
echo "\n"; mtrace("\t".get_string('auth_dbupdatinguser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)).$skipped);
$xcount++; $xcount++;
// Update course creators if needed // Update course creators if needed
...@@ -374,7 +376,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -374,7 +376,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
unset($users); // free mem unset($users); // free mem
} }
} else { // end do updates } else { // end do updates
print_string('noupdatestobedone', 'auth_ldap'); echo "\n"; mtrace(get_string('noupdatestobedone', 'auth_ldap'));
} }
/// User Additions /// User Additions
...@@ -389,7 +391,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -389,7 +391,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
$add_users = $DB->get_records_sql($sql); $add_users = $DB->get_records_sql($sql);
if (!empty($add_users)) { if (!empty($add_users)) {
print_string('userentriestoadd', 'auth_ldap', count($add_users)); echo "\n"; mtrace(get_string('userentriestoadd', 'auth_ldap', count($add_users)));
$sitecontext = context_system::instance(); $sitecontext = context_system::instance();
if (!empty($this->config->creators) and !empty($this->config->memberattribute) if (!empty($this->config->creators) and !empty($this->config->memberattribute)
...@@ -419,7 +421,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -419,7 +421,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
} }
$id = user_create_user($user, false); $id = user_create_user($user, false);
echo "\t"; print_string('auth_dbinsertuser', 'auth_db', array('name'=>$user->username, 'id'=>$id)); echo "\n"; mtrace("\t".get_string('auth_dbinsertuser', 'auth_db', array('name'=>$user->username, 'id'=>$id)));
$euser = $DB->get_record('user', array('id' => $id)); $euser = $DB->get_record('user', array('id' => $id));
if (!empty($this->config->forcechangepassword)) { if (!empty($this->config->forcechangepassword)) {
...@@ -435,10 +437,10 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { ...@@ -435,10 +437,10 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
$transaction->allow_commit(); $transaction->allow_commit();
unset($add_users); // free mem unset($add_users); // free mem
} else { } else {
print_string('nouserstobeadded', 'auth_ldap'); echo "\n"; mtrace(get_string('nouserstobeadded', 'auth_ldap'));
} }
} else { } else {
print_string('nouserstobeadded', 'auth_ldap'); echo "\n"; mtrace(get_string('nouserstobeadded', 'auth_ldap'));
} }
$dbman->drop_table($table); $dbman->drop_table($table);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment