Moodle

backup_execute() code coudl be refactored for easy maintenance

Details

  • Type: Improvement Improvement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.9, 1.9.1, 1.9.2
  • Fix Version/s: None
  • Component/s: Backup
  • Labels:
    None
  • Affected Branches:
    MOODLE_19_STABLE

Description

I've just had the fun of merging some code in backup/backuplib.php from a development installation into our moodle head. A large part fo the code would benefit from what seems a very simple refactor. I'd do it but deadlines are looming.

I've logged this as major because I think it would tidy up a large part of this key method and make it easier to read and debug.

The code is in the method backup_execute. This method is generally following just a couple of patterns over and over again. Most of it looks like this
if (!defined('BACKUP_SILENTLY')) { echo "<li>".get_string("blocks").'</li>'; }
//Blocks information
if ($status) {
if (!$status = backup_course_blocks($backup_file,$preferences)) {
$errorstr = "An error occurred while backing up course blocks";
backup_add_to_log(time(),$preferences->backup_course,$errorstr,'manual');
if (!defined('BACKUP_SILENTLY')) { notify($errorstr); } else { return false; }
}
}

repeated over and over again. This could easily be abstracted to a method or two and save maybe 500 - 1000 lines of code

Activity

Hide
Petr Škoda (skodak) added a comment -

This is a known problem, I hope the backup/restore will be rewritten in 2.0

Show
Petr Škoda (skodak) added a comment - This is a known problem, I hope the backup/restore will be rewritten in 2.0
Hide
Colin Chambers added a comment -

thanks petr. Sorry for maybe duplicating a bug but it would save a bit of hassle for anyone maintaining the code or merging it like me and dan. I thought ebtter to have two bugs than none at all.

Show
Colin Chambers added a comment - thanks petr. Sorry for maybe duplicating a bug but it would save a bit of hassle for anyone maintaining the code or merging it like me and dan. I thought ebtter to have two bugs than none at all.

People

Dates

  • Created:
    Updated: