diff --git a/classes/lifecycle/course_table.php b/classes/lifecycle/course_table.php index f835869..4081487 100644 --- a/classes/lifecycle/course_table.php +++ b/classes/lifecycle/course_table.php @@ -20,8 +20,14 @@ require_once($CFG->libdir . '/tablelib.php'); -class course_table extends \table_sql -{ +/** + * Backup course table. + * + * @package tool_lcbackupcoursestep + * @copyright 2024 Catalyst IT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class course_table extends \table_sql { /** * @var array "cached" lang strings @@ -33,13 +39,12 @@ class course_table extends \table_sql * * @throws \coding_exception */ - public function __construct($filterdata = []) - { + public function __construct($filterdata = []) { global $DB; parent::__construct('tool_lcbackupcoursestep-course'); - // Action buttons string + // Action buttons string. $this->strings = [ 'download' => get_string('download'), 'restore' => get_string('restore'), @@ -48,7 +53,7 @@ public function __construct($filterdata = []) // Build the SQL. $fields = 'f.id as id, co.id as courseid, co.shortname as courseshortname, co.fullname as coursefullname, - f.filename as filename, f.filesize as filesize, f.timecreated as createdat'; + f.filename as filename, f.filesize as filesize, f.timecreated as datecreated'; $from = '{files} f JOIN {context} c ON c.id = f.contextid JOIN {course} co ON co.id = c.instanceid'; @@ -85,7 +90,7 @@ public function __construct($filterdata = []) 'coursefullname', 'filename', 'filesize', - 'createdat', + 'datecreated', 'actions', ]); @@ -95,7 +100,7 @@ public function __construct($filterdata = []) get_string('course_fullname_header', 'tool_lcbackupcoursestep'), get_string('filename_header', 'tool_lcbackupcoursestep'), get_string('filesize_header', 'tool_lcbackupcoursestep'), - get_string('createdat_header', 'tool_lcbackupcoursestep'), + get_string('datecreated_header', 'tool_lcbackupcoursestep'), get_string('actions_header', 'tool_lcbackupcoursestep'), ]); @@ -113,8 +118,7 @@ public function __construct($filterdata = []) * @param object $row * @return string */ - public function col_actions($row) - { + public function col_actions($row) { global $OUTPUT; $actionmenu = new \action_menu(); @@ -142,16 +146,17 @@ public function col_actions($row) * @param $row * @return string */ - public function col_createdat($row) - { - return userdate($row->createdat); + public function col_datecreated($row) { + return userdate($row->datecreated); } /** * Display size in user friendly format. + * + * @param $row + * @return string */ - public function col_filesize($row) - { + public function col_filesize($row) { return display_size($row->filesize); } -} \ No newline at end of file +} diff --git a/classes/lifecycle/step.php b/classes/lifecycle/step.php index 7caec28..be3cc07 100644 --- a/classes/lifecycle/step.php +++ b/classes/lifecycle/step.php @@ -16,6 +16,8 @@ namespace tool_lcbackupcoursestep\lifecycle; +defined('MOODLE_INTERNAL') || die(); + global $CFG; require_once($CFG->dirroot . '/admin/tool/lifecycle/step/lib.php'); @@ -28,20 +30,42 @@ use tool_lifecycle\step\instance_setting; use tool_lifecycle\step\libbase; -defined('MOODLE_INTERNAL') || die(); - +/** + * Defines the backup course step. + * + * @package tool_lcbackupcoursestep + * @copyright 2024 Catalyst IT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class step extends libbase { - public function get_subpluginname() - { + /** + * Returns the subplugin name. + * + * @return string + */ + public function get_subpluginname() { return 'tool_lcbackupcoursestep'; } + + /** + * Returns the description. + * + * @return string + */ public function get_plugin_description() { return "Backup course"; } - public function process_course($processid, $instanceid, $course) - { + /** + * Processes the course. + * + * @param int $processid the process id. + * @param int $instanceid step instance id. + * @param object $course the course object. + * @return step_response + */ + public function process_course($processid, $instanceid, $course) { $courseid = $course->id; // Get backup settings. @@ -109,6 +133,11 @@ public function process_course($processid, $instanceid, $course) return step_response::proceed(); } + /** + * Returns the instance settings. + * + * @return array + */ public function instance_settings() { return [ new instance_setting('backup_users', PARAM_BOOL, true), @@ -132,6 +161,11 @@ public function instance_settings() { ]; } + /** + * Adds the instance form definition. + * + * @param \moodleform $mform the form. + */ public function extend_add_instance_form_definition($mform) { // Backup settings. @@ -224,18 +258,18 @@ public function extend_add_instance_form_definition($mform) { $mform->addElement('advcheckbox', 'backup_legacyfiles', get_string('generallegacyfiles', 'backup')); $mform->setType('backup_legacyfiles', PARAM_BOOL); $mform->setDefault('backup_legacyfiles', true); - } - public function get_plugin_settings() - { + /** + * Returns the instance settings. + * + * @return void + */ + public function get_plugin_settings() { global $ADMIN; - // Page to show the list of backed up courses. $ADMIN->add('lifecycle_category', new admin_externalpage('tool_lcbackupcoursestep_courses', get_string('backedupcourses', 'tool_lcbackupcoursestep'), new moodle_url('/admin/tool/lcbackupcoursestep/courses.php'))); - } - } diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 838d5c6..9c3e488 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -21,7 +21,8 @@ /** * Privacy subsystem implementation for tool_samplestep. * - * @package tool_samplestep + * @package tool_lcbackupcoursestep + * @copyright 2024 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class provider implements null_provider { @@ -32,7 +33,7 @@ class provider implements null_provider { * * @return string the reason */ - public static function get_reason() : string { + public static function get_reason(): string { return 'privacy:metadata'; } } diff --git a/courses.php b/courses.php index 891211c..2efe375 100644 --- a/courses.php +++ b/courses.php @@ -17,8 +17,9 @@ /** * Displays backed up courses. * - * @package tool_lcbackupcourselogstep - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package tool_lcbackupcoursestep + * @copyright 2024 Catalyst IT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ use tool_lcbackupcoursestep\lifecycle\course_table; @@ -66,11 +67,11 @@ case 'restore': $context = \context_system::instance(); $restoreurl = new \moodle_url('/backup/restore.php', - array( + [ 'contextid' => $context->id, 'pathnamehash' => $file->get_pathnamehash(), 'contenthash' => $file->get_contenthash(), - ) + ] ); redirect($restoreurl); default: diff --git a/lang/en/tool_lcbackupcoursestep.php b/lang/en/tool_lcbackupcoursestep.php index 9e099d3..d9ec442 100644 --- a/lang/en/tool_lcbackupcoursestep.php +++ b/lang/en/tool_lcbackupcoursestep.php @@ -14,6 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * String definitions for the tool_lcbackupcoursestep plugin. + * + * @package tool_lcbackupcoursestep + * @copyright 2024 Catalyst IT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + $string['pluginname'] = 'Backup course step'; $string['privacy:metadata'] = 'The plugin does not store any personal data.'; $string['backedupcourses'] = 'Backed up courses'; @@ -22,5 +30,5 @@ $string['course_fullname_header'] = 'Course fullname name'; $string['filename_header'] = 'File name'; $string['filesize_header'] = 'File size'; -$string['createdat_header'] = 'Created at'; +$string['datecreated_header'] = 'Created at'; $string['actions_header'] = 'Actions'; diff --git a/tests/step_test.php b/tests/step_test.php index 7070503..0d56787 100644 --- a/tests/step_test.php +++ b/tests/step_test.php @@ -17,10 +17,11 @@ /** * Trigger test for end date delay trigger. * - * @package tool_lcbackupcoursestep - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package tool_lcbackupcoursestep + * @copyright 2024 Catalyst IT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -namespace tool_lcbackupcoursestep\tests; +namespace tool_lcbackupcoursestep; use backup; use restore_controller; @@ -34,8 +35,6 @@ use tool_lifecycle\processor; use tool_lifecycle\settings_type; -defined('MOODLE_INTERNAL') || die(); - /** * Trigger test for start date delay trigger. * @@ -58,9 +57,13 @@ class step_test extends \advanced_testcase { /** @var \stdClass $course Instance of the course under test. */ private $course; + /** @var \stdClass $student Instance of the student user. */ private $student; - public function setUp() : void { + /** + * Set up the test. + */ + public function setUp(): void { global $USER, $DB; // We do not need a sesskey check in these tests. @@ -109,10 +112,10 @@ public function setUp() : void { $this->student = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->enrol_user($this->student->id, $this->course->id); - // Create an assigment in the course + // Create an assigment in the course. $this->getDataGenerator()->create_module('assign', [ 'name' => "Test assign", - 'course' => $this->course->id + 'course' => $this->course->id, ]); // Activate the workflow. @@ -121,6 +124,7 @@ public function setUp() : void { /** * Test course is backed up. + * @covers \tool_lcbackupcoursestep\lifecycle\step::process_course */ public function test_backup_course_step() { global $DB, $CFG; @@ -146,7 +150,7 @@ public function test_backup_course_step() { 'component' => 'tool_lcbackupcoursestep', 'filearea' => 'course_backup', 'filepath' => '/', - 'filename' => '.' + 'filename' => '.', ] ); @@ -170,7 +174,7 @@ public function test_backup_course_step() { $path = $CFG->tempdir . DIRECTORY_SEPARATOR . "backup" . DIRECTORY_SEPARATOR . $backupdir; $storedfile->extract_to_pathname(get_file_packer('application/vnd.moodle.backup'), $path); - // Restore course + // Restore course. list($fullname, $shortname) = restore_dbops::calculate_course_names(0, get_string('restoringcourse', 'backup'), get_string('restoringcourseshortname', 'backup')); @@ -197,7 +201,5 @@ public function test_backup_course_step() { // There is an assignment in the course. $this->assertNotEmpty($DB->get_record('assign', ['course' => $courseid])); - } - } diff --git a/version.php b/version.php index 509e04e..b2e2439 100644 --- a/version.php +++ b/version.php @@ -15,10 +15,11 @@ // along with Moodle. If not, see . /** - * Back up course + * Version details. * - * @package core - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package tool_lcbackupcoursestep + * @copyright 2024 Catalyst IT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); @@ -27,8 +28,8 @@ $plugin->requires = 2022041200; $plugin->component = 'tool_lcbackupcoursestep'; -$plugin->dependencies = array( - 'tool_lifecycle' => 2023050201 -); +$plugin->dependencies = [ + 'tool_lifecycle' => 2023050201, +]; $plugin->supported = [401, 405];