Skip to content

Commit

Permalink
codechecker fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
my-curiosity committed Aug 21, 2024
1 parent 4e86874 commit 1ae70b0
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 79 deletions.
15 changes: 8 additions & 7 deletions classes/archiveduser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Class archive user.
*
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions classes/cleanupusers_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Create an Exception Class for the tool_cleanupusers
*
Expand Down
1 change: 1 addition & 0 deletions classes/cleanupusers_reactivate_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Create an Exception Class for the tool_cleanupusers for failing to reactivate users.
*
Expand Down
1 change: 1 addition & 0 deletions classes/cleanupusers_subplugin_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Create an additional Exception Class for the cleanupusers_subplugins.
*
Expand Down
3 changes: 2 additions & 1 deletion classes/subplugin_select_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Create an Form Class for the tool_cleanupusers
* Create a Form Class for the tool_cleanupusers
*
* @package tool_cleanupusers
* @copyright 2017 N. Herrmann
Expand Down
1 change: 1 addition & 0 deletions classes/table/never_logged_in_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Create a custom sql_table for the tool_cleanupusers
*
Expand Down
1 change: 1 addition & 0 deletions classes/table/users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Create a custom sql_table for the tool_cleanupusers
*
Expand Down
4 changes: 2 additions & 2 deletions classes/userstatusinterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace tool_cleanupusers;

/**
* Interface for the sub-plugin userstatus.
*
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions db/subplugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* This file defines the sub-plugins for the cleanupusers admin tool.
*
Expand Down
1 change: 1 addition & 0 deletions db/tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Tasks definition.
*
Expand Down
1 change: 1 addition & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Upgrade for the tool_cleanupusers.
*
Expand Down
1 change: 1 addition & 0 deletions handleuser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Suspend, delete or reactivate user. This is called when sideadmin changes user from the cleanupusers
*
Expand Down
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
83 changes: 42 additions & 41 deletions lang/en/tool_cleanupusers.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* This file contains language strings used in the cleanupusers admin tool.
*
Expand All @@ -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 <b>{$a}</b> 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 <b>{$a}</b> 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:';
1 change: 1 addition & 0 deletions neverloggedin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 0 additions & 1 deletion renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 3 additions & 2 deletions tests/generator_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* PHPUnit data generator tests
*
Expand All @@ -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);
}
}
28 changes: 14 additions & 14 deletions tests/tool_cleanupusers_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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');
Expand All @@ -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', []));
Expand Down
Loading

0 comments on commit 1ae70b0

Please sign in to comment.