From b61b61fd450543520dbca282e11c348e853dd12f Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Mon, 3 Jun 2024 16:00:31 -0700 Subject: [PATCH 1/4] adds Github Actions support. --- .github/workflows/ci.yml | 109 +++++++++++++++++++++++++++++++++++++++ .phpcs.xml | 4 ++ 2 files changed, 113 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .phpcs.xml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0768493 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,109 @@ +name: Moodle Plugin CI + +on: + push: + pull_request: + schedule: + - cron: '33 2 * * 1' # weekly, on Monday morning + +jobs: + test: + runs-on: ubuntu-latest + + services: + mariadb: + image: mariadb:10 + env: + MYSQL_USER: 'root' + MYSQL_ALLOW_EMPTY_PASSWORD: "true" + MYSQL_CHARACTER_SET_SERVER: "utf8mb4" + MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci" + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3 + + strategy: + fail-fast: false + matrix: + include: + - php: '8.2' + moodle-branch: 'main' + database: 'mariadb' + - php: '8.2' + moodle-branch: 'MOODLE_403_STABLE' + database: 'mariadb' + steps: + - name: Check out repository code + uses: actions/checkout@v3 + with: + path: plugin + + - name: Setup PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: ${{ matrix.extensions }} + ini-values: max_input_vars=5000 + # If you are not using code coverage, keep "none". Otherwise, use "pcov" (Moodle 3.10 and up) or "xdebug". + # If you try to use code coverage with "none", it will fallback to phpdbg (which has known problems). + coverage: none + + - name: Initialise moodle-plugin-ci + run: | + composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4 + echo $(cd ci/bin; pwd) >> $GITHUB_PATH + echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH + sudo locale-gen en_AU.UTF-8 + echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV + + - name: Install moodle-plugin-ci + run: | + moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 + env: + DB: ${{ matrix.database }} + MOODLE_BRANCH: ${{ matrix.moodle-branch }} + + - name: PHP Lint + if: ${{ !cancelled() }} + run: moodle-plugin-ci phplint + + - name: PHP Mess Detector + continue-on-error: true # This step will show errors but will not fail + if: ${{ !cancelled() }} + run: moodle-plugin-ci phpmd + + - name: Moodle Code Checker + if: ${{ !cancelled() }} + run: moodle-plugin-ci phpcs --max-warnings 0 + + - name: Moodle PHPDoc Checker + if: ${{ !cancelled() }} + run: moodle-plugin-ci phpdoc --max-warnings 0 + + - name: Validating + if: ${{ !cancelled() }} + run: moodle-plugin-ci validate + + - name: Check upgrade savepoints + if: ${{ !cancelled() }} + run: moodle-plugin-ci savepoints + + - name: Mustache Lint + if: ${{ !cancelled() }} + run: moodle-plugin-ci mustache + + - name: Grunt + if: ${{ !cancelled() }} + run: moodle-plugin-ci grunt --max-lint-warnings 0 + + - name: PHPUnit tests + if: ${{ !cancelled() }} + run: moodle-plugin-ci phpunit --fail-on-warning + + - name: Behat features + if: ${{ !cancelled() }} + run: moodle-plugin-ci behat --profile chrome + + - name: Mark cancelled jobs as failed. + if: ${{ cancelled() }} + run: exit 1 \ No newline at end of file diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 0000000..a730760 --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,4 @@ + + + + From 1efafa09f86ebfd2d665fd75258c9fa552364bf0 Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Mon, 3 Jun 2024 16:19:00 -0700 Subject: [PATCH 2/4] auto-correct PHP code linter errors. --- classes/form/create_sync_job.php | 18 ++-- classes/manager.php | 48 +++++------ classes/output/renderer.php | 56 ++++++------- classes/sync_job.php | 34 ++++---- classes/task/sync_task.php | 137 +++++++++++++++---------------- create.php | 14 ++-- db/events.php | 8 +- db/tasks.php | 10 +-- db/uninstall.php | 2 +- db/upgrade.php | 5 +- index.php | 42 +++++----- version.php | 4 +- 12 files changed, 190 insertions(+), 188 deletions(-) diff --git a/classes/form/create_sync_job.php b/classes/form/create_sync_job.php index bfbe269..4b0e35f 100644 --- a/classes/form/create_sync_job.php +++ b/classes/form/create_sync_job.php @@ -53,17 +53,17 @@ public function definition() { return; } - $role_options = array(); + $roleoptions = []; foreach ($roles as $role) { - $role_options[$role->id] = $role->localname; + $roleoptions[$role->id] = $role->localname; } try { - $ilios_client = manager::instantiate_ilios_client(); - $access_token = manager::get_config('apikey', ''); - $ilios_schools = $ilios_client->get($access_token, 'schools'); - if (!empty($ilios_schools)) { - $ilios_schools = array_column($ilios_schools, 'title', 'id'); + $iliosclient = manager::instantiate_ilios_client(); + $accesstoken = manager::get_config('apikey', ''); + $iliosschools = $iliosclient->get($accesstoken, 'schools'); + if (!empty($iliosschools)) { + $iliosschools = array_column($iliosschools, 'title', 'id'); } } catch (\Exception $e) { $warning = $renderer->notify_error(get_string('ilioserror', 'tool_ilioscategoryassignment')); @@ -79,11 +79,11 @@ public function definition() { $mform->addElement('select', 'categoryid', get_string('selectcategory', 'tool_ilioscategoryassignment'), $categories); $mform->addRule('categoryid', null, 'required', null, 'client'); - $mform->addElement('select', 'roleid', get_string('selectrole', 'tool_ilioscategoryassignment'), $role_options); + $mform->addElement('select', 'roleid', get_string('selectrole', 'tool_ilioscategoryassignment'), $roleoptions); $mform->addRule('roleid', null, 'required', null, 'client'); $mform->addElement('select', 'iliosschoolid', get_string('selectiliosschool', 'tool_ilioscategoryassignment'), - $ilios_schools); + $iliosschools); $mform->addRule('iliosschoolid', null, 'required', null, 'client'); $this->add_action_buttons(false, get_string('submit')); diff --git a/classes/manager.php b/classes/manager.php index 2f4c45d..d6e7a25 100644 --- a/classes/manager.php +++ b/classes/manager.php @@ -36,7 +36,7 @@ class manager { * @throws \moodle_exception */ public static function instantiate_ilios_client(): ilios_client { - return new ilios_client(manager::get_config('host_url', ''), new curl()); + return new ilios_client(self::get_config('host_url', ''), new curl()); } /** @@ -46,7 +46,7 @@ public static function instantiate_ilios_client(): ilios_client { * @throws \dml_exception */ public static function get_sync_job($id) { - $jobs = self::get_sync_jobs(array('id' => $id)); + $jobs = self::get_sync_jobs(['id' => $id]); return empty($jobs) ? null : $jobs[0]; } @@ -103,13 +103,13 @@ public static function set_config($name, $value) { * @return sync_job[] * @throws \dml_exception */ - public static function get_sync_jobs(array $filters = array()) { + public static function get_sync_jobs(array $filters = []) { global $DB; - $jobs = array(); - $job_recs = $DB->get_records('tool_ilioscatassignment', $filters); - foreach ($job_recs as $job_rec) { - $jobs[] = new sync_job($job_rec->id, $job_rec->title, $job_rec->roleid, $job_rec->coursecatid, - (boolean) $job_rec->enabled, $job_rec->schoolid); + $jobs = []; + $jobrecs = $DB->get_records('tool_ilioscatassignment', $filters); + foreach ($jobrecs as $jobrec) { + $jobs[] = new sync_job($jobrec->id, $jobrec->title, $jobrec->roleid, $jobrec->coursecatid, + (boolean) $jobrec->enabled, $jobrec->schoolid); } return $jobs; @@ -120,13 +120,13 @@ public static function get_sync_jobs(array $filters = array()) { * * @throws \dml_exception */ - public static function disable_job($job_id) { + public static function disable_job($jobid) { global $DB; - $table_name = 'tool_ilioscatassignment'; - $job = $DB->get_record($table_name, array('id' => $job_id)); + $tablename = 'tool_ilioscatassignment'; + $job = $DB->get_record($tablename, ['id' => $jobid]); if (!empty($job)) { $job->enabled = false; - $DB->update_record($table_name, $job); + $DB->update_record($tablename, $job); } } @@ -135,13 +135,13 @@ public static function disable_job($job_id) { * * @throws \dml_exception */ - public static function enable_job($job_id) { + public static function enable_job($jobid) { global $DB; - $table_name = 'tool_ilioscatassignment'; - $job = $DB->get_record($table_name, array('id' => $job_id)); + $tablename = 'tool_ilioscatassignment'; + $job = $DB->get_record($tablename, ['id' => $jobid]); if (!empty($job)) { $job->enabled = true; - $DB->update_record($table_name, $job); + $DB->update_record($tablename, $job); } } @@ -160,8 +160,8 @@ public static function create_job(sync_job $job) { $dto->enabled = $job->is_enabled(); $dto->schoolid = $job->get_school_id(); - $job_id = $DB->insert_record('tool_ilioscatassignment', $dto); - return self::get_sync_job($job_id); + $jobid = $DB->insert_record('tool_ilioscatassignment', $dto); + return self::get_sync_job($jobid); } /** @@ -171,15 +171,15 @@ public static function create_job(sync_job $job) { * @throws \dml_exception * @throws \moodle_exception */ - public static function delete_job($job_id) { + public static function delete_job($jobid) { global $DB; - $job = self::get_sync_job($job_id); + $job = self::get_sync_job($jobid); if (empty($job)) { return; } // delete the given job - $DB->delete_records('tool_ilioscatassignment', array('id' => $job_id)); + $DB->delete_records('tool_ilioscatassignment', ['id' => $jobid]); // remove any course category role assignments that were managed by the given job $category = core_course_category::get($job->get_course_category_id(), IGNORE_MISSING); @@ -187,8 +187,8 @@ public static function delete_job($job_id) { return; } $context = $category->get_context(); - role_unassign_all(array('component' => 'tool_ilioscategoryassignment', 'roleid' => $job->get_role_id(), - 'contextid' => $context->id)); + role_unassign_all(['component' => 'tool_ilioscategoryassignment', 'roleid' => $job->get_role_id(), + 'contextid' => $context->id]); } /** @@ -203,7 +203,7 @@ public static function delete_job($job_id) { */ public static function course_category_deleted(course_category_deleted $event) { $category = $event->get_coursecat(); - $jobs = self::get_sync_jobs(array('coursecatid' => $category->id)); + $jobs = self::get_sync_jobs(['coursecatid' => $category->id]); foreach ($jobs as $job) { self::delete_job($job->get_id()); } diff --git a/classes/output/renderer.php b/classes/output/renderer.php index 5d9a62a..7642e5d 100644 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -46,75 +46,75 @@ class renderer extends plugin_renderer_base { * @throws coding_exception * @throws moodle_exception */ - public function sync_jobs_table(array $sync_jobs, array $course_categories, array $roles, array $ilios_schools) { + public function sync_jobs_table(array $syncjobs, array $coursecategories, array $roles, array $iliosschools) { global $CFG; $table = new html_table(); - $table->head = array( + $table->head = [ get_string('title', 'tool_ilioscategoryassignment'), get_string('coursecategory'), get_string('role'), get_string('iliosschool', 'tool_ilioscategoryassignment'), - get_string('actions') - ); + get_string('actions'), + ]; $table->attributes['class'] = 'admintable generaltable'; - $data = array(); + $data = []; - foreach ($sync_jobs as $job) { + foreach ($syncjobs as $job) { $titlecell = new html_table_cell($job->get_title()); $titlecell->header = true; - $course_category_id = $job->get_course_category_id(); - $course_title = get_string('notfound', 'tool_ilioscategoryassignment', $course_category_id); - if (!empty($course_categories[$course_category_id])) { - $course_title = $course_categories[$course_category_id]->get_nested_name(); + $coursecategoryid = $job->get_course_category_id(); + $coursetitle = get_string('notfound', 'tool_ilioscategoryassignment', $coursecategoryid); + if (!empty($coursecategories[$coursecategoryid])) { + $coursetitle = $coursecategories[$coursecategoryid]->get_nested_name(); } - $coursecatcell = new html_table_cell($course_title); + $coursecatcell = new html_table_cell($coursetitle); - $role_id = $job->get_role_id(); - $role_title = get_string('notfound', 'tool_ilioscategoryassignment', $role_id); - if (array_key_exists($role_id, $roles)) { - $role_title = $roles[$role_id]->localname; + $roleid = $job->get_role_id(); + $roletitle = get_string('notfound', 'tool_ilioscategoryassignment', $roleid); + if (array_key_exists($roleid, $roles)) { + $roletitle = $roles[$roleid]->localname; } - $rolecell = new html_table_cell($role_title); + $rolecell = new html_table_cell($roletitle); - $ilios_school_id = $job->get_school_id(); - $ilios_school_title = get_string('notfound', 'tool_ilioscategoryassignment', $ilios_school_id); - if (array_key_exists($ilios_school_id, $ilios_schools)) { - $ilios_school_title = $ilios_schools[$ilios_school_id]; + $iliosschoolid = $job->get_school_id(); + $iliosschooltitle = get_string('notfound', 'tool_ilioscategoryassignment', $iliosschoolid); + if (array_key_exists($iliosschoolid, $iliosschools)) { + $iliosschooltitle = $iliosschools[$iliosschoolid]; } - $iliosschoolcell = new html_table_cell($ilios_school_title); + $iliosschoolcell = new html_table_cell($iliosschooltitle); - $actions = array(); + $actions = []; if ($job->is_enabled()) { $actions[] = $this->action_icon( new moodle_url("$CFG->wwwroot/$CFG->admin/tool/ilioscategoryassignment/index.php", - array('job_id' => $job->get_id(), 'action' => 'disable', 'sesskey' => sesskey())), + ['job_id' => $job->get_id(), 'action' => 'disable', 'sesskey' => sesskey()]), new pix_icon('t/hide', new lang_string('disable')) ); } else { $actions[] = $this->action_icon( new moodle_url("$CFG->wwwroot/$CFG->admin/tool/ilioscategoryassignment/index.php", - array('job_id' => $job->get_id(), 'action' => 'enable', 'sesskey' => sesskey())), + ['job_id' => $job->get_id(), 'action' => 'enable', 'sesskey' => sesskey()]), new pix_icon('t/show', new lang_string('enable')) ); } $actions[] = $this->action_icon( new moodle_url("$CFG->wwwroot/$CFG->admin/tool/ilioscategoryassignment/index.php", - array('job_id' => $job->get_id(), 'action' => 'delete', 'sesskey' => sesskey())), + ['job_id' => $job->get_id(), 'action' => 'delete', 'sesskey' => sesskey()]), new pix_icon('t/delete', new lang_string('delete')) ); $actionscell = new html_table_cell(implode(' ', $actions)); - $row = new html_table_row(array( + $row = new html_table_row([ $titlecell, $coursecatcell, $rolecell, $iliosschoolcell, - $actionscell - )); + $actionscell, + ]); $data[] = $row; } $table->data = $data; diff --git a/classes/sync_job.php b/classes/sync_job.php index 53839db..f2add34 100644 --- a/classes/sync_job.php +++ b/classes/sync_job.php @@ -11,35 +11,39 @@ class sync_job { /** @var int $id */ protected $id; + /** @var string $title */ protected $title; + /** @var int $role_id */ - protected $role_id; - /** @var int $course_category_id */ - protected $course_category_id; + protected $roleid; + + /** @var int $coursecategoryid */ + protected $coursecategoryid; + /** @var bool $enabled */ protected $enabled; - /** @var int $school_id */ - protected $school_id; + /** @var int $school_id */ + protected $schoolid; /** - * sync_job constructor. + * Constructor. * * @param $id * @param $title - * @param $role_id + * @param $roleid * @param $course_category_id * @param $enabled - * @param $school_id + * @param $schoolid */ - public function __construct($id, $title, $role_id, $course_category_id, $enabled, $school_id) { + public function __construct($id, $title, $roleid, $coursecategoryid, $enabled, $schoolid) { $this->id = $id; $this->title = $title; - $this->role_id = $role_id; - $this->course_category_id = $course_category_id; + $this->roleid = $roleid; + $this->coursecategoryid = $coursecategoryid; $this->enabled = $enabled; - $this->school_id = $school_id; + $this->schoolid = $schoolid; } /** @@ -60,21 +64,21 @@ public function get_title() { * @return int */ public function get_role_id() { - return $this->role_id; + return $this->roleid; } /** * @return int */ public function get_school_id() { - return $this->school_id; + return $this->schoolid; } /** * @return int */ public function get_course_category_id() { - return $this->course_category_id; + return $this->coursecategoryid; } /** diff --git a/classes/task/sync_task.php b/classes/task/sync_task.php index ea42741..18011e3 100644 --- a/classes/task/sync_task.php +++ b/classes/task/sync_task.php @@ -42,24 +42,24 @@ public function execute() { raise_memory_limit(MEMORY_HUGE); mtrace('Started Ilios Category Assignment sync job.'); - $sync_jobs = $this->get_enabled_sync_jobs(); - if (empty($sync_jobs)) { + $syncjobs = $this->get_enabled_sync_jobs(); + if (empty($syncjobs)) { mtrace('No sync jobs enabled.'); return; } try { - $ilios_client = manager::instantiate_ilios_client(); + $iliosclient = manager::instantiate_ilios_client(); } catch (\Exception $e) { // re-throw exception throw new \Exception('ERROR: Failed to instantiate Ilios client.' . 0, $e); } - $access_token = manager::get_config('apikey', ''); + $accesstoken = manager::get_config('apikey', ''); // run enabled each sync job - foreach ($sync_jobs as $sync_job) { - $this->run_sync_job($sync_job, $access_token, $ilios_client); + foreach ($syncjobs as $syncjob) { + $this->run_sync_job($syncjob, $accesstoken, $iliosclient); } mtrace('Finished Ilios Category Assignment sync job.'); @@ -70,7 +70,7 @@ public function execute() { * @throws \dml_exception */ protected function get_enabled_sync_jobs() { - return manager::get_sync_jobs(array('enabled' => true)); + return manager::get_sync_jobs(['enabled' => true]); } /** @@ -83,20 +83,20 @@ protected function get_enabled_sync_jobs() { * @throws \moodle_exception * @throws \Exception */ - protected function run_sync_job(sync_job $sync_job, string $access_token, ilios_client $ilios_client) { - $job_title = $sync_job->get_title(); - mtrace("Started sync job '$job_title'."); - $course_category = core_course_category::get($sync_job->get_course_category_id(), IGNORE_MISSING); - if (empty($course_category)) { - mtrace('ERROR: Failed to load course category with ID = ' . $sync_job->get_course_category_id()); + protected function run_sync_job(sync_job $syncjob, string $accesstoken, ilios_client $iliosclient) { + $jobtitle = $syncjob->get_title(); + mtrace("Started sync job '$jobtitle'."); + $coursecategory = core_course_category::get($syncjob->get_course_category_id(), IGNORE_MISSING); + if (empty($coursecategory)) { + mtrace('ERROR: Failed to load course category with ID = ' . $syncjob->get_course_category_id()); return; } - $ilios_users = $this->get_users_from_ilios($sync_job, $access_token, $ilios_client); - mtrace('Retrieved ' . count($ilios_users) . ' Ilios user(s) to sync.'); - $moodle_users = $this->get_moodle_users($ilios_users); - $this->sync_category($sync_job, $course_category, $moodle_users); - mtrace("Finished sync job '$job_title'."); + $iliosusers = $this->get_users_from_ilios($syncjob, $accesstoken, $iliosclient); + mtrace('Retrieved ' . count($iliosusers) . ' Ilios user(s) to sync.'); + $moodleusers = $this->get_moodle_users($iliosusers); + $this->sync_category($syncjob, $coursecategory, $moodleusers); + mtrace("Finished sync job '$jobtitle'."); } /** @@ -109,16 +109,16 @@ protected function run_sync_job(sync_job $sync_job, string $access_token, ilios_ * @return string[] A list of campus IDs. * @throws \Exception */ - protected function get_users_from_ilios(sync_job $sync_job, string $access_token, ilios_client $ilios_client) { - $ilios_users = array(); + protected function get_users_from_ilios(sync_job $syncjob, string $accesstoken, ilios_client $iliosclient) { + $iliosusers = []; - $filters = array( - 'school' => $sync_job->get_school_id(), - 'enabled' => true - ); + $filters = [ + 'school' => $syncjob->get_school_id(), + 'enabled' => true, + ]; try { - $records = $ilios_client->get( - $access_token, + $records = $iliosclient->get( + $accesstoken, 'users', $filters, null, @@ -146,14 +146,13 @@ protected function get_users_from_ilios(sync_job $sync_job, string $access_token if (object_property_exists($rec, 'campusId') && '' !== trim($rec->campusId) ) { - $ilios_users[] = $rec->campusId; + $iliosusers[] = $rec->campusId; } } + $iliosusers = array_unique($iliosusers); - $ilios_users = array_unique($ilios_users); - - return $ilios_users; + return $iliosusers; } /** @@ -165,17 +164,17 @@ protected function get_users_from_ilios(sync_job $sync_job, string $access_token * @throws \coding_exception * @throws \dml_exception */ - protected function get_moodle_users(array $ilios_users) { + protected function get_moodle_users(array $iliosusers) { global $DB; - if (empty($ilios_users)) { - return array(); + if (empty($iliosusers)) { + return []; } - list($insql, $params) = $DB->get_in_or_equal($ilios_users); + list($insql, $params) = $DB->get_in_or_equal($iliosusers); $sql = "SELECT * FROM {user} WHERE idnumber $insql"; $users = $DB->get_records_sql($sql, $params); - if (count($users) < count($ilios_users)) { - $id_numbers = array_column($users, 'idnumber'); - $excluded = array_diff($ilios_users, $id_numbers); + if (count($users) < count($iliosusers)) { + $idnumbers = array_column($users, 'idnumber'); + $excluded = array_diff($iliosusers, $idnumbers); mtrace('WARNING: Skipping non-matching user accounts with the following Ilios campus IDs: ' . implode(', ', $excluded)); } @@ -193,65 +192,65 @@ protected function get_moodle_users(array $ilios_users) { * * @throws \coding_exception */ - public function sync_category(sync_job $sync_job, core_course_category $course_category, array $user_ids) { - $formatted_category_name = $course_category->get_formatted_name(); - mtrace("Started syncing course category '{$formatted_category_name}'."); + public function sync_category(sync_job $syncjob, core_course_category $coursecategory, array $userids) { + $formattedcategoryname = $coursecategory->get_formatted_name(); + mtrace("Started syncing course category '{$formattedcategoryname}'."); $role = new \stdClass(); - $role->id = $sync_job->get_role_id(); - $ctx = $course_category->get_context(); - $role_assignments = get_users_from_role_on_context($role, $ctx); + $role->id = $syncjob->get_role_id(); + $ctx = $coursecategory->get_context(); + $roleassignments = get_users_from_role_on_context($role, $ctx); - $all_assigned_users = array(); - if (!empty($role_assignments)) { - $all_assigned_users = array_column($role_assignments, 'userid'); + $allassignedusers = []; + if (!empty($roleassignments)) { + $allassignedusers = array_column($roleassignments, 'userid'); } // filter out any role assignments that weren't made by this plugin - $role_assignments = array_values(array_filter($role_assignments, function($role) { + $roleassignments = array_values(array_filter($roleassignments, function($role) { return $role->component === 'tool_ilioscategoryassignment'; })); - $assigned_users = array(); - if (!empty($role_assignments)) { - $assigned_users = array_column($role_assignments, 'userid'); + $assignedusers = []; + if (!empty($roleassignments)) { + $assignedusers = array_column($roleassignments, 'userid'); } - $out_of_band_assignments = array_diff($all_assigned_users, $assigned_users); - $add_users = array_diff($user_ids, $assigned_users); - $remove_users = array_diff($assigned_users, $user_ids); + $outofbandassignments = array_diff($allassignedusers, $assignedusers); + $addusers = array_diff($userids, $assignedusers); + $removeusers = array_diff($assignedusers, $userids); - $add_users_total = count($add_users); - $remove_users_total = count($remove_users); + $adduserstotal = count($addusers); + $removeuserstotal = count($removeusers); - if (!$add_users_total && !$remove_users_total) { + if (!$adduserstotal && !$removeuserstotal) { mtrace('No user assignment/un-assignment necessary.'); } - $assignment_counter = 0; - if ($add_users_total) { - foreach ($add_users as $user_id) { + $assignmentcounter = 0; + if ($adduserstotal) { + foreach ($addusers as $userid) { // Prevent double role assignment. - if (in_array($user_id, $out_of_band_assignments)) { + if (in_array($userid, $outofbandassignments)) { mtrace("User with id = ${user_id} had this role assigned out-of-band, skipping."); continue; } - role_assign($sync_job->get_role_id(), $user_id, $ctx->id, 'tool_ilioscategoryassignment'); - $assignment_counter++; + role_assign($syncjob->get_role_id(), $userid, $ctx->id, 'tool_ilioscategoryassignment'); + $assignmentcounter++; } mtrace("Assigned ${assignment_counter} user(s) into category."); } - $unassignment_counter = 0; - if ($remove_users_total) { - foreach ($remove_users as $user_id) { - role_unassign($sync_job->get_role_id(), $user_id, $ctx->id, 'tool_ilioscategoryassignment'); - $unassignment_counter++; + $unassignmentcounter = 0; + if ($removeuserstotal) { + foreach ($removeusers as $userid) { + role_unassign($syncjob->get_role_id(), $userid, $ctx->id, 'tool_ilioscategoryassignment'); + $unassignmentcounter++; } - mtrace("Un-assigned {$unassignment_counter} user(s) from category."); + mtrace("Un-assigned {$unassignmentcounter} user(s) from category."); } - mtrace("Finished syncing course category '{$formatted_category_name}'."); + mtrace("Finished syncing course category '{$formattedcategoryname}'."); } } diff --git a/create.php b/create.php index bd4a421..c5c77f0 100644 --- a/create.php +++ b/create.php @@ -38,20 +38,20 @@ $data = $mform->get_data(); if ($data) { - $sync_sources = array(); - $ilios_school_id = (int) $data->iliosschoolid; + $syncsources = []; + $iliosschoolid = (int) $data->iliosschoolid; - $sync_job = new sync_job( + $syncjob = new sync_job( null, $data->title, (int) $data->roleid, (int) $data->categoryid, true, - $ilios_school_id + $iliosschoolid ); - $sync_job = manager::create_job($sync_job); - $redirect_url = new moodle_url("$CFG->wwwroot/$CFG->admin/tool/ilioscategoryassignment/index.php"); - redirect($redirect_url, get_string('newjobcreated', 'tool_ilioscategoryassignment', $sync_job->get_title()), 10); + $syncjob = manager::create_job($syncjob); + $redirecturl = new moodle_url("$CFG->wwwroot/$CFG->admin/tool/ilioscategoryassignment/index.php"); + redirect($redirecturl, get_string('newjobcreated', 'tool_ilioscategoryassignment', $syncjob->get_title()), 10); } else { /* @var core_renderer $OUTPUT */ echo $OUTPUT->header(); diff --git a/db/events.php b/db/events.php index 6df9f34..a5aff91 100644 --- a/db/events.php +++ b/db/events.php @@ -7,10 +7,10 @@ */ // List of observers. -$observers = array( - array( +$observers = [ + [ 'eventname' => '\core\event\course_category_deleted', 'priority' => 1, 'callback' => '\tool_ilioscategoryassignment\manager::course_category_deleted', - ), -); + ], +]; diff --git a/db/tasks.php b/db/tasks.php index faced79..5c45a2b 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -8,14 +8,14 @@ defined('MOODLE_INTERNAL') || die(); -$tasks = array( - array( +$tasks = [ + [ 'classname' => 'tool_ilioscategoryassignment\task\sync_task', 'blocking' => 0, 'minute' => '0', 'hour' => '0', 'day' => '*', 'month' => '*', - 'dayofweek' => '*' - ) -); + 'dayofweek' => '*', + ], +]; diff --git a/db/uninstall.php b/db/uninstall.php index 650e2fc..2e8d33c 100644 --- a/db/uninstall.php +++ b/db/uninstall.php @@ -15,6 +15,6 @@ * @return bool */ function xmldb_tool_ilioscategoryassignment_uninstall() { - role_unassign_all(array('component' => 'tool_ilioscategoryassignment')); + role_unassign_all(['component' => 'tool_ilioscategoryassignment']); return true; } diff --git a/db/upgrade.php b/db/upgrade.php index 2aaae80..60d0395 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -28,8 +28,7 @@ * @param int $oldversion * @return bool always true */ -function xmldb_tool_ilioscategoryassignment_upgrade($oldversion) -{ +function xmldb_tool_ilioscategoryassignment_upgrade($oldversion) { global $DB; $dbman = $DB->get_manager(); @@ -47,6 +46,6 @@ function xmldb_tool_ilioscategoryassignment_upgrade($oldversion) } upgrade_plugin_savepoint(true, 2018041100, 'tool', 'ilioscategoryassignment'); } - + return true; } diff --git a/index.php b/index.php index 24cfbee..601e95c 100644 --- a/index.php +++ b/index.php @@ -37,26 +37,26 @@ $renderer = $PAGE->get_renderer('tool_ilioscategoryassignment'); -if (in_array($action, array('enable', 'disable', 'delete'))) { +if (in_array($action, ['enable', 'disable', 'delete'])) { require_sesskey(); - $job_id = required_param('job_id', PARAM_INT); - $job = manager::get_sync_job($job_id); + $jobid = required_param('job_id', PARAM_INT); + $job = manager::get_sync_job($jobid); if (!empty($job)) { if ('enable' === $action && confirm_sesskey()) { - manager::enable_job($job_id); + manager::enable_job($jobid); $returnmsg = get_string('jobenabled', 'tool_ilioscategoryassignment', $job->get_title()); redirect($returnurl, $returnmsg, null, notification::NOTIFY_SUCCESS); - } elseif ('disable' === $action && confirm_sesskey()) { - manager::disable_job($job_id); + } else if ('disable' === $action && confirm_sesskey()) { + manager::disable_job($jobid); $returnmsg = get_string('jobdisabled', 'tool_ilioscategoryassignment', $job->get_title()); redirect($returnurl, $returnmsg, null, notification::NOTIFY_SUCCESS); - } elseif ('delete' === $action && confirm_sesskey()) { + } else if ('delete' === $action && confirm_sesskey()) { if ($confirm !== md5($action)) { echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('deletejob', 'tool_ilioscategoryassignment')); $deleteurl = new moodle_url( $returnurl, - array('action' => $action, 'job_id' => $job->get_id(), 'confirm' => md5($action), 'sesskey' => sesskey()) + ['action' => $action, 'job_id' => $job->get_id(), 'confirm' => md5($action), 'sesskey' => sesskey()] ); $deletebutton = new single_button($deleteurl, get_string('delete'), 'post'); @@ -78,14 +78,14 @@ } echo $OUTPUT->confirm( - get_string('deletejobconfirm','tool_ilioscategoryassignment', $a), + get_string('deletejobconfirm', 'tool_ilioscategoryassignment', $a), $deletebutton, $returnurl ); echo $OUTPUT->footer(); die; - } elseif (data_submitted()) { - manager::delete_job($job_id); + } else if (data_submitted()) { + manager::delete_job($jobid); $returnmsg = get_string('jobdeleted', 'tool_ilioscategoryassignment', $job->get_title()); redirect($returnurl, $returnmsg, null, notification::NOTIFY_SUCCESS); @@ -97,26 +97,26 @@ $jobs = manager::get_sync_jobs(); -$course_categories = array(); -$roles = array(); -$ilios_schools = array(); +$coursecategories = []; +$roles = []; +$iliosschools = []; if (!empty($jobs)) { - $course_category_ids = array_column($jobs, 'course_category_id'); - $course_categories = core_course_category::get_many($course_category_ids); + $coursecategoryids = array_column($jobs, 'course_category_id'); + $coursecategories = core_course_category::get_many($coursecategoryids); $roles = role_get_names(); } try { - $access_token = manager::get_config('apikey', ''); - $ilios_client = manager::instantiate_ilios_client(); - $ilios_schools = $ilios_client->get($access_token, 'schools'); - $ilios_schools = array_column($ilios_schools, 'title', 'id'); + $accesstoken = manager::get_config('apikey', ''); + $iliosclient = manager::instantiate_ilios_client(); + $iliosschools = $iliosclient->get($accesstoken, 'schools'); + $iliosschools = array_column($iliosschools, 'title', 'id'); } catch (Exception $e) { echo $renderer->notify_error(get_string('ilioserror', 'tool_ilioscategoryassignment')); } echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('syncjobscount', 'tool_ilioscategoryassignment', count($jobs))); -echo $renderer->sync_jobs_table($jobs, $course_categories, $roles, $ilios_schools); +echo $renderer->sync_jobs_table($jobs, $coursecategories, $roles, $iliosschools); echo $OUTPUT->footer(); diff --git a/version.php b/version.php index 344f57f..f740378 100644 --- a/version.php +++ b/version.php @@ -13,6 +13,6 @@ $plugin->release = 'v4.3'; $plugin->supported = [403, 403]; $plugin->maturity = MATURITY_STABLE; -$plugin->dependencies = array( +$plugin->dependencies = [ 'local_iliosapiclient' => 2024032200, -); \ No newline at end of file +]; From 36614bec80f1c9af0c27b81efda05ae077313c99 Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Mon, 3 Jun 2024 17:23:13 -0700 Subject: [PATCH 3/4] manually corrects PHP code linter errors. --- classes/form/create_sync_job.php | 44 ++++-- classes/manager.php | 138 +++++++++++-------- classes/output/renderer.php | 53 +++++--- classes/sync_job.php | 101 ++++++++++---- classes/task/sync_task.php | 163 +++++++++++++---------- create.php | 23 +++- db/events.php | 20 ++- db/tasks.php | 22 ++- db/uninstall.php | 29 +++- db/upgrade.php | 25 ++-- index.php | 28 ++-- lang/en/tool_ilioscategoryassignment.php | 26 +++- settings.php | 31 +++-- version.php | 25 +++- 14 files changed, 493 insertions(+), 235 deletions(-) diff --git a/classes/form/create_sync_job.php b/classes/form/create_sync_job.php index 4b0e35f..0b614ca 100644 --- a/classes/form/create_sync_job.php +++ b/classes/form/create_sync_job.php @@ -1,9 +1,25 @@ . + /** * Form for creating a new sync job. * - * @package tool_ilioscategoryassignment - * @category form + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace tool_ilioscategoryassignment\form; @@ -11,30 +27,31 @@ defined('MOODLE_INTERNAL') || die(); use core_course_category; +use Exception; +use moodle_page; use moodleform; use tool_ilioscategoryassignment\manager; use tool_ilioscategoryassignment\output\renderer; -/* @global $CFG */ require_once($CFG->libdir . '/accesslib.php'); require_once($CFG->libdir . '/formslib.php'); /** - * Form for creating a new sync job. + * New sync job form class. * - * @package tool_ilioscategoryassignment - * @category form + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class create_sync_job extends moodleform { - /** - * @inheritdoc + * Form definition. */ - public function definition() { - /* @var \moodle_page $PAGE */ + public function definition(): void { + /* @var moodle_page $PAGE The current page. */ global $PAGE; - /* @var renderer $renderer */ + /* @var renderer $renderer The plugin renderer. */ $renderer = $PAGE->get_renderer('tool_ilioscategoryassignment'); $mform = $this->_form; @@ -65,13 +82,14 @@ public function definition() { if (!empty($iliosschools)) { $iliosschools = array_column($iliosschools, 'title', 'id'); } - } catch (\Exception $e) { + } catch (Exception $e) { $warning = $renderer->notify_error(get_string('ilioserror', 'tool_ilioscategoryassignment')); $mform->addElement('html', $warning); return; } - $mform->addElement('text', 'title', get_string('title', 'tool_ilioscategoryassignment')); // Add elements to your form + // Add elements to your form. + $mform->addElement('text', 'title', get_string('title', 'tool_ilioscategoryassignment')); $mform->setType('title', PARAM_NOTAGS); $mform->addRule('title', null, 'required', null, 'client'); $mform->addRule('title', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); diff --git a/classes/manager.php b/classes/manager.php index d6e7a25..aaa1f4f 100644 --- a/classes/manager.php +++ b/classes/manager.php @@ -1,49 +1,70 @@ . /** * Handles sync job, configuration and Ilios client management. * - * @package tool_ilioscategoryassignment + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace tool_ilioscategoryassignment; -/* @global $CFG */ +use coding_exception; use core\event\course_category_deleted; use core_course_category; use curl; +use dml_exception; use local_iliosapiclient\ilios_client; +use moodle_exception; +use stdClass; + +defined('MOODLE_INTERNAL') || die(); require_once($CFG->libdir . '/accesslib.php'); /** - * Handles sync job, configuration and Ilios client management. + * Handler class for sync job, configuration and Ilios client management. * - * In other words, this is kitchen sink. + * In other words, this is the kitchen sink. * This is obviously less than ideal, but still better than polluting the global namespace with functions in locallib.php. * [ST 2017/07/24] * - * @package tool_ilioscategoryassignment + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class manager { - - const PLUGIN_NAME = 'tool_ilioscategoryassignment'; - /** * Instantiates and returns an Ilios API client. * * @return ilios_client - * @throws \moodle_exception + * @throws moodle_exception */ public static function instantiate_ilios_client(): ilios_client { return new ilios_client(self::get_config('host_url', ''), new curl()); } /** - * @param $id + * Retrieves a sync job by its given ID. * - * @return sync_job|null - * @throws \dml_exception + * @param int $id The sync job ID. + * @return sync_job|null The sync job, or NULL if none were found. + * @throws dml_exception */ public static function get_sync_job($id) { $jobs = self::get_sync_jobs(['id' => $id]); @@ -53,26 +74,25 @@ public static function get_sync_job($id) { /** * Loads, caches and returns the configuration for this plugin. * - * @return \stdClass + * @return stdClass The plugin configuration object. * @see get_config() - * @throws \dml_exception + * @throws dml_exception */ public static function get_plugin_config() { static $config = null; if (!isset($config)) { - $config = get_config(self::PLUGIN_NAME); + $config = get_config('tool_ilioscategoryassignment'); } return $config; } /** - * Returns a configuration value by its given name or a given default value. - * - * @param string $name - * @param string $default value if config does not exist yet + * Returns a configuration item by its given name or a given default value. * - * @return string value or default - * @throws \dml_exception + * @param string $name The config item name. + * @param string $default A default value if the config item does not exist. + * @return mixed The config value or the given default value. + * @throws dml_exception */ public static function get_config($name, $default = null) { $config = self::get_plugin_config(); @@ -82,28 +102,29 @@ public static function get_config($name, $default = null) { /** * Sets and stores a given config value. * - * @param string $name name of config - * @param string $value string config value, null means delete - * - * @throws \dml_exception + * @param string $name The config item name. + * @param string $value string The config item's value, NULL means unset the config item. + * @return void + * @throws dml_exception */ - public static function set_config($name, $value) { + public static function set_config($name, $value): void { $config = self::get_plugin_config(); if ($value === null) { unset($config->$name); } else { $config->$name = $value; } - set_config($name, $value, self::PLUGIN_NAME); + set_config($name, $value, 'tool_ilioscategoryassignment'); } /** - * @param array $filters + * Retrieves all sync jobs matching the given filters. * - * @return sync_job[] - * @throws \dml_exception + * @param array $filters The filter criteria. + * @return array A list of sync jobs. + * @throws dml_exception */ - public static function get_sync_jobs(array $filters = []) { + public static function get_sync_jobs(array $filters = []): array { global $DB; $jobs = []; $jobrecs = $DB->get_records('tool_ilioscatassignment', $filters); @@ -116,11 +137,13 @@ public static function get_sync_jobs(array $filters = []) { } /** - * @param int $job_id + * Disables a given sync job. * - * @throws \dml_exception + * @param int $jobid The job ID. + * @return void + * @throws dml_exception */ - public static function disable_job($jobid) { + public static function disable_job($jobid): void { global $DB; $tablename = 'tool_ilioscatassignment'; $job = $DB->get_record($tablename, ['id' => $jobid]); @@ -131,11 +154,13 @@ public static function disable_job($jobid) { } /** - * @param int $job_id + * Enables a given sync job. * - * @throws \dml_exception + * @param int $jobid The job ID. + * @return void + * @throws dml_exception */ - public static function enable_job($jobid) { + public static function enable_job($jobid): void { global $DB; $tablename = 'tool_ilioscatassignment'; $job = $DB->get_record($tablename, ['id' => $jobid]); @@ -146,14 +171,15 @@ public static function enable_job($jobid) { } /** - * @param sync_job $job - * - * @return sync_job - * @throws \dml_exception + * Creates and returns a new sync job. + * @param sync_job $job The new sync job to create. + * @return sync_job The created sync job. + * @throws dml_exception */ public static function create_job(sync_job $job) { global $DB; - $dto = new \stdClass(); + + $dto = new stdClass(); $dto->title = $job->get_title(); $dto->roleid = $job->get_role_id(); $dto->coursecatid = $job->get_course_category_id(); @@ -165,23 +191,25 @@ public static function create_job(sync_job $job) { } /** - * @param int $job_id + * Deletes a given sync job. * - * @throws \coding_exception - * @throws \dml_exception - * @throws \moodle_exception + * @param int $jobid The sync job ID. + * @return void + * @throws coding_exception + * @throws dml_exception + * @throws moodle_exception */ - public static function delete_job($jobid) { + public static function delete_job($jobid): void { global $DB; $job = self::get_sync_job($jobid); if (empty($job)) { return; } - // delete the given job + // Delete the given job. $DB->delete_records('tool_ilioscatassignment', ['id' => $jobid]); - // remove any course category role assignments that were managed by the given job + // Remove any course category role assignments that were managed by the given job. $category = core_course_category::get($job->get_course_category_id(), IGNORE_MISSING); if (empty($category)) { return; @@ -195,13 +223,13 @@ public static function delete_job($jobid) { * Event observer for the "course category deleted" event. * Removes any sync jobs and role assignments associated with that category. * - * @param \core\event\course_category_deleted $event - * - * @throws \coding_exception - * @throws \dml_exception - * @throws \moodle_exception + * @param course_category_deleted $event + * @return void + * @throws coding_exception + * @throws dml_exception + * @throws moodle_exception */ - public static function course_category_deleted(course_category_deleted $event) { + public static function course_category_deleted(course_category_deleted $event): void { $category = $event->get_coursecat(); $jobs = self::get_sync_jobs(['coursecatid' => $category->id]); foreach ($jobs as $job) { diff --git a/classes/output/renderer.php b/classes/output/renderer.php index 7642e5d..d111050 100644 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -1,4 +1,26 @@ . + +/** + * Output renderer for the plugin. + * + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ namespace tool_ilioscategoryassignment\output; @@ -19,34 +41,25 @@ use function sesskey; /** - * Output renderer for the plugin. + * Output renderer class. * - * @package tool_ilioscategoryassignment - * @category output - */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Output renderer for the plugin. - * - * @package tool_ilioscategoryassignment - * @category output + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class renderer extends plugin_renderer_base { /** * Renders a table displaying all configured sync jobs. * - * @param sync_job[] $sync_jobs - * @param core_course_category[] $course_categories + * @param sync_job[] $syncjobs + * @param core_course_category[] $coursecategories * @param stdClass[] $roles - * @param string[] $ilios_schools - * + * @param string[] $iliosschools * @return string HTML to output. * @throws coding_exception * @throws moodle_exception */ - public function sync_jobs_table(array $syncjobs, array $coursecategories, array $roles, array $iliosschools) { + public function sync_jobs_table(array $syncjobs, array $coursecategories, array $roles, array $iliosschools): string { global $CFG; $table = new html_table(); $table->head = [ @@ -124,7 +137,7 @@ public function sync_jobs_table(array $syncjobs, array $coursecategories, array /** * Renders and returns a notification. * - * @param string $message the message + * @param string $message The message. * @return string The formatted message. */ public function notify_info($message) { @@ -135,7 +148,7 @@ public function notify_info($message) { /** * Renders and returns an error notification. * - * @param string $message the message + * @param string $message The message. * @return string The formatted message. */ public function notify_error($message) { @@ -146,7 +159,7 @@ public function notify_error($message) { /** * Renders and returns a success notification. * - * @param string $message the message + * @param string $message The message. * @return string The formatted message. */ public function notify_success($message) { diff --git a/classes/sync_job.php b/classes/sync_job.php index f2add34..e91d459 100644 --- a/classes/sync_job.php +++ b/classes/sync_job.php @@ -1,41 +1,76 @@ . + +/** + * Defines the sync job model. + * + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ namespace tool_ilioscategoryassignment; /** - * Sync job definition model. + * Sync job model class. * - * @package tool_ilioscategoryassignment - * @category model + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class sync_job { - /** @var int $id */ + /** + * @var int $id The sync job ID. + */ protected $id; - /** @var string $title */ + /** + * @var string $title The sync job title. + */ protected $title; - /** @var int $role_id */ + /** + * @var int $role_id The Moodle user role ID to assign to users during sync. + */ protected $roleid; - /** @var int $coursecategoryid */ + /** + * @var int $coursecategoryid The Moodle course category ID to sync users into. + */ protected $coursecategoryid; - /** @var bool $enabled */ + /** + * @var bool $enabled TRUE if this job is enabled, otherwise FALSE. + */ protected $enabled; - /** @var int $school_id */ + /** + * @var int $schoolid The Ilios school ID to sync users from. + */ protected $schoolid; /** * Constructor. * - * @param $id - * @param $title - * @param $roleid - * @param $course_category_id - * @param $enabled - * @param $schoolid + * @param int $id The sync job Id. + * @param string $title The sync job title. + * @param int $roleid The Moodle user role ID to assign to users during sync. + * @param int $coursecategoryid The Moodle course category ID to sync users into. + * @param bool $enabled TRUE if this job is enabled, otherwise FALSE. + * @param int $schoolid The Ilios school ID to sync users from. */ public function __construct($id, $title, $roleid, $coursecategoryid, $enabled, $schoolid) { $this->id = $id; @@ -47,58 +82,74 @@ public function __construct($id, $title, $roleid, $coursecategoryid, $enabled, $ } /** - * @return int + * Returns the sync job ID. + * + * @return int The sync job ID. */ public function get_id() { return $this->id; } /** - * @return string + * Returns the sync job title. + * + * @return string The sync job title. */ public function get_title() { return $this->title; } /** - * @return int + * Returns the Moodle user role ID. + * + * @return int The user role ID. */ public function get_role_id() { return $this->roleid; } /** - * @return int + * Returns the Ilios school ID. + * + * @return int The school ID. */ public function get_school_id() { return $this->schoolid; } /** - * @return int + * Returns the Moodle course category ID. + * + * @return int The course category ID. */ public function get_course_category_id() { return $this->coursecategoryid; } /** - * @return bool + * Returns whether this sync job is enabled or not. + * + * @return bool TRUE if this job is enabled, otherwise FALSE. */ public function is_enabled() { return $this->enabled; } /** - * @param string $prop - * @return mixed + * Magic getter function. + * + * @param string $prop The property name. + * @return mixed The property value. */ public function __get($prop) { return $this->$prop; } /** - * @param string $prop - * @return bool + * Determine if a variable is declared and is different from NULL. + * + * @param string $prop The property name. + * @return bool TRUE if the property is declared/set, FALSE otherwise. */ public function __isset($prop) { return isset($this->$prop); diff --git a/classes/task/sync_task.php b/classes/task/sync_task.php index 18011e3..ed19f96 100644 --- a/classes/task/sync_task.php +++ b/classes/task/sync_task.php @@ -1,43 +1,72 @@ . + /** * A scheduled task for syncing users with Ilios. * - * @package tool_ilioscategoryassignment - * @category task + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace tool_ilioscategoryassignment\task; +use coding_exception; use core\task\scheduled_task; use core_course_category; +use dml_exception; +use Exception; use local_iliosapiclient\ilios_client; +use moodle_exception; +use stdClass; use tool_ilioscategoryassignment\manager; use tool_ilioscategoryassignment\sync_job; -/* @global $CFG */ +defined('MOODLE_INTERNAL') || die(); + require_once($CFG->libdir . '/accesslib.php'); /** - * A scheduled task for syncing users with Ilios. + * The scheduled task class. * - * @package tool_ilioscategoryassignment - * @category task + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class sync_task extends scheduled_task { - /** - * @inheritdoc + * Returns the task name. + * + * @return string The task name. + * @throws coding_exception */ public function get_name() { return get_string('taskname', 'tool_ilioscategoryassignment'); } /** - * @inheritdoc + * Executes this task. + * + * @return void + * @throws dml_exception + * @throws moodle_exception + * @throws exception */ - public function execute() { - - // this may take a while and consume quite a bit of memory... + public function execute(): void { + // This may take a while and consume quite a bit of memory. @set_time_limit(0); raise_memory_limit(MEMORY_HUGE); @@ -50,14 +79,14 @@ public function execute() { try { $iliosclient = manager::instantiate_ilios_client(); - } catch (\Exception $e) { - // re-throw exception - throw new \Exception('ERROR: Failed to instantiate Ilios client.' . 0, $e); + } catch (Exception $e) { + // Re-throw exception. + throw new Exception('ERROR: Failed to instantiate Ilios client.' . 0, $e); } $accesstoken = manager::get_config('apikey', ''); - // run enabled each sync job + // Run enabled each sync job. foreach ($syncjobs as $syncjob) { $this->run_sync_job($syncjob, $accesstoken, $iliosclient); } @@ -66,30 +95,31 @@ public function execute() { } /** - * @return sync_job[] - * @throws \dml_exception + * Retrieves the list of enabled sync jobs. + * + * @return array A list of enabled sync jobs. + * @throws dml_exception */ - protected function get_enabled_sync_jobs() { + protected function get_enabled_sync_jobs(): array { return manager::get_sync_jobs(['enabled' => true]); } /** * Performs a given sync job. * - * @param sync_job $sync_job - * @param string $access_token - * @param $ilios_client $ilios_client - * - * @throws \moodle_exception - * @throws \Exception + * @param sync_job $syncjob The sync job. + * @param string $accesstoken An Ilios API access token. + * @param ilios_client $iliosclient The Ilios API client. + * @return void + * @throws moodle_exception + * @throws Exception */ - protected function run_sync_job(sync_job $syncjob, string $accesstoken, ilios_client $iliosclient) { + protected function run_sync_job(sync_job $syncjob, string $accesstoken, ilios_client $iliosclient): void { $jobtitle = $syncjob->get_title(); mtrace("Started sync job '$jobtitle'."); $coursecategory = core_course_category::get($syncjob->get_course_category_id(), IGNORE_MISSING); if (empty($coursecategory)) { mtrace('ERROR: Failed to load course category with ID = ' . $syncjob->get_course_category_id()); - return; } $iliosusers = $this->get_users_from_ilios($syncjob, $accesstoken, $iliosclient); @@ -100,16 +130,15 @@ protected function run_sync_job(sync_job $syncjob, string $accesstoken, ilios_cl } /** - * Retrieves a list of user campus IDs from Ilios qualifying for the given sync job. - * - * @param sync_job $sync_job - * @param string $access_token - * @param ilios_client $ilios_client + * Retrieves a list of campus IDs for users qualifying for the given sync job from Ilios. * - * @return string[] A list of campus IDs. - * @throws \Exception + * @param sync_job $syncjob The sync job. + * @param string $accesstoken The Ilios API access token. + * @param ilios_client $iliosclient The Ilios API client. + * @return array A list of campus IDs. + * @throws Exception */ - protected function get_users_from_ilios(sync_job $syncjob, string $accesstoken, ilios_client $iliosclient) { + protected function get_users_from_ilios(sync_job $syncjob, string $accesstoken, ilios_client $iliosclient): array { $iliosusers = []; $filters = [ @@ -125,14 +154,13 @@ protected function get_users_from_ilios(sync_job $syncjob, string $accesstoken, 5000 ); - } catch (\Exception $e) { - // re-throw exception with a better error message - throw new \Exception('Failed to retrieve users from Ilios with the following parameters: ' . - print_r($filters, true), 0, $e); + } catch (Exception $e) { + // Re-throw exception with a better error message. + throw new Exception('Failed to retrieve users from Ilios with the following error message.', 0, $e); } - // filter out any users that do not fulfill a director or instructor function in ilios. - $records = array_filter($records, function(\stdClass $rec) { + // Filter out any users that do not fulfill a director or instructor function in ilios. + $records = array_filter($records, function(stdClass $rec) { return ! empty($rec->directedCourses) || ! empty($rec->directedPrograms) || ! empty($rec->directedSchools) || @@ -150,21 +178,18 @@ protected function get_users_from_ilios(sync_job $syncjob, string $accesstoken, } } - $iliosusers = array_unique($iliosusers); - - return $iliosusers; + return array_unique($iliosusers); } /** * Retrieves the IDs of all users matching a given list of Ilios user campus IDs. * - * @param string[] $ilios_users The campus IDs of users retrieved from Ilios. - * - * @return int[] A list of Moodle user IDs. - * @throws \coding_exception - * @throws \dml_exception + * @param array $iliosusers The campus IDs of users retrieved from Ilios. + * @return array A list of Moodle user IDs. + * @throws coding_exception + * @throws dml_exception */ - protected function get_moodle_users(array $iliosusers) { + protected function get_moodle_users(array $iliosusers): array { global $DB; if (empty($iliosusers)) { return []; @@ -180,22 +205,20 @@ protected function get_moodle_users(array $iliosusers) { } return array_column($users, 'id'); - } /** - * Updates users role assignment in a given category. - * - * @param sync_job $sync_job - * @param core_course_category $course_category - * @param int[] $user_ids + * Updates users role assignment in a given course category. * - * @throws \coding_exception + * @param sync_job $syncjob The sync job. + * @param core_course_category $coursecategory The course category. + * @param array $userids A list of IDs of users that were updated during this sync job. + * @throws coding_exception */ - public function sync_category(sync_job $syncjob, core_course_category $coursecategory, array $userids) { + public function sync_category(sync_job $syncjob, core_course_category $coursecategory, array $userids): void { $formattedcategoryname = $coursecategory->get_formatted_name(); - mtrace("Started syncing course category '{$formattedcategoryname}'."); - $role = new \stdClass(); + mtrace("Started syncing course category '$formattedcategoryname'."); + $role = new stdClass(); $role->id = $syncjob->get_role_id(); $ctx = $coursecategory->get_context(); $roleassignments = get_users_from_role_on_context($role, $ctx); @@ -205,10 +228,12 @@ public function sync_category(sync_job $syncjob, core_course_category $coursecat $allassignedusers = array_column($roleassignments, 'userid'); } - // filter out any role assignments that weren't made by this plugin - $roleassignments = array_values(array_filter($roleassignments, function($role) { - return $role->component === 'tool_ilioscategoryassignment'; - })); + // Filter out any role assignments that weren't made by this plugin. + $roleassignments = array_values( + array_filter($roleassignments, function($role) { + return $role->component === 'tool_ilioscategoryassignment'; + }) + ); $assignedusers = []; if (!empty($roleassignments)) { @@ -231,14 +256,13 @@ public function sync_category(sync_job $syncjob, core_course_category $coursecat foreach ($addusers as $userid) { // Prevent double role assignment. if (in_array($userid, $outofbandassignments)) { - mtrace("User with id = ${user_id} had this role assigned out-of-band, skipping."); + mtrace("User with id = $userid had this role assigned out-of-band, skipping."); continue; } role_assign($syncjob->get_role_id(), $userid, $ctx->id, 'tool_ilioscategoryassignment'); $assignmentcounter++; } - mtrace("Assigned ${assignment_counter} user(s) into category."); - + mtrace("Assigned $assignmentcounter user(s) into category."); } $unassignmentcounter = 0; @@ -247,10 +271,9 @@ public function sync_category(sync_job $syncjob, core_course_category $coursecat role_unassign($syncjob->get_role_id(), $userid, $ctx->id, 'tool_ilioscategoryassignment'); $unassignmentcounter++; } - mtrace("Un-assigned {$unassignmentcounter} user(s) from category."); + mtrace("Un-assigned $unassignmentcounter user(s) from category."); } - - mtrace("Finished syncing course category '{$formattedcategoryname}'."); + mtrace("Finished syncing course category '$formattedcategoryname'."); } } diff --git a/create.php b/create.php index c5c77f0..fb4cb3b 100644 --- a/create.php +++ b/create.php @@ -1,30 +1,42 @@ . /** * Create new sync job page. * - * @package tool_ilioscategoryassignment + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ use tool_ilioscategoryassignment\form\create_sync_job; use tool_ilioscategoryassignment\manager; use tool_ilioscategoryassignment\output\renderer; use tool_ilioscategoryassignment\sync_job; -use tool_ilioscategoryassignment\sync_source; require_once(__DIR__ . '/../../../config.php'); require_login(); require_capability('moodle/site:config', context_system::instance()); -/* @var $CFG */ require_once($CFG->libdir . '/adminlib.php'); require_once($CFG->libdir . '/tablelib.php'); $action = optional_param('action', 'list', PARAM_ALPHA); -/* @var moodle_page $PAGE */ -/* @var renderer $renderer */ $PAGE->set_context(context_system::instance()); $PAGE->set_url('/admin/tool/ilioscategoryassignment/create.php'); $PAGE->set_pagelayout('admin'); @@ -53,7 +65,6 @@ $redirecturl = new moodle_url("$CFG->wwwroot/$CFG->admin/tool/ilioscategoryassignment/index.php"); redirect($redirecturl, get_string('newjobcreated', 'tool_ilioscategoryassignment', $syncjob->get_title()), 10); } else { - /* @var core_renderer $OUTPUT */ echo $OUTPUT->header(); echo $OUTPUT->heading($strheading); $mform->display(); diff --git a/db/events.php b/db/events.php index a5aff91..3aa90ca 100644 --- a/db/events.php +++ b/db/events.php @@ -1,11 +1,29 @@ . /** * Event observer definitions. * - * @package tool_ilioscategoryassignment + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + // List of observers. $observers = [ [ diff --git a/db/tasks.php b/db/tasks.php index 5c45a2b..1326c02 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -1,9 +1,25 @@ . + /** - * Definition of Ilios category assignment tasks + * Task definitions. * - * @package tool_ilioscategoryassignment - * @category task + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); diff --git a/db/uninstall.php b/db/uninstall.php index 2e8d33c..e627804 100644 --- a/db/uninstall.php +++ b/db/uninstall.php @@ -1,20 +1,37 @@ . + /** - * Plugin un-installation callback. + * Uninstall script. * - * @package tool_ilioscategoryassignment - * @link https://docs.moodle.org/dev/Plugin_files#db.2Funinstall.php + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -/* @global $CFG */ require_once($CFG->libdir . '/accesslib.php'); /** - * @return bool + * Plugin uninstall callback. + * @return bool Always TRUE. + * @throws coding_exception */ -function xmldb_tool_ilioscategoryassignment_uninstall() { +function xmldb_tool_ilioscategoryassignment_uninstall(): bool { role_unassign_all(['component' => 'tool_ilioscategoryassignment']); return true; } diff --git a/db/upgrade.php b/db/upgrade.php index 60d0395..694debc 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -17,18 +17,24 @@ /** * Upgrade script. * - * @package tool_ilioscategoryassignment - * @link https://docs.moodle.org/dev/Plugin_files#db.2Funinstall.php + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); /** - * Upgrade the plugin. + * Plugin upgrade callback. * - * @param int $oldversion - * @return bool always true + * @param int $oldversion The old plugin version. + * @return bool Always TRUE. + * @throws ddl_exception + * @throws ddl_table_missing_exception + * @throws dml_exception + * @throws downgrade_exception + * @throws moodle_exception + * @throws upgrade_exception */ -function xmldb_tool_ilioscategoryassignment_upgrade($oldversion) { +function xmldb_tool_ilioscategoryassignment_upgrade($oldversion): bool { global $DB; $dbman = $DB->get_manager(); @@ -39,7 +45,10 @@ function xmldb_tool_ilioscategoryassignment_upgrade($oldversion) { if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } - $DB->execute('UPDATE {tool_ilioscatassignment} t SET t.schoolid = (SELECT schoolid FROM {tool_ilioscatassignment_src} WHERE jobid = t.id ORDER BY id DESC LIMIT 1)'); + $DB->execute( + 'UPDATE {tool_ilioscatassignment} t SET t.schoolid = ' . + ' (SELECT schoolid FROM {tool_ilioscatassignment_src} WHERE jobid = t.id ORDER BY id DESC LIMIT 1)' + ); $table = new xmldb_table('tool_ilioscatassignment_src'); if ($dbman->table_exists($table)) { $dbman->drop_table($table); diff --git a/index.php b/index.php index 601e95c..08ebd81 100644 --- a/index.php +++ b/index.php @@ -1,21 +1,35 @@ . /** - * Sync jobs admin pages. + * Sync jobs admin page. * * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ use core\output\notification; use tool_ilioscategoryassignment\manager; -use tool_ilioscategoryassignment\output\renderer; require_once(__DIR__ . '/../../../config.php'); require_login(); require_capability('moodle/site:config', context_system::instance()); -/* @var $CFG */ require_once($CFG->libdir . '/adminlib.php'); require_once($CFG->libdir . '/tablelib.php'); @@ -24,10 +38,6 @@ $returnurl = new moodle_url('/admin/tool/ilioscategoryassignment/index.php'); -/* @var moodle_page $PAGE */ -/* @var renderer $renderer */ -/* @var core_renderer $OUTPUT */ - $PAGE->set_context(context_system::instance()); $PAGE->set_url('/admin/tool/ilioscategoryassignment/index.php'); $PAGE->set_pagelayout('admin'); @@ -50,7 +60,7 @@ manager::disable_job($jobid); $returnmsg = get_string('jobdisabled', 'tool_ilioscategoryassignment', $job->get_title()); redirect($returnurl, $returnmsg, null, notification::NOTIFY_SUCCESS); - } else if ('delete' === $action && confirm_sesskey()) { + } else if ('delete' === $action && confirm_sesskey()) { if ($confirm !== md5($action)) { echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('deletejob', 'tool_ilioscategoryassignment')); @@ -102,7 +112,7 @@ $iliosschools = []; if (!empty($jobs)) { - $coursecategoryids = array_column($jobs, 'course_category_id'); + $coursecategoryids = array_column($jobs, 'coursecategoryid'); $coursecategories = core_course_category::get_many($coursecategoryids); $roles = role_get_names(); } diff --git a/lang/en/tool_ilioscategoryassignment.php b/lang/en/tool_ilioscategoryassignment.php index 6fcecb2..1118ae5 100644 --- a/lang/en/tool_ilioscategoryassignment.php +++ b/lang/en/tool_ilioscategoryassignment.php @@ -1,11 +1,26 @@ . /** - * Language strings. + * Language strings for the tool_ilioscategoryassignment plugin. * - * @package tool_ilioscategoryassignment + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - $string['apikey'] = 'Ilios API key'; $string['apikey_desc'] = 'Enter the API key obtained from your Ilios server.'; $string['clientconfig'] = "Ilios API client configuration"; @@ -14,12 +29,11 @@ $string['deletejobconfirm'] = 'You are about to delete the Ilios category assignment sync job "{$a->jobtitle}". All users currently assigned as course participants in the "{$a->roletitle}" role to courses in the "{$a->coursecattitle}" course category using this method will be removed.

Are you sure you want to continue?'; $string['host_url'] = 'Host URL'; $string['host_url_desc'] = 'Type Ilios server IP address or host URL.'; -$string['ilioserror'] = - 'An error occurred while accessing Ilios. Please check that Ilios is up and running, and that your connection to Ilios is configured correctly.'; +$string['ilioserror'] = 'An error occurred while accessing Ilios. Please check that Ilios is up and running, and that your connection to Ilios is configured correctly.'; $string['iliosschool'] = 'Ilios school'; -$string['jobenabled'] = 'Enabled sync job "{$a}".'; $string['jobdeleted'] = 'Deleted sync job "{$a}".'; $string['jobdisabled'] = 'Disabled sync job "{$a}".'; +$string['jobenabled'] = 'Enabled sync job "{$a}".'; $string['newjobcreated'] = 'Created new sync job "{$a}".'; $string['newsyncjob'] = "New sync job"; $string['noassignablecategories'] = 'There are currently no course categories that can be used for assignment.'; diff --git a/settings.php b/settings.php index bcb69f9..6e6616b 100644 --- a/settings.php +++ b/settings.php @@ -1,22 +1,35 @@ . + /** - * Adds this plugin to the admin menu. + * Admin settings. * - * @package tool_ilioscategoryassignment + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -/* @var admin_root $ADMIN */ -/* @var $CFG */ - if ($hassiteconfig) { - $ADMIN->add('root', new admin_category( 'ilioscategoryassignment', get_string('pluginname', 'tool_ilioscategoryassignment'))); - // Sync jobs admin page + // Sync jobs admin page. $ADMIN->add('ilioscategoryassignment', new admin_externalpage( 'ilioscategoryassignment_jobs', get_string('syncjobs', 'tool_ilioscategoryassignment'), @@ -24,7 +37,7 @@ 'moodle/site:config' )); - // New job page + // New job page. $ADMIN->add('ilioscategoryassignment', new admin_externalpage( 'ilioscategoryassignment_new_jobs', get_string('newsyncjob', 'tool_ilioscategoryassignment'), @@ -32,7 +45,7 @@ 'moodle/site:config' )); - // API client settings page + // API client settings page. $settings = new admin_settingpage( 'ilioscategoryassignment_clientconfig', get_string('clientconfig', 'tool_ilioscategoryassignment'), diff --git a/version.php b/version.php index f740378..8ded2e9 100644 --- a/version.php +++ b/version.php @@ -1,15 +1,32 @@ . + /** * Ilios category assignment tool - version file. * - * @package tool_ilioscategoryassignment + * @package tool_ilioscategoryassignment + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024052300; // The current plugin version (Date: YYYYMMDDXX) -$plugin->requires = 2023100400; // Requires this Moodle version -$plugin->component = 'tool_ilioscategoryassignment'; // Full name of the plugin (used for diagnostics) +$plugin->version = 2024052300; // The current plugin version (Date: YYYYMMDDXX). +$plugin->requires = 2023100400; // Requires this Moodle version. +$plugin->component = 'tool_ilioscategoryassignment'; // Full name of the plugin (used for diagnostics). $plugin->release = 'v4.3'; $plugin->supported = [403, 403]; $plugin->maturity = MATURITY_STABLE; From 6b4a54abfa866379ccfd1c09677e3f7c460e9d74 Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Tue, 4 Jun 2024 08:04:22 -0700 Subject: [PATCH 4/4] realigns table name with plugin name. --- classes/manager.php | 10 +++++----- db/install.xml | 2 +- db/upgrade.php | 6 ++++++ version.php | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/classes/manager.php b/classes/manager.php index aaa1f4f..c012e31 100644 --- a/classes/manager.php +++ b/classes/manager.php @@ -127,7 +127,7 @@ public static function set_config($name, $value): void { public static function get_sync_jobs(array $filters = []): array { global $DB; $jobs = []; - $jobrecs = $DB->get_records('tool_ilioscatassignment', $filters); + $jobrecs = $DB->get_records('tool_ilioscategoryassignment', $filters); foreach ($jobrecs as $jobrec) { $jobs[] = new sync_job($jobrec->id, $jobrec->title, $jobrec->roleid, $jobrec->coursecatid, (boolean) $jobrec->enabled, $jobrec->schoolid); @@ -145,7 +145,7 @@ public static function get_sync_jobs(array $filters = []): array { */ public static function disable_job($jobid): void { global $DB; - $tablename = 'tool_ilioscatassignment'; + $tablename = 'tool_ilioscategoryassignment'; $job = $DB->get_record($tablename, ['id' => $jobid]); if (!empty($job)) { $job->enabled = false; @@ -162,7 +162,7 @@ public static function disable_job($jobid): void { */ public static function enable_job($jobid): void { global $DB; - $tablename = 'tool_ilioscatassignment'; + $tablename = 'tool_ilioscategoryassignment'; $job = $DB->get_record($tablename, ['id' => $jobid]); if (!empty($job)) { $job->enabled = true; @@ -186,7 +186,7 @@ public static function create_job(sync_job $job) { $dto->enabled = $job->is_enabled(); $dto->schoolid = $job->get_school_id(); - $jobid = $DB->insert_record('tool_ilioscatassignment', $dto); + $jobid = $DB->insert_record('tool_ilioscategoryassignment', $dto); return self::get_sync_job($jobid); } @@ -207,7 +207,7 @@ public static function delete_job($jobid): void { } // Delete the given job. - $DB->delete_records('tool_ilioscatassignment', ['id' => $jobid]); + $DB->delete_records('tool_ilioscategoryassignment', ['id' => $jobid]); // Remove any course category role assignments that were managed by the given job. $category = core_course_category::get($job->get_course_category_id(), IGNORE_MISSING); diff --git a/db/install.xml b/db/install.xml index 04e6901..2c23795 100644 --- a/db/install.xml +++ b/db/install.xml @@ -4,7 +4,7 @@ xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd" > - +
diff --git a/db/upgrade.php b/db/upgrade.php index 694debc..6ab3189 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -56,5 +56,11 @@ function xmldb_tool_ilioscategoryassignment_upgrade($oldversion): bool { upgrade_plugin_savepoint(true, 2018041100, 'tool', 'ilioscategoryassignment'); } + if ($oldversion < 2024060400) { + $table = new xmldb_table('tool_ilioscatassignment'); + $dbman->rename_table($table, 'tool_ilioscategoryassignment'); + upgrade_plugin_savepoint(true, 2024060400, 'tool', 'ilioscategoryassignment'); + } + return true; } diff --git a/version.php b/version.php index 8ded2e9..0edacd5 100644 --- a/version.php +++ b/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024052300; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2024060400; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2023100400; // Requires this Moodle version. $plugin->component = 'tool_ilioscategoryassignment'; // Full name of the plugin (used for diagnostics). $plugin->release = 'v4.3';