From 950d313a86a25c67ac4309e592ae93fc762592c8 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 18 Nov 2014 16:04:47 -0800 Subject: [PATCH] MDL-30937 report_backups: added ability to view backup logs --- pix/t/viewdetails.png | Bin 0 -> 292 bytes pix/t/viewdetails.svg | 15 ++++ report/backups/index.php | 99 +++++++++++++++++++--- report/backups/lang/en/report_backups.php | 6 ++ 4 files changed, 109 insertions(+), 11 deletions(-) create mode 100644 pix/t/viewdetails.png create mode 100644 pix/t/viewdetails.svg diff --git a/pix/t/viewdetails.png b/pix/t/viewdetails.png new file mode 100644 index 0000000000000000000000000000000000000000..cf6824b71613ee4dd8b97849b21837e5a42f2278 GIT binary patch literal 292 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1|-8uW1a&k$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWw1G$2?seLn>}1r8G3nG)^~TSXrSEmf+C9>ku~kaSbZ#7)&e}jwCo1 z7b{(O#cN;|Fp+uE9>x>?J`s1i`}xa+HYM0!2w}`{P;u~WZR9rKJ(0(%S-~GtBkytE z-B@PbLcwE>-&Ceuh~nQgm-B^Zfd%tNMz%i;DZlI7QUn)pvITImu3%J{{ayKY>%@kY lJQo}oTxB#m#2Hv57+%L%6wHlTx)A6i22WQ%mvv4FO#sK4V6^}M literal 0 HcmV?d00001 diff --git a/pix/t/viewdetails.svg b/pix/t/viewdetails.svg new file mode 100644 index 0000000000000..9b3ddba9595fb --- /dev/null +++ b/pix/t/viewdetails.svg @@ -0,0 +1,15 @@ + + + +]> + + + + + diff --git a/report/backups/index.php b/report/backups/index.php index b6950345dd07a..39dadc41fa4d4 100644 --- a/report/backups/index.php +++ b/report/backups/index.php @@ -24,13 +24,95 @@ */ require_once('../../config.php'); -require_once($CFG->libdir.'/adminlib.php'); +require_once($CFG->libdir . '/adminlib.php'); + +// Required for backup::xxx constants. +require_once($CFG->dirroot . '/backup/util/interfaces/checksumable.class.php'); +require_once($CFG->dirroot . '/backup/backup.class.php'); + +$courseid = optional_param('courseid', 0, PARAM_INT); +$page = optional_param('page', 0, PARAM_INT); // This represents which backup we are viewing. // Required for constants in backup_cron_automated_helper require_once($CFG->dirroot.'/backup/util/helper/backup_cron_helper.class.php'); admin_externalpage_setup('reportbackups', '', null, '', array('pagelayout'=>'report')); +$strftimedatetime = get_string('strftimerecent'); +$strerror = get_string('error'); +$strok = get_string('ok'); +$strunfinished = get_string('unfinished'); +$strskipped = get_string('skipped'); +$strwarning = get_string('warning'); +$strnotyetrun = get_string('backupnotyetrun'); + +if ($courseid) { + $course = $DB->get_record('course', array('id' => $courseid), 'id, fullname', MUST_EXIST); + + // Get the automated backups that have been performed for this course. + $params = array('operation' => backup::OPERATION_BACKUP, + 'type' => backup::TYPE_1COURSE, + 'itemid' => $course->id, + 'interactive' => backup::INTERACTIVE_NO); + if ($backups = $DB->get_records('backup_controllers', $params, 'timecreated DESC', + 'id, backupid, status, timecreated', $page, 1)) { + // Get the backup we want to use. + $backup = reset($backups); + + // Get the backup status. + if ($backup->status == backup::STATUS_FINISHED_OK) { + $status = $strok; + $statusclass = 'backup-ok'; // Green. + } else if ($backup->status == backup::STATUS_AWAITING || $backup->status == backup::STATUS_EXECUTING) { + $status = $strunfinished; + $statusclass = 'backup-unfinished'; // Red. + } else { // Else show error. + $status = $strerror; + $statusclass = 'backup-error'; // Red. + } + + $table = new html_table(); + $table->head = array(''); + $table->data = array(); + $statusrow = get_string('status') . ' - ' . html_writer::tag('span', $status, array('class' => $statusclass)); + $table->data[] = array($statusrow); + + // Get the individual logs for this backup. + if ($logs = $DB->get_records('backup_logs', array('backupid' => $backup->backupid), 'timecreated ASC', + 'id, message, timecreated')) { + foreach ($logs as $log) { + $table->data[] = array(userdate($log->timecreated, get_string('strftimetime', 'report_backups')) . + ' - ' . $log->message); + } + } else { + $table->data[] = array(get_string('nologsfound', 'report_backups')); + } + } + + // Set the course name to display. + $coursename = format_string($course->fullname, true, array('context' => context_course::instance($course->id))); + + echo $OUTPUT->header(); + echo $OUTPUT->heading(get_string('backupofcourselogs', 'report_backups', $coursename)); + if (isset($backup)) { + // We put this logic down here as we may be viewing a backup that was performed which there were no logs + // recorded for. We still want to display the pagination so the user can still navigate to other backups, + // and we also display a message so they are aware that the backup happened but there were no logs. + $baseurl = new moodle_url('/report/backups/index.php', array('courseid' => $courseid)); + $numberofbackups = $DB->count_records('backup_controllers', $params); + $pagingbar = new paging_bar($numberofbackups, $page, 1, $baseurl); + + echo $OUTPUT->render($pagingbar); + echo $OUTPUT->heading(get_string('logsofbackupexecutedon', 'report_backups', userdate($backup->timecreated)), 3); + echo html_writer::table($table); + echo $OUTPUT->render($pagingbar); + } else { + echo $OUTPUT->box(get_string('nobackupsfound', 'report_backups'), 'center'); + } + echo $OUTPUT->footer(); + exit(); +} + $table = new html_table; $table->head = array( get_string("course"), @@ -42,17 +124,9 @@ $table->attributes = array('class' => 'generaltable backup-report'); $table->data = array(); -$strftimedatetime = get_string('strftimerecent'); -$strerror = get_string('error'); -$strok = get_string('ok'); -$strunfinished = get_string('unfinished'); -$strskipped = get_string('skipped'); -$strwarning = get_string('warning'); -$strnotyetrun = get_string('backupnotyetrun'); - $select = ', ' . context_helper::get_preload_record_columns_sql('ctx'); $join = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)"; -$sql = "SELECT bc.*, c.fullname $select +$sql = "SELECT bc.*, c.id as courseid, c.fullname $select FROM {backup_courses} bc JOIN {course} c ON c.id = bc.courseid $join"; @@ -86,8 +160,11 @@ $status->attributes = array('class' => $statusclass); // Create the row and add it to the table + $backuprowname = format_string($backuprow->fullname, true, array('context' => context_course::instance($backuprow->courseid))); + $backuplogsurl = new moodle_url('/report/backups/index.php', array('courseid' => $backuprow->courseid)); + $backuplogsicon = new pix_icon('t/viewdetails', get_string('viewlogs', 'report_backups')); $cells = array( - format_string($backuprow->fullname, true, array('context' => context_course::instance($backuprow->courseid))), + $backuprowname . ' ' . $OUTPUT->action_icon($backuplogsurl, $backuplogsicon), userdate($backuprow->laststarttime, $strftimedatetime), '-', userdate($backuprow->lastendtime, $strftimedatetime), diff --git a/report/backups/lang/en/report_backups.php b/report/backups/lang/en/report_backups.php index 25bfccc29156f..3128d3f2dac0e 100644 --- a/report/backups/lang/en/report_backups.php +++ b/report/backups/lang/en/report_backups.php @@ -23,4 +23,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['backupofcourselogs'] = 'Backup logs of {$a}'; +$string['logsofbackupexecutedon'] = 'Logs of the backup executed on {$a}'; +$string['nobackupsfound'] = 'There were no backups found.'; +$string['nologsfound'] = 'There were no logs found for this backup.'; $string['pluginname'] = 'Backups report'; +$string['strftimetime'] = '%I:%M:%S %p'; +$string['viewlogs'] = 'View logs';