Skip to content

Commit

Permalink
letting phpcbf run
Browse files Browse the repository at this point in the history
  • Loading branch information
NinaHerrmann committed Dec 26, 2023
1 parent fb946b0 commit 29248f1
Show file tree
Hide file tree
Showing 17 changed files with 210 additions and 189 deletions.
30 changes: 15 additions & 15 deletions classes/archiveduser.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
require_once($CFG->dirroot.'/user/lib.php');
require_once($CFG->dirroot.'/lib/moodlelib.php');

use \core\session\manager;
use core\session\manager;
/**
* The class collects the necessary information to suspend, delete and activate users.
*
Expand Down Expand Up @@ -97,17 +97,17 @@ public function archive_me() {
}

$timestamp = time();
$tooluser = $DB->get_record('tool_cleanupusers', array('id' => $user->id));
$tooluser = $DB->get_record('tool_cleanupusers', ['id' => $user->id]);

// Document time of editing user in Database.
// In case there is no entry in the tool table make a new one.
if (empty($tooluser)) {
$DB->insert_record_raw('tool_cleanupusers', array('id' => $user->id, 'archived' => 1,
'timestamp' => $timestamp), true, false, true);
$DB->insert_record_raw('tool_cleanupusers', ['id' => $user->id, 'archived' => 1,
'timestamp' => $timestamp, ], true, false, true);
}

// Insert copy of user in second DB and replace user in main table when entry was successful.
$DB->delete_records('tool_cleanupusers_archive', array('id' => $shadowuser->id));
$DB->delete_records('tool_cleanupusers_archive', ['id' => $shadowuser->id]);

$success = $DB->insert_record_raw('tool_cleanupusers_archive', $shadowuser, true, false, true);

Expand Down Expand Up @@ -137,21 +137,21 @@ public function activate_me() {
$user = \core_user::get_user($this->id);

// Deletes record of plugin table tool_cleanupusers.
if (!$DB->record_exists('tool_cleanupusers', array('id' => $user->id))) {
if (!$DB->record_exists('tool_cleanupusers', ['id' => $user->id])) {
throw new cleanupusers_exception(get_string('errormessagenotactive', 'tool_cleanupusers'));
} else if (!$DB->record_exists('tool_cleanupusers_archive', array('id' => $user->id))) {
} else if (!$DB->record_exists('tool_cleanupusers_archive', ['id' => $user->id])) {
throw new cleanupusers_exception(get_string('errormessagenotactive', 'tool_cleanupusers'));
} else if ($DB->record_exists('user', array('username' => $this->username))) {
} else if ($DB->record_exists('user', ['username' => $this->username])) {
throw new cleanupusers_exception(get_string('errormessagenotactive', 'tool_cleanupusers'));
} else {
// Both record exist so we have a user which can be reactivated.
$DB->delete_records('tool_cleanupusers', array('id' => $user->id));
$DB->delete_records('tool_cleanupusers', ['id' => $user->id]);
// If the user is in table replace data.
$shadowuser = $DB->get_record('tool_cleanupusers_archive', array('id' => $user->id));
$shadowuser = $DB->get_record('tool_cleanupusers_archive', ['id' => $user->id]);

$DB->update_record('user', $shadowuser);
// Delete records from tool_cleanupusers_archive table.
$DB->delete_records('tool_cleanupusers_archive', array('id' => $user->id));
$DB->delete_records('tool_cleanupusers_archive', ['id' => $user->id]);
}
// Gets the new user for additional checks.
$transaction->allow_commit();
Expand Down Expand Up @@ -179,20 +179,20 @@ public function delete_me() {
$transaction = $DB->start_delegated_transaction();

// Deletes the records in both plugin tables.
$DB->delete_records('tool_cleanupusers', array('id' => $user->id));
$DB->delete_records('tool_cleanupusers', ['id' => $user->id]);

$DB->delete_records('tool_cleanupusers_archive', array('id' => $user->id));
$DB->delete_records('tool_cleanupusers_archive', ['id' => $user->id]);

// To secure that plugins that reference the user table do not fail create empty user with a hash as username.
$newusername = hash('md5', $user->username);

// Checks whether the username already exist (possible but unlikely).
if (!$DB->record_exists('user', array("username" => $newusername))) {
if (!$DB->record_exists('user', ["username" => $newusername])) {
$user->username = $newusername;
user_update_user($user, false);
} else {
// In the unlikely case that hash(username) exist in the table, while loop generates new username.
while ($DB->record_exists('user', array("username" => $newusername))) {
while ($DB->record_exists('user', ["username" => $newusername])) {
$tempname = $newusername;
$newusername = hash('md5', $user->username . $tempname);
}
Expand Down
6 changes: 3 additions & 3 deletions classes/event/deprovisionusercronjob_completed.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace tool_cleanupusers\event;

use \core\event\base;
use core\event\base;
/**
* The tool_cleanupusers event informs admin about outcome of cron-job.
*
Expand All @@ -43,8 +43,8 @@ class deprovisionusercronjob_completed extends base {
* @return \core\event\base
*/
public static function create_simple($context, $numbersuspended, $numberdeleted) {
return self::create(array('context' => $context, 'other' => array('numbersuspended' => $numbersuspended,
'numberdeleted' => $numberdeleted)));
return self::create(['context' => $context, 'other' => ['numbersuspended' => $numbersuspended,
'numberdeleted' => $numberdeleted, ], ]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/subplugin_select_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function definition() {
$mform = $this->_form;
// Gets all available plugins of type userstatus.
$plugins = core_plugin_manager::instance()->get_plugins_of_type('userstatus');
$types = array();
$types = [];

foreach ($plugins as $value) {
$types[$value->name] = $value->name;
Expand Down
6 changes: 3 additions & 3 deletions classes/table/never_logged_in_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class never_logged_in_table extends \table_sql {
public function __construct($users, $sqlwhere, $param) {
parent::__construct('tool_cleanupusers_never_logged_in_table');
// Define the list of columns to show.
$columns = array('id', 'username', 'fullname', 'suspended', 'deleted');
$columns = ['id', 'username', 'fullname', 'suspended', 'deleted'];
$this->define_columns($columns);

// Define the titles of columns to show in header.
$headers = array(get_string('id', 'tool_cleanupusers'), get_string('Neverloggedin', 'tool_cleanupusers'),
get_string('fullname'), get_string('Archived', 'tool_cleanupusers'), 'Archive');
$headers = [get_string('id', 'tool_cleanupusers'), get_string('Neverloggedin', 'tool_cleanupusers'),
get_string('fullname'), get_string('Archived', 'tool_cleanupusers'), 'Archive', ];
$this->define_headers($headers);

$idsasstring = '';
Expand Down
6 changes: 3 additions & 3 deletions classes/table/users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function __construct($uniqueid, $users, $sqlwhere, $param) {
parent::__construct($uniqueid);

// Define the list of columns to show.
$columns = array('id', 'username', 'fullname', 'lastaccess');
$columns = ['id', 'username', 'fullname', 'lastaccess'];
$this->define_columns($columns);

// Define the titles of columns to show in header.
$headers = array(get_string('id', 'tool_cleanupusers' ), get_string('Neverloggedin', 'tool_cleanupusers'),
get_string('fullname'), get_string('lastaccess', 'tool_cleanupusers'));
$headers = [get_string('id', 'tool_cleanupusers' ), get_string('Neverloggedin', 'tool_cleanupusers'),
get_string('fullname'), get_string('lastaccess', 'tool_cleanupusers'), ];
$this->define_headers($headers);

$idsasstring = '';
Expand Down
6 changes: 3 additions & 3 deletions classes/task/archive_user_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ public function execute() {
*/
private function change_user_deprovisionstatus($userarray, $intention) {
// Checks whether the intention is valid.
if (!in_array($intention, array('suspend', 'reactivate', 'delete'))) {
if (!in_array($intention, ['suspend', 'reactivate', 'delete'])) {
throw new \coding_exception('Invalid parameters in tool_cleanupusers.');
}

// Number of successfully changed users.
$countersuccess = 0;

// Array of users who could not be changed.
$failures = array();
$failures = [];

// Alternatively one could have wrote different function for each intention.
// However this would have produced duplicated code.
Expand Down Expand Up @@ -164,7 +164,7 @@ private function change_user_deprovisionstatus($userarray, $intention) {
}
}
}
$result = array();
$result = [];
$result['countersuccess'] = $countersuccess;
$result['failures'] = $failures;
return $result;
Expand Down
2 changes: 1 addition & 1 deletion db/subplugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@

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

$subplugins = array('userstatus' => 'admin/tool/cleanupusers/userstatus');
$subplugins = ['userstatus' => 'admin/tool/cleanupusers/userstatus'];
8 changes: 4 additions & 4 deletions db/tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

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

$tasks = array(
array(
$tasks = [
[
'classname' => 'tool_cleanupusers\task\archive_user_task',
'blocking' => 0,
'minute' => 'R',
Expand All @@ -33,5 +33,5 @@
'month' => '*',
'dayofweek' => '*',
'faildelay' => 0,
)
);
],
];
2 changes: 1 addition & 1 deletion handleuser.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
$PAGE->set_url('/admin/tool/cleanupusers/handleuser.php');
$PAGE->set_context(context_system::instance());

$user = $DB->get_record('user', array('id' => $userid));
$user = $DB->get_record('user', ['id' => $userid]);
require_capability('moodle/user:update', $PAGE->context);

$url = new moodle_url('/admin/tool/cleanupusers/index.php');
Expand Down
50 changes: 25 additions & 25 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,53 +45,53 @@ class tool_cleanupusers_renderer extends plugin_renderer_base {
public function render_index_page($userstoreactivate, $userstosuspend, $usertodelete, $usersneverloggedin) {
global $DB;

$cleanupusers = $DB->get_records('tool_cleanupusers', array('archived' => 1));
$cleanupusers = $DB->get_records('tool_cleanupusers', ['archived' => 1]);

// Checks if one of the given arrays is empty to prevent rendering empty arrays.
// If not empty renders the information needed.

if (empty($userstoreactivate)) {
$rendertoreactivate = array();
$rendertoreactivate = [];
} else {
$rendertoreactivate = $this->information_user_reactivate($userstoreactivate, $cleanupusers);
}
if (empty($usertodelete)) {
$rendertodelete = array();
$rendertodelete = [];
} else {
$rendertodelete = $this->information_user_delete($usertodelete, $cleanupusers);
}
if (empty($usersneverloggedin)) {
$renderneverloggedin = array();
$renderneverloggedin = [];
} else {
$renderneverloggedin = $this->information_user_notloggedin($usersneverloggedin, $cleanupusers);
}
if (empty($userstosuspend)) {
$rendertosuspend = array();
$rendertosuspend = [];
} else {
$rendertosuspend = $this->information_user_suspend($userstosuspend, $cleanupusers);
}

// Renders the information for each array in a separate html table.
$output = '';
if (!empty($rendertoreactivate)) {
$output .= $this->render_table_of_users($rendertoreactivate, array(get_string('willbereactivated', 'tool_cleanupusers'),
$output .= $this->render_table_of_users($rendertoreactivate, [get_string('willbereactivated', 'tool_cleanupusers'),
get_string('lastaccess', 'tool_cleanupusers'), get_string('Archived', 'tool_cleanupusers'),
get_string('Willbe', 'tool_cleanupusers')));
get_string('Willbe', 'tool_cleanupusers'), ]);
}
if (!empty($renderneverloggedin)) {
$output .= $this->render_table_of_users($renderneverloggedin, array(get_string('Neverloggedin', 'tool_cleanupusers'),
$output .= $this->render_table_of_users($renderneverloggedin, [get_string('Neverloggedin', 'tool_cleanupusers'),
get_string('lastaccess', 'tool_cleanupusers'), get_string('Archived', 'tool_cleanupusers'),
get_string('Willbe', 'tool_cleanupusers')));
get_string('Willbe', 'tool_cleanupusers'), ]);
}
if (!empty($rendertosuspend)) {
$output .= $this->render_table_of_users($rendertosuspend, array(get_string('willbesuspended', 'tool_cleanupusers'),
$output .= $this->render_table_of_users($rendertosuspend, [get_string('willbesuspended', 'tool_cleanupusers'),
get_string('lastaccess', 'tool_cleanupusers'),
get_string('Archived', 'tool_cleanupusers'), get_string('Willbe', 'tool_cleanupusers')));
get_string('Archived', 'tool_cleanupusers'), get_string('Willbe', 'tool_cleanupusers'), ]);
}
if (!empty($rendertodelete)) {
$output .= $this->render_table_of_users($rendertodelete, array(get_string('willbedeleted', 'tool_cleanupusers'),
$output .= $this->render_table_of_users($rendertodelete, [get_string('willbedeleted', 'tool_cleanupusers'),
get_string('lastaccess', 'tool_cleanupusers'),
get_string('Archived', 'tool_cleanupusers'), get_string('Willbe', 'tool_cleanupusers')));
get_string('Archived', 'tool_cleanupusers'), get_string('Willbe', 'tool_cleanupusers'), ]);
}

return $output;
Expand All @@ -114,10 +114,10 @@ public function render_archive_page($userstosuspend) {
}
$idsasstring = rtrim( $idsasstring , ',');
$table = new table_sql('tool_deprovisionuser_usertosuspend');
$table->define_columns(array('username', 'lastaccess', 'suspended'));
$table->define_columns(['username', 'lastaccess', 'suspended']);
$table->define_baseurl($CFG->wwwroot .'/'. $CFG->admin .'/tool/cleanupusers/toarchive.php');
$table->define_headers(array(get_string('aresuspended', 'tool_cleanupusers'),
get_string('lastaccess', 'tool_cleanupusers'), get_string('Archived', 'tool_cleanupusers')));
$table->define_headers([get_string('aresuspended', 'tool_cleanupusers'),
get_string('lastaccess', 'tool_cleanupusers'), get_string('Archived', 'tool_cleanupusers'), ]);
// TODO Customize the archived status.
$table->set_sql('username, lastaccess, suspended', $DB->get_prefix() . 'tool_cleanupusers_archive',
'id in (' . $idsasstring . ')');
Expand Down Expand Up @@ -169,9 +169,9 @@ public function get_heading() {
* @return array
*/
private function information_user_delete($users, $cleanupusers) {
$resultarray = array();
$resultarray = [];
foreach ($users as $key => $user) {
$userinformation = array();
$userinformation = [];

if (!empty($user)) {
$userinformation['username'] = $user->username;
Expand Down Expand Up @@ -201,9 +201,9 @@ private function information_user_delete($users, $cleanupusers) {
* @return array
*/
private function information_user_reactivate($users, $cleanupusers) {
$resultarray = array();
$resultarray = [];
foreach ($users as $key => $user) {
$userinformation = array();
$userinformation = [];

if (!empty($user)) {
$userinformation['username'] = $user->username;
Expand Down Expand Up @@ -232,9 +232,9 @@ private function information_user_reactivate($users, $cleanupusers) {
* @return array
*/
private function information_user_suspend($users, $cleanupusers) {
$result = array();
$result = [];
foreach ($users as $key => $user) {
$userinformation = array();
$userinformation = [];
if (!empty($user)) {
$userinformation['username'] = $user->username;
$userinformation['lastaccess'] = date('d.m.Y h:i:s', $user->lastaccess);
Expand Down Expand Up @@ -266,9 +266,9 @@ private function information_user_suspend($users, $cleanupusers) {
* @return array userid as key for user information
*/
private function information_user_notloggedin($users, $cleanupusers) {
$result = array();
$result = [];
foreach ($users as $key => $user) {
$userinformation = array();
$userinformation = [];
if (!empty($user)) {
$userinformation['username'] = $user->username;
$userinformation['lastaccess'] = get_string('neverlogged', 'tool_cleanupusers');
Expand Down Expand Up @@ -299,7 +299,7 @@ private function render_table_of_users($users, $tableheadings) {
$table = new html_table();
$table->head = $tableheadings;
$table->attributes['class'] = 'generaltable admintable cleanupusers';
$table->data = array();
$table->data = [];
foreach ($users as $key => $user) {
$table->data[$key] = $user;
}
Expand Down
Loading

0 comments on commit 29248f1

Please sign in to comment.