Skip to content
Snippets Groups Projects
Unverified Commit de9b8e0a authored by Tobias Reischmann's avatar Tobias Reischmann
Browse files

Added a table to store information about course backups

parent ffff7a24
No related branches found
No related tags found
No related merge requests found
......@@ -35,10 +35,18 @@ class backup_manager {
* @return bool tells if the backup was completed successfully.
*/
public static function create_course_backup($courseid) {
global $CFG;
global $CFG, $DB;
try {
$course = get_course($courseid);
$record = new \stdClass();
$record->courseid = $courseid;
$record->fullname = $course->fullname;
$record->shortname = $course->shortname;
$recordid = $DB->insert_record('tool_cleanupcourses_backups', $record, true);
$record->id = $recordid;
// Build filename.
$archivefile = date("Y-m-d") . "-ID-{$courseid}.mbz";
$archivefile = date("Y-m-d") . "-ID-{$recordid}-COURSE-{$courseid}.mbz";
// Path of backup folder.
$path = $CFG->dataroot . '/cleanupcourses_backups';
......@@ -61,6 +69,16 @@ class backup_manager {
}
$bc->destroy();
unset($bc);
// First check if the file was created.
if (!file_exists($path . '/' . $archivefile)) {
return false;
}
$record->backupfile = $archivefile;
$record->backupcreated = time();
$DB->update_record('tool_cleanupcourses_backups', $record, true);
return true;
} catch (\moodle_exception $e) {
debugging('There was a problem during backup!');
......
......@@ -76,5 +76,18 @@
<KEY NAME="stepid_fk" TYPE="foreign" FIELDS="stepid" REFTABLE="tool_cleanupcourses_step" REFFIELDS="id" COMMENT="Foreign key on step table"/>
</KEYS>
</TABLE>
<TABLE NAME="tool_cleanupcourses_backups" COMMENT="Saves the location of course backups and the relevant information of the course.">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="20" NOTNULL="true" SEQUENCE="false" COMMENT="id of the course the backup belongs to"/>
<FIELD NAME="fullname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The fullname of the course"/>
<FIELD NAME="shortname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Shortname of the course"/>
<FIELD NAME="backupfile" TYPE="char" LENGTH="120" NOTNULL="false" SEQUENCE="false" COMMENT="Name of the backup file"/>
<FIELD NAME="backupcreated" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="timestamp the backup was created"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
\ No newline at end of file
......@@ -23,5 +23,5 @@
defined('MOODLE_INTERNAL') || die;
$plugin->version = 2017061902;
$plugin->version = 2017061903;
$plugin->component = 'tool_cleanupcourses';
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment