Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Nguyen committed Oct 16, 2024
1 parent 96cb0f6 commit a8b9620
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 53 deletions.
37 changes: 21 additions & 16 deletions classes/lifecycle/course_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'),
Expand All @@ -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';
Expand Down Expand Up @@ -85,7 +90,7 @@ public function __construct($filterdata = [])
'coursefullname',
'filename',
'filesize',
'createdat',
'datecreated',
'actions',
]);

Expand All @@ -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'),
]);

Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}
}
58 changes: 46 additions & 12 deletions classes/lifecycle/step.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

namespace tool_lcbackupcoursestep\lifecycle;

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

global $CFG;
require_once($CFG->dirroot . '/admin/tool/lifecycle/step/lib.php');

Expand All @@ -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.
Expand Down Expand Up @@ -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),
Expand All @@ -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.

Expand Down Expand Up @@ -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')));

}

}
5 changes: 3 additions & 2 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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';
}
}
9 changes: 5 additions & 4 deletions courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion lang/en/tool_lcbackupcoursestep.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* 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';
Expand All @@ -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';
26 changes: 14 additions & 12 deletions tests/step_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,8 +35,6 @@
use tool_lifecycle\processor;
use tool_lifecycle\settings_type;

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

/**
* Trigger test for start date delay trigger.
*
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -146,7 +150,7 @@ public function test_backup_course_step() {
'component' => 'tool_lcbackupcoursestep',
'filearea' => 'course_backup',
'filepath' => '/',
'filename' => '.'
'filename' => '.',
]
);

Expand All @@ -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'));

Expand All @@ -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]));

}

}
13 changes: 7 additions & 6 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* 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();
Expand All @@ -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];

0 comments on commit a8b9620

Please sign in to comment.