From 1ae70b0267ebde40ce560ee009b64bdafdcea955 Mon Sep 17 00:00:00 2001 From: curiosity Date: Wed, 21 Aug 2024 14:29:17 +0200 Subject: [PATCH] codechecker fixes --- classes/archiveduser.php | 15 ++-- classes/cleanupusers_exception.php | 1 + classes/cleanupusers_reactivate_exception.php | 1 + classes/cleanupusers_subplugin_exception.php | 1 + classes/subplugin_select_form.php | 3 +- classes/table/never_logged_in_table.php | 1 + classes/table/users_table.php | 1 + classes/userstatusinterface.php | 4 +- db/subplugins.php | 1 + db/tasks.php | 1 + db/upgrade.php | 1 + handleuser.php | 1 + index.php | 1 + lang/en/tool_cleanupusers.php | 83 ++++++++++--------- neverloggedin.php | 1 + renderer.php | 1 - tests/generator_test.php | 5 +- tests/tool_cleanupusers_test.php | 28 +++---- toarchive.php | 1 + .../timechecker/classes/timechecker.php | 10 ++- .../lang/en/userstatus_timechecker.php | 9 +- .../tests/userstatus_timechecker_test.php | 8 +- 22 files changed, 99 insertions(+), 79 deletions(-) diff --git a/classes/archiveduser.php b/classes/archiveduser.php index e85bdc3..e42fa24 100644 --- a/classes/archiveduser.php +++ b/classes/archiveduser.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Class archive user. * @@ -100,14 +101,14 @@ public function archive_me() { // Document time of editing user in Database. // In case there is no entry in the tool table make a new one. $timestamp = time(); - if (!$DB->record_exists('tool_cleanupusers', ['id' => $user->id])) { - $DB->insert_record_raw('tool_cleanupusers', ['id' => $user->id, 'archived' => 1, - 'timestamp' => $timestamp], true, false, true); - } + if (!$DB->record_exists('tool_cleanupusers', ['id' => $user->id])) { + $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. - if ($DB->record_exists('tool_cleanupusers_archive', ['id' => $shadowuser->id])) { - $DB->delete_records('tool_cleanupusers_archive', ['id' => $shadowuser->id]); - } + if ($DB->record_exists('tool_cleanupusers_archive', ['id' => $shadowuser->id])) { + $DB->delete_records('tool_cleanupusers_archive', ['id' => $shadowuser->id]); + } $DB->insert_record_raw('tool_cleanupusers_archive', $shadowuser, true, false, true); // Replaces the current user with a pseudo_user that has no reference. $cloneuser = $this->give_suspended_pseudo_user($shadowuser->id, $timestamp); diff --git a/classes/cleanupusers_exception.php b/classes/cleanupusers_exception.php index 5aa168b..22a4c36 100644 --- a/classes/cleanupusers_exception.php +++ b/classes/cleanupusers_exception.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Create an Exception Class for the tool_cleanupusers * diff --git a/classes/cleanupusers_reactivate_exception.php b/classes/cleanupusers_reactivate_exception.php index 2db92d9..06c1420 100644 --- a/classes/cleanupusers_reactivate_exception.php +++ b/classes/cleanupusers_reactivate_exception.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Create an Exception Class for the tool_cleanupusers for failing to reactivate users. * diff --git a/classes/cleanupusers_subplugin_exception.php b/classes/cleanupusers_subplugin_exception.php index 35a102a..560775d 100644 --- a/classes/cleanupusers_subplugin_exception.php +++ b/classes/cleanupusers_subplugin_exception.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Create an additional Exception Class for the cleanupusers_subplugins. * diff --git a/classes/subplugin_select_form.php b/classes/subplugin_select_form.php index c3e0121..2c066bc 100644 --- a/classes/subplugin_select_form.php +++ b/classes/subplugin_select_form.php @@ -13,8 +13,9 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** - * Create an Form Class for the tool_cleanupusers + * Create a Form Class for the tool_cleanupusers * * @package tool_cleanupusers * @copyright 2017 N. Herrmann diff --git a/classes/table/never_logged_in_table.php b/classes/table/never_logged_in_table.php index 5fc2d91..4f202a7 100644 --- a/classes/table/never_logged_in_table.php +++ b/classes/table/never_logged_in_table.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Create a custom sql_table for the tool_cleanupusers * diff --git a/classes/table/users_table.php b/classes/table/users_table.php index 8762f49..3ba2df8 100644 --- a/classes/table/users_table.php +++ b/classes/table/users_table.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Create a custom sql_table for the tool_cleanupusers * diff --git a/classes/userstatusinterface.php b/classes/userstatusinterface.php index c8badbc..684f554 100644 --- a/classes/userstatusinterface.php +++ b/classes/userstatusinterface.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace tool_cleanupusers; + /** * Interface for the sub-plugin userstatus. * @@ -34,8 +36,6 @@ * @copyright 2016/17 N. Herrmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -namespace tool_cleanupusers; - interface userstatusinterface { /** * Function which returns an array of all users to be suspended by the next cron-job. diff --git a/db/subplugins.php b/db/subplugins.php index a1a2fad..e55e116 100644 --- a/db/subplugins.php +++ b/db/subplugins.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * This file defines the sub-plugins for the cleanupusers admin tool. * diff --git a/db/tasks.php b/db/tasks.php index 790955a..ff12ad3 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Tasks definition. * diff --git a/db/upgrade.php b/db/upgrade.php index b0c47c6..ecf9978 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Upgrade for the tool_cleanupusers. * diff --git a/handleuser.php b/handleuser.php index 39c2816..5d55566 100644 --- a/handleuser.php +++ b/handleuser.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Suspend, delete or reactivate user. This is called when sideadmin changes user from the cleanupusers * diff --git a/index.php b/index.php index c5e0469..0d5fff3 100644 --- a/index.php +++ b/index.php @@ -21,6 +21,7 @@ * @copyright 2016 N Herrmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + require_once(__DIR__ . '/../../../config.php'); require_once($CFG->libdir . '/adminlib.php'); diff --git a/lang/en/tool_cleanupusers.php b/lang/en/tool_cleanupusers.php index 503504a..1c3c9e4 100644 --- a/lang/en/tool_cleanupusers.php +++ b/lang/en/tool_cleanupusers.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * This file contains language strings used in the cleanupusers admin tool. * @@ -21,55 +22,55 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['pluginname'] = 'Clean up users'; -$string['pluginsettingstitle'] = 'General settings'; -$string['subplugintype_userstatus'] = 'Returns the status of users'; -$string['subplugintype_userstatus_plural'] = 'Returns the status of users'; -$string['neverloggedin'] = 'Manage users who never logged in'; -$string['toarchive'] = 'Manage users who will be archived'; -$string['todelete'] = 'Manage users who will be deleted'; -$string['lastaccess'] = 'Last access:'; -$string['usersarchived'] = 'The Users have been archived'; -$string['Yes'] = 'Yes'; -$string['id'] = 'ID'; -$string['No'] = 'No'; $string['Archived'] = 'Archived:'; -$string['Willbe'] = 'Will be:'; $string['Neverloggedin'] = 'Users that never logged in:'; -$string['willbereactivated'] = 'Users that will be reactivated:'; -$string['willbesuspended'] = 'Users that will be suspended:'; -$string['willbedeleted'] = 'Users that will be deleted:'; -$string['usersdeleted'] = 'The user has been deleted.'; -$string['usersreactivated'] = 'The user has been reactivated.'; -$string['showuser'] = 'Activate User'; -$string['hideuser'] = 'Suspend User'; -$string['deleteuser'] = 'Delete User'; -$string['aresuspended'] = 'Users currently suspended:'; +$string['No'] = 'No'; +$string['Willbe'] = 'Will be:'; +$string['Yes'] = 'Yes'; $string['archive_user_task'] = 'Archive Users'; -$string['willbe_archived'] = 'will be archived in the next cron-job'; -$string['shouldbedelted'] = 'will be deleted in the next cron-job'; -$string['neverlogged'] = 'Never logged in'; -$string['nothinghappens'] = 'Not handled since the user never logged in'; -$string['waittodelete'] = 'The user is suspended and will not be deleted in the next cron-job.'; +$string['aresuspended'] = 'Users currently suspended:'; +$string['cronjobcomplete'] = 'tool_cleanupusers cron job complete'; +$string['cronjobwasrunning'] = 'The tool_cleanupusers cron job was running. No user was suspended or deleted.'; +$string['deleteuser'] = 'Delete User'; +$string['e-mail-activated'] = 'In the last cron-job {$a} users were reactivated.'; $string['e-mail-archived'] = 'In the last cron-job {$a} users were archived.'; $string['e-mail-deleted'] = 'In the last cron-job {$a} users were deleted.'; -$string['e-mail-activated'] = 'In the last cron-job {$a} users were reactivated.'; +$string['e-mail-noproblem'] = 'No problems occurred in plugin tool_cleanupusers in the last run.'; +$string['e-mail-problematic_delete'] = 'In the last cron-job {$a} users caused exception and could not be deleted.'; +$string['e-mail-problematic_reactivate'] = 'In the last cron-job {$a} users caused exception and could not be reactivated.'; +$string['e-mail-problematic_suspend'] = 'In the last cron-job {$a} users caused exception and could not be suspended.'; +$string['errormessagenoaction'] = 'The requested action could not be executed.'; $string['errormessagenotactive'] = 'Not able to activate user'; $string['errormessagenotdelete'] = 'Not able to delete user'; $string['errormessagenotsuspend'] = 'Not able to suspend user'; -$string['errormessagenoaction'] = 'The requested action could not be executed.'; $string['errormessagesubplugin'] = 'The sub-plugin you selected is not available. The default will be used.'; -$string['e-mail-problematic_delete'] = 'In the last cron-job {$a} users caused exception and could not be deleted.'; -$string['e-mail-problematic_suspend'] = 'In the last cron-job {$a} users caused exception and could not be suspended.'; -$string['e-mail-problematic_reactivate'] = 'In the last cron-job {$a} users caused exception and could not be reactivated.'; -$string['e-mail-noproblem'] = 'No problems occurred in plugin tool_cleanupusers in the last run.'; -$string['cronjobcomplete'] = 'tool_cleanupusers cron job complete'; -$string['cronjobwasrunning'] = 'The tool_cleanupusers cron job was running. No user was suspended or deleted.'; -$string['using-plugin'] = 'You are currently using the {$a} Plugin'; -$string['suspendusername'] = 'anonym'; -$string['suspendfirstname'] = 'Anonym'; -$string['sett_title'] = 'Configure suspended users'; -$string['sett_suspendusername'] = 'Username for suspended'; +$string['hideuser'] = 'Suspend User'; +$string['id'] = 'ID'; +$string['lastaccess'] = 'Last access:'; +$string['neverlogged'] = 'Never logged in'; +$string['neverloggedin'] = 'Manage users who never logged in'; +$string['nothinghappens'] = 'Not handled since the user never logged in'; +$string['pluginname'] = 'Clean up users'; +$string['pluginsettingstitle'] = 'General settings'; $string['sett_suspendfirstname'] = 'Firstname for suspended'; -$string['sett_suspendusername_description'] = 'Choose a username for suspended users (must be lowercase)'; $string['sett_suspendfirstname_description'] = 'Choose a firstname for suspended users'; +$string['sett_suspendusername'] = 'Username for suspended'; +$string['sett_suspendusername_description'] = 'Choose a username for suspended users (must be lowercase)'; +$string['sett_title'] = 'Configure suspended users'; +$string['shouldbedelted'] = 'will be deleted in the next cron-job'; +$string['showuser'] = 'Activate User'; +$string['subplugintype_userstatus'] = 'Returns the status of users'; +$string['subplugintype_userstatus_plural'] = 'Returns the status of users'; +$string['suspendfirstname'] = 'Anonym'; +$string['suspendusername'] = 'anonym'; +$string['toarchive'] = 'Manage users who will be archived'; +$string['todelete'] = 'Manage users who will be deleted'; +$string['usersarchived'] = 'The Users have been archived'; +$string['usersdeleted'] = 'The user has been deleted.'; +$string['usersreactivated'] = 'The user has been reactivated.'; +$string['using-plugin'] = 'You are currently using the {$a} Plugin'; +$string['waittodelete'] = 'The user is suspended and will not be deleted in the next cron-job.'; +$string['willbe_archived'] = 'will be archived in the next cron-job'; +$string['willbedeleted'] = 'Users that will be deleted:'; +$string['willbereactivated'] = 'Users that will be reactivated:'; +$string['willbesuspended'] = 'Users that will be suspended:'; diff --git a/neverloggedin.php b/neverloggedin.php index 13fbf9b..92ee0a7 100644 --- a/neverloggedin.php +++ b/neverloggedin.php @@ -21,6 +21,7 @@ * @copyright 2018 N Herrmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + require_once(__DIR__ . '/../../../config.php'); require_once($CFG->libdir . '/adminlib.php'); require_once($CFG->libdir . '/tablelib.php'); diff --git a/renderer.php b/renderer.php index e8e96b8..39ad5a5 100644 --- a/renderer.php +++ b/renderer.php @@ -117,7 +117,6 @@ public function render_archive_page($userstosuspend) { $table->define_baseurl($CFG->wwwroot . '/' . $CFG->admin . '/tool/cleanupusers/toarchive.php'); $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', diff --git a/tests/generator_test.php b/tests/generator_test.php index 40678a9..3c7d124 100644 --- a/tests/generator_test.php +++ b/tests/generator_test.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * PHPUnit data generator tests * @@ -32,13 +33,13 @@ * @copyright 2016/17 Nina Herrmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class generator_test extends advanced_testcase { +final class generator_test extends advanced_testcase { /** * In the future might relly test the generator... * @return void * @covers \tool_cleanupusers_generator::test_create_preparation */ - public function test_generator() { + public function test_generator(): void { $this->resetAfterTest(true); } } diff --git a/tests/tool_cleanupusers_test.php b/tests/tool_cleanupusers_test.php index 0cfb6bc..497903c 100644 --- a/tests/tool_cleanupusers_test.php +++ b/tests/tool_cleanupusers_test.php @@ -41,9 +41,9 @@ * @covers \tool_cleanupusers\task\archive_user_task::execute() * */ -class tool_cleanupusers_test extends advanced_testcase { - /** Get data from generator. - * @return mixed +final class tool_cleanupusers_test extends advanced_testcase { + /** + * Get data from generator. */ protected function set_up() { // Recommended in Moodle docs to always include CFG. @@ -61,7 +61,7 @@ protected function set_up() { * user | tendaysago | no | no | no * @see archiveduser */ - public function test_archiveduser_archiveme() { + public function test_archiveduser_archiveme(): void { global $DB; $data = $this->set_up(); $this->assertNotEmpty($data); @@ -102,7 +102,7 @@ public function test_archiveduser_archiveme() { * usersuspendedbyplugin | oneyearago | no | yes | no * @see archiveduser */ - public function test_archiveduser_deleteme() { + public function test_archiveduser_deleteme(): void { global $DB; $data = $this->set_up(); $this->assertNotEmpty($data); @@ -151,7 +151,7 @@ public function test_archiveduser_deleteme() { * usersuspendedbyplugin | oneyearago | no | yes | no * @see archiveduser */ - public function test_archiveduser_activateme() { + public function test_archiveduser_activateme(): void { global $DB; $data = $this->set_up(); $this->assertNotEmpty($data); @@ -209,7 +209,7 @@ public function test_archiveduser_activateme() { * @throws cleanupusers_exception * @throws dml_exception */ - public function test_exception_archiveme() { + public function test_exception_archiveme(): void { global $DB; $data = $this->set_up(); $this->assertNotEmpty($data); @@ -241,7 +241,7 @@ public function test_exception_archiveme() { * @throws cleanupusers_exception * @throws dml_exception */ - public function test_exception_deleteme() { + public function test_exception_deleteme(): void { global $DB; $data = $this->set_up(); $this->assertNotEmpty($data); @@ -313,7 +313,7 @@ public function test_exception_deleteme() { * @throws cleanupusers_exception * @throws dml_exception */ - public function test_exception_activateme() { + public function test_exception_activateme(): void { global $DB; $data = $this->set_up(); $this->assertNotEmpty($data); @@ -385,7 +385,7 @@ public function test_exception_activateme() { * * @see subplugin_select_form */ - public function test_subpluginform() { + public function test_subpluginform(): void { $data = $this->set_up(); $this->assertNotEmpty($data); @@ -420,7 +420,7 @@ public function test_subpluginform() { * @throws dml_exception * @throws coding_exception */ - public function test_cronjob() { + public function test_cronjob(): void { global $DB; $data = $this->set_up(); $this->assertNotEmpty($data); @@ -551,7 +551,7 @@ private function assert_user_equals($expected, $actual) { * * @see event\deprovisionusercronjob_completed */ - public function test_logging() { + public function test_logging(): void { $data = $this->set_up(); $this->assertNotEmpty($data); $timestamp = time(); @@ -582,7 +582,7 @@ public function test_logging() { /** * Methods recommended by moodle to assure database and dataroot is reset. */ - public function test_deleting() { + public function test_deleting(): void { global $DB; $this->resetAfterTest(true); $DB->delete_records('user'); @@ -594,7 +594,7 @@ public function test_deleting() { /** * Methods recommended by moodle to assure database is reset. */ - public function test_user_table_was_reset() { + public function test_user_table_was_reset(): void { global $DB; $this->assertEquals(2, $DB->count_records('user', [])); $this->assertEquals(0, $DB->count_records('tool_cleanupusers', [])); diff --git a/toarchive.php b/toarchive.php index 6b9b76d..73d9f67 100644 --- a/toarchive.php +++ b/toarchive.php @@ -21,6 +21,7 @@ * @copyright 2018 N Herrmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + require_once(__DIR__ . '/../../../config.php'); require_once($CFG->libdir . '/adminlib.php'); require_once($CFG->dirroot . '/user/filters/lib.php'); diff --git a/userstatus/timechecker/classes/timechecker.php b/userstatus/timechecker/classes/timechecker.php index 0f9c929..d25a606 100644 --- a/userstatus/timechecker/classes/timechecker.php +++ b/userstatus/timechecker/classes/timechecker.php @@ -109,8 +109,13 @@ public function get_never_logged_in() { ); $neverloggedin = []; foreach ($users as $key => $user) { - $informationuser = new archiveduser($user->id, $user->suspended, - $user->lastaccess, $user->username, $user->deleted); + $informationuser = new archiveduser( + $user->id, + $user->suspended, + $user->lastaccess, + $user->username, + $user->deleted + ); $neverloggedin[$key] = $informationuser; } return $neverloggedin; @@ -203,5 +208,4 @@ public function get_to_reactivate() { return $toactivate; } - } diff --git a/userstatus/timechecker/lang/en/userstatus_timechecker.php b/userstatus/timechecker/lang/en/userstatus_timechecker.php index 28bb6f5..9ab9f25 100644 --- a/userstatus/timechecker/lang/en/userstatus_timechecker.php +++ b/userstatus/timechecker/lang/en/userstatus_timechecker.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * This file contains language strings used in the timechecker sub-plugin. * @@ -21,11 +22,11 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['pluginname'] = 'Timechecker'; -$string['settingsinformation'] = 'Subplugin information'; +$string['deletetime'] = 'Time until deletion'; $string['introsettingstext'] = 'In these settings, the time until suspension and the time until deletion can be defined.
The plugin does apply this to users who were changed by the plugin and users who are manually suspended or deleted.'; +$string['pluginname'] = 'Timechecker'; +$string['settingsinformation'] = 'Subplugin information'; +$string['suspendtime'] = 'Time until suspension'; $string['timechecker_time_to_archive'] = 'Number of days without log in until a user is suspended.'; $string['timechecker_time_to_delete'] = 'Number of days a user is suspended until s/he is deleted.'; -$string['suspendtime'] = 'Time until suspension'; -$string['deletetime'] = 'Time until deletion'; diff --git a/userstatus/timechecker/tests/userstatus_timechecker_test.php b/userstatus/timechecker/tests/userstatus_timechecker_test.php index 875b2dc..f39b784 100644 --- a/userstatus/timechecker/tests/userstatus_timechecker_test.php +++ b/userstatus/timechecker/tests/userstatus_timechecker_test.php @@ -40,7 +40,7 @@ * @covers \userstatus_timechecker\timechecker::get_to_reactivate() * */ -class userstatus_timechecker_test extends advanced_testcase { +final class userstatus_timechecker_test extends advanced_testcase { /** * Create the data from the generator. * @return mixed @@ -58,7 +58,7 @@ protected function set_up() { * * @see timechecker */ - public function test_locallib() { + public function test_locallib(): void { $data = $this->set_up(); $checker = new timechecker(); @@ -108,7 +108,7 @@ public function test_locallib() { /** * Methodes recommended by moodle to assure database and dataroot is reset. */ - public function test_deleting() { + public function test_deleting(): void { global $DB; $this->resetAfterTest(true); $DB->delete_records('user'); @@ -119,7 +119,7 @@ public function test_deleting() { /** * Methodes recommended by moodle to assure database is reset. */ - public function test_user_table_was_reset() { + public function test_user_table_was_reset(): void { global $DB; $this->assertEquals(2, $DB->count_records('user', [])); $this->assertEquals(0, $DB->count_records('tool_cleanupusers', []));