Skip to content
Snippets Groups Projects
Commit daffca07 authored by Justus Dieckmann's avatar Justus Dieckmann
Browse files

Add functionality to download course backups

parent 3de9d628
No related branches found
No related tags found
No related merge requests found
...@@ -41,13 +41,14 @@ class course_backups_table extends \table_sql { ...@@ -41,13 +41,14 @@ class course_backups_table extends \table_sql {
} }
public function init() { public function init() {
$this->define_columns(['courseid', 'courseshortname', 'coursefullname', 'backupcreated', 'tools']); $this->define_columns(['courseid', 'courseshortname', 'coursefullname', 'backupcreated', 'download', 'restore']);
$this->define_headers([ $this->define_headers([
get_string('course'), get_string('course'),
get_string('shortnamecourse'), get_string('shortnamecourse'),
get_string('fullnamecourse'), get_string('fullnamecourse'),
get_string('backupcreated', 'tool_lifecycle'), get_string('backupcreated', 'tool_lifecycle'),
get_string('tools', 'tool_lifecycle')]); get_string('download', 'tool_lifecycle'),
get_string('restore', 'tool_lifecycle')]);
$this->setup(); $this->setup();
} }
...@@ -100,11 +101,23 @@ class course_backups_table extends \table_sql { ...@@ -100,11 +101,23 @@ class course_backups_table extends \table_sql {
} }
/** /**
* Render tools column. * Render download column.
* @param $row
* @return string action buttons for downloading a backup.
*/
public function col_download($row) {
return \html_writer::link(
new \moodle_url('/admin/tool/lifecycle/downloadbackup.php', array('backupid' => $row->id)),
get_string('download', 'tool_lifecycle')
);
}
/**
* Render restore column.
* @param $row * @param $row
* @return string action buttons for restoring a course. * @return string action buttons for restoring a course.
*/ */
public function col_tools($row) { public function col_restore($row) {
return \html_writer::link( return \html_writer::link(
new \moodle_url('/admin/tool/lifecycle/restore.php', array('backupid' => $row->id)), new \moodle_url('/admin/tool/lifecycle/restore.php', array('backupid' => $row->id)),
get_string('restore', 'tool_lifecycle') get_string('restore', 'tool_lifecycle')
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Provides download for backup
*
* @package tool_lifecycle
* @copyright 2019 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_login(null, false);
require_capability('moodle/site:config', context_system::instance());
$backupid = required_param('backupid', PARAM_INT);
$backuprecord = $DB->get_record('tool_lifecycle_backups', array('id' => $backupid), '*', MUST_EXIST);
$source = $CFG->dataroot . '/lifecycle_backups/' . $backuprecord->backupfile;
if (!file_exists($source)) {
throw new \moodle_exception('errorbackupfiledoesnotexist', 'tool_lifecycle', $source);
}
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=\"backup-$backuprecord->backupfile\"");
readfile($source);
\ No newline at end of file
...@@ -132,7 +132,8 @@ $string['nocoursestodisplay'] = 'There are currently no courses which require yo ...@@ -132,7 +132,8 @@ $string['nocoursestodisplay'] = 'There are currently no courses which require yo
$string['course_backups_list_header'] = 'Course Backups'; $string['course_backups_list_header'] = 'Course Backups';
$string['backupcreated'] = 'Created at'; $string['backupcreated'] = 'Created at';
$string['restore'] = 'restore'; $string['restore'] = 'Restore';
$string['download'] = 'Download';
$string['workflownotfound'] = 'Workflow with id {$a} could not be found'; $string['workflownotfound'] = 'Workflow with id {$a} could not be found';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment