MDL-20700 coding style cleanup - cvs keywords removed, closign php tag removed, trailing whitespace cleanup

This commit is contained in:
Petr Skoda 2009-11-01 15:39:15 +00:00
parent 49ab5e1950
commit 795b694516
26 changed files with 150 additions and 177 deletions

View file

@ -1,11 +1,11 @@
README $Id$ README
---------- ----------
This directory contains my try to create a backup/recover This directory contains my try to create a backup/recover
admin option to moodle. I don't know when and how it'll be admin option to moodle. I don't know when and how it'll be
finished, but I'going to try it, sure. finished, but I'going to try it, sure.
Some day, if this is fully functional, it could be integrated Some day, if this is fully functional, it could be integrated
into the main Moodle distribution (ask uncle Martin). :-) into the main Moodle distribution (ask uncle Martin). :-)
Code here may not be tested - so there are no guarantees as Code here may not be tested - so there are no guarantees as
@ -14,11 +14,11 @@ Moodle release.
Please, for any comment about this option, do it in Moodle Please, for any comment about this option, do it in Moodle
Developer Forum at: Developer Forum at:
http://moodle.org/mod/forum/view.php?id=55
(searching an "backup" topic)
or you can put tour comments in Moodel Bugs at: http://moodle.org/mod/forum/view.php?id=55
(searching an "backup" topic)
or you can put tour comments in Moodel Bugs at:
http://moodle.org/bugs/bug.php?op=show&bugid=84. http://moodle.org/bugs/bug.php?op=show&bugid=84.
@ -27,7 +27,7 @@ All comments will be welcome. TIA.
To see the general status of the utility, take a look to To see the general status of the utility, take a look to
"STATUS.txt" in this directory. "STATUS.txt" in this directory.
And this is all, I start with it NOW. And this is all, I start with it NOW.
Eloy (stronk7) Eloy (stronk7)
29-04-2003 29-04-2003

View file

@ -1,4 +1,4 @@
STATUS $Id$ STATUS
---------- ----------
This documment shows the current status of the backup/restore option. This documment shows the current status of the backup/restore option.
@ -37,15 +37,15 @@ Backup Details:
x mods info.......................................DONE x mods info.......................................DONE
- User Accounts Info.................................DONE - User Accounts Info.................................DONE
x admins..........................................DONE x admins..........................................DONE
- All..........................................DONE - All..........................................DONE
x course creators.................................DONE x course creators.................................DONE
- All..........................................DONE - All..........................................DONE
x teachers........................................DONE x teachers........................................DONE
- Course.......................................DONE - Course.......................................DONE
- All..........................................DONE - All..........................................DONE
x students........................................DONE x students........................................DONE
- Course.......................................DONE - Course.......................................DONE
- All..........................................DONE - All..........................................DONE
- Logs...............................................DONE - Logs...............................................DONE
- Scales.............................................DONE - Scales.............................................DONE
- Events.(course)....................................DONE - Events.(course)....................................DONE
@ -111,7 +111,7 @@ Backup Details:
- User Files..............................................DONE. - User Files..............................................DONE.
- Copy finished file to browseable dir.......................DONE - Copy finished file to browseable dir.......................DONE
- Delete old entries at backup end...........................DONE - Delete old entries at backup end...........................DONE
- From database...........................................DONE - From database...........................................DONE
- From filesystem.........................................DONE - From filesystem.........................................DONE
- Browse backup files........................................DONE - Browse backup files........................................DONE
- Download backup files......................................DONE - Download backup files......................................DONE
@ -163,15 +163,15 @@ Restore Details:
x teacheras. .....................................DONE x teacheras. .....................................DONE
- None .......................................DONE - None .......................................DONE
- Course.......................................DONE - Course.......................................DONE
- All..........................................DONE - All..........................................DONE
x students........................................DONE x students........................................DONE
- None.........................................DONE - None.........................................DONE
- Course.......................................DONE - Course.......................................DONE
- All..........................................DONE - All..........................................DONE
x creators........................................DONE x creators........................................DONE
- None.........................................DONE - None.........................................DONE
- Course.......................................DONE - Course.......................................DONE
- All..........................................DONE - All..........................................DONE
x admins..........................................DONE x admins..........................................DONE
- None.........................................DONE - None.........................................DONE
- Course.......................................DONE - Course.......................................DONE

View file

@ -1,4 +1,4 @@
<?php //$Id$ <?php
//This script is used to configure and execute the backup proccess. //This script is used to configure and execute the backup proccess.
//Define some globals for all the script //Define some globals for all the script
@ -134,4 +134,3 @@
//Print footer //Print footer
echo $OUTPUT->footer(); echo $OUTPUT->footer();
?>

View file

@ -1,4 +1,4 @@
<?php //$Id$ <?php
//This page prints the backup todo list to see everything //This page prints the backup todo list to see everything
//Check login //Check login

View file

@ -1,7 +1,7 @@
<?php //$Id$ <?php
//This page prints the backup todo list to see everything //This page prints the backup todo list to see everything
//Check login //Check login
require_login(); require_login();
$loginurl = get_login_url(); $loginurl = get_login_url();
@ -39,7 +39,7 @@
if (empty($to)) { if (empty($to)) {
//Start the main table //Start the main table
echo "<table cellpadding=\"5\">"; echo "<table cellpadding=\"5\">";
//Now print the Backup Name tr //Now print the Backup Name tr
echo "<tr>"; echo "<tr>";
echo "<td align=\"right\"><b>"; echo "<td align=\"right\"><b>";
@ -47,11 +47,11 @@
echo "</b></td><td>"; echo "</b></td><td>";
echo $preferences->backup_name; echo $preferences->backup_name;
echo "</td></tr>"; echo "</td></tr>";
//Start the main tr, where all the backup progress is done //Start the main tr, where all the backup progress is done
echo "<tr>"; echo "<tr>";
echo "<td colspan=\"2\">"; echo "<td colspan=\"2\">";
//Start the main ul //Start the main ul
echo "<ul>"; echo "<ul>";
} }
@ -67,7 +67,7 @@
//End the main table //End the main table
echo "</table>"; echo "</table>";
if (!$status) { if (!$status) {
print_error('error', 'error', "$CFG->wwwroot/course/view.php?id=$course->id"); print_error('error', 'error', "$CFG->wwwroot/course/view.php?id=$course->id");
} }
@ -76,7 +76,7 @@
//Print final message //Print final message
echo $OUTPUT->box(get_string("backupfinished")); echo $OUTPUT->box(get_string("backupfinished"));
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = get_context_instance(CONTEXT_COURSE, $course->id);
echo $OUTPUT->continue_button("$CFG->wwwroot/files/index.php?contextid=".$context->id."&filearea=course_backup&itemid=0"); echo $OUTPUT->continue_button("$CFG->wwwroot/files/index.php?contextid=".$context->id."&filearea=course_backup&itemid=0");
} else { } else {
echo $OUTPUT->box(get_string('importdataexported')); echo $OUTPUT->box(get_string('importdataexported'));
if (!empty($preferences->backup_destination)) { if (!empty($preferences->backup_destination)) {

View file

@ -1,4 +1,4 @@
<?php //$Id$ <?php
//This page prints the backup form to select everything //This page prints the backup form to select everything
global $DB; global $DB;

View file

@ -1,7 +1,7 @@
<?php //$Id$ <?php
//This file contains all the code needed to execute scheduled backups //This file contains all the code needed to execute scheduled backups
require_once($CFG->libdir.'/eventslib.php'); require_once($CFG->libdir.'/eventslib.php');
//This function is executed via moodle cron //This function is executed via moodle cron
//It prepares all the info and execute backups as necessary //It prepares all the info and execute backups as necessary
@ -855,5 +855,3 @@ function schedule_backup_course_delete_old_files($preferences,$starttime=0) {
} }
return $status; return $status;
} }
?>

View file

@ -1,4 +1,4 @@
<?php //$Id$ <?php
//This file contains all the function needed in the backup utility //This file contains all the function needed in the backup utility
//except the mod-related funtions that are into every backuplib.php inside //except the mod-related funtions that are into every backuplib.php inside
//every mod directory //every mod directory
@ -950,7 +950,7 @@
function backup_blog($bf, $blogid, $level) { function backup_blog($bf, $blogid, $level) {
global $DB; global $DB;
$blog = $DB->get_record('post', array('module'=>'blog', 'id'=>$blogid)); $blog = $DB->get_record('post', array('module'=>'blog', 'id'=>$blogid));
/// start blog /// start blog
fwrite($bf, start_tag("BLOG",$level,true)); fwrite($bf, start_tag("BLOG",$level,true));
/// blog body /// blog body
@ -989,12 +989,12 @@
/// End BLOG_TAGS tag /// End BLOG_TAGS tag
fwrite ($bf,end_tag("BLOG_TAGS",$level+1,true)); fwrite ($bf,end_tag("BLOG_TAGS",$level+1,true));
} }
} }
/// end blog /// end blog
fwrite($bf, end_tag("BLOG",$level,true)); fwrite($bf, end_tag("BLOG",$level,true));
} }
/** /**
* Prints course's blocks info (table block_instance) * Prints course's blocks info (table block_instance)
@ -1167,7 +1167,7 @@
$status = true; $status = true;
$first_record = true; $first_record = true;
$course=$DB->get_record('course',array('id'=>$preferences->backup_course)); $course=$DB->get_record('course',array('id'=>$preferences->backup_course));
if(!$course) { if(!$course) {
return false; return false;
@ -1245,7 +1245,7 @@
// write completion data if enabled and user data enabled // write completion data if enabled and user data enabled
require_once($CFG->libdir.'/completionlib.php'); require_once($CFG->libdir.'/completionlib.php');
$completion=new completion_info($course); $completion=new completion_info($course);
if($completion->is_enabled($course_module) && if($completion->is_enabled($course_module) &&
backup_userdata_selected($preferences,$moduletype,$course_module->instance)) { backup_userdata_selected($preferences,$moduletype,$course_module->instance)) {
fwrite ($bf,start_tag("COMPLETIONDATA",6,true)); fwrite ($bf,start_tag("COMPLETIONDATA",6,true));
@ -1267,7 +1267,7 @@
// Write availability data if enabled // Write availability data if enabled
require_once($CFG->libdir.'/conditionlib.php'); require_once($CFG->libdir.'/conditionlib.php');
if(!empty($CFG->enableavailability)) { if(!empty($CFG->enableavailability)) {
fwrite ($bf,start_tag("AVAILABILITYDATA",6,true)); fwrite ($bf,start_tag("AVAILABILITYDATA",6,true));
// Get all availability restrictions for this activity // Get all availability restrictions for this activity
$data=$DB->get_records('course_modules_availability', $data=$DB->get_records('course_modules_availability',
@ -1281,7 +1281,7 @@
fwrite ($bf,full_tag("GRADEITEMID",8,false,$availability->gradeitemid)); fwrite ($bf,full_tag("GRADEITEMID",8,false,$availability->gradeitemid));
fwrite ($bf,full_tag("GRADEMIN",8,false,$availability->grademin)); fwrite ($bf,full_tag("GRADEMIN",8,false,$availability->grademin));
fwrite ($bf,full_tag("GRADEMAX",8,false,$availability->grademax)); fwrite ($bf,full_tag("GRADEMAX",8,false,$availability->grademax));
fwrite ($bf,end_tag("AVAILABILITY",7,true)); fwrite ($bf,end_tag("AVAILABILITY",7,true));
} }
fwrite ($bf,end_tag("AVAILABILITYDATA",6,true)); fwrite ($bf,end_tag("AVAILABILITYDATA",6,true));
} }
@ -1299,7 +1299,7 @@
return $status; return $status;
} }
//Print users to xml //Print users to xml
//Only users previously calculated in backup_ids will output //Only users previously calculated in backup_ids will output
// //
@ -3583,5 +3583,3 @@
$preferences->backup_version = $CFG->backup_version; $preferences->backup_version = $CFG->backup_version;
$preferences->backup_release = $CFG->backup_release; $preferences->backup_release = $CFG->backup_release;
} }
?>

View file

@ -2,24 +2,24 @@ Ziba Scott <ziba@linuxbox.com> 06/23/05
This is a utility to convert Blackboard Course export zip files into This is a utility to convert Blackboard Course export zip files into
Moodle course export zip files. It has been successfully tested with Moodle course export zip files. It has been successfully tested with
Blackboard 5.5 and Moodle 1.4.1 and Moodle CVS. There is minimal Blackboard 5.5 and Moodle 1.4.1 and Moodle CVS. There is minimal
Blackboard 6 support. It will convert: Blackboard 6 support. It will convert:
* Course Name/Title * Course Name/Title
* Forum Topics * Forum Topics
* Course Documents * Course Documents
* Assignments * Assignments
* External Links * External Links
AUTOMATED OPERATION: AUTOMATED OPERATION:
REQUIREMENTS FOR WEB INTERFACE: REQUIREMENTS FOR WEB INTERFACE:
*Moodle 1.4.1 or greater *Moodle 1.4.1 or greater
*PHP 4.3 compiled with --enable-xslt --with-xslt-sablot options *PHP 4.3 compiled with --enable-xslt --with-xslt-sablot options
(Check php.net for instructions on enabling xslt for your platform) (Check php.net for instructions on enabling xslt for your platform)
*Alternatively, PHP 5 compiled with xml and xsl support (-with-xsl) *Alternatively, PHP 5 compiled with xml and xsl support (-with-xsl)
INSTALLATION: INSTALLATION:
*Unpack this file into the "backup" directory *Unpack this file into the "backup" directory
@ -28,7 +28,7 @@ AUTOMATED OPERATION:
MANUAL OPERATION: MANUAL OPERATION:
REQUIREMENTS: REQUIREMENTS:
*An XSLT 1.0 processor (like Sablotron) *An XSLT 1.0 processor (like Sablotron)
*A zipping utility *A zipping utility
@ -39,23 +39,23 @@ MANUAL OPERATION:
*PHP 5 compiled with -with-xsl and the default xml support left in. *PHP 5 compiled with -with-xsl and the default xml support left in.
*Apache with write access to /tmp *Apache with write access to /tmp
*A commandline zipping utility *A commandline zipping utility
COMMAND LINE INSTRUCTIONS: COMMAND LINE INSTRUCTIONS:
1) Download and uncompress the Blackboard export into a directory. 1) Download and uncompress the Blackboard export into a directory.
2) Copy bb2moodle.xslt into the Blackboard course directory. 2) Copy bb2moodle.xslt into the Blackboard course directory.
3) Run your XSLT processor on imsmanifest.xml with bb2moodle.xslt 3) Run your XSLT processor on imsmanifest.xml with bb2moodle.xslt
as the input and moodle.xml as the output. If you are using as the input and moodle.xml as the output. If you are using
Sablotron on linux, this command will look like this: Sablotron on linux, this command will look like this:
sabcmd bb2moodle.xslt imsmanifest.xml > moodle.xml sabcmd bb2moodle.xslt imsmanifest.xml > moodle.xml
4) Create a moodle zip file with this structure: 4) Create a moodle zip file with this structure:
moodle.xml moodle.xml
user_files/ user_files/
course_files/ course_files/
5) Copy every subdirectory and its contents from the Blackboard 5) Copy every subdirectory and its contents from the Blackboard
export directory into the course_files directory. This does export directory into the course_files directory. This does
not include the Blackboard XML files, only the course not include the Blackboard XML files, only the course

View file

@ -1,4 +1,4 @@
<?php // $Id$ <?php
// This file facilitates the conversion of a Blackboard course export // This file facilitates the conversion of a Blackboard course export
// into a Moodle course export. It assumes an unzipped directory and makes in-place alterations. // into a Moodle course export. It assumes an unzipped directory and makes in-place alterations.
@ -6,7 +6,7 @@ defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
// Ziba Scott <ziba@linuxbox.com> 10-25-04 // Ziba Scott <ziba@linuxbox.com> 10-25-04
require_once($CFG->dirroot.'/backup/bb/xsl_emulate_xslt.inc'); require_once($CFG->dirroot.'/backup/bb/xsl_emulate_xslt.inc');
function get_subdirs($directory){ function get_subdirs($directory){
$opendirectory = opendir( $directory ); $opendirectory = opendir( $directory );
while(false !== ($filename = readdir($opendirectory))) { while(false !== ($filename = readdir($opendirectory))) {
@ -62,7 +62,7 @@ function blackboard_convert($dir){
// Process the Blackboard XML files with the chosen XSL file. // Process the Blackboard XML files with the chosen XSL file.
// The imsmanifest contains all the XML files and their relationships. // The imsmanifest contains all the XML files and their relationships.
// The XSL processor will open them as needed. // The XSL processor will open them as needed.
$xsltproc = xslt_create(); $xsltproc = xslt_create();
if (!xslt_process($xsltproc, 'imsmanifest.xml', "$dir/$xslt_file", "$dir/moodle.xml")) { if (!xslt_process($xsltproc, 'imsmanifest.xml', "$dir/$xslt_file", "$dir/moodle.xml")) {
@ -95,7 +95,7 @@ function blackboard_convert($dir){
* then checks to see if the name is a hex - if so, it translates/renames correctly. * then checks to see if the name is a hex - if so, it translates/renames correctly.
* *
* @param string $subdir - the directory to parse. * @param string $subdir - the directory to parse.
* *
*/ */
function rename_hexfiles($subdir) { function rename_hexfiles($subdir) {
//this bit of code grabs all files in the directory, and if they start with ! or @, performs the name conversion //this bit of code grabs all files in the directory, and if they start with ! or @, performs the name conversion
@ -120,4 +120,3 @@ function rename_hexfiles($subdir) {
closedir($handle); closedir($handle);
} }
} }
?>

View file

@ -711,4 +711,3 @@ class cc2moodle {
return $code; return $code;
} }
} }
?>

View file

@ -267,4 +267,3 @@ class entities {
return $text; return $text;
} }
} }
?>

View file

@ -125,4 +125,3 @@ class forum extends entities {
return ''; return '';
} }
} }
?>

View file

@ -56,4 +56,3 @@ class label extends entities {
return str_replace($find_tags, $replace_values, $sheet_mod_label); return str_replace($find_tags, $replace_values, $sheet_mod_label);
} }
} }
?>

View file

@ -955,4 +955,3 @@ class quiz extends entities {
} }
} }
?>

View file

@ -101,4 +101,3 @@ class resource extends entities {
return str_replace($find_tags, $replace_values, $sheet_mod_resource); return str_replace($find_tags, $replace_values, $sheet_mod_resource);
} }
} }
?>

View file

@ -139,4 +139,3 @@ function detect_cc_format ($xml_file) {
} }
} }
?>

View file

@ -1,4 +1,4 @@
<?php //$Id$ <?php
//This file contains all the general function needed (file manipulation...) //This file contains all the general function needed (file manipulation...)
//not directly part of the backup/restore utility plus some constants //not directly part of the backup/restore utility plus some constants
@ -289,7 +289,7 @@
if (!is_dir($to_file)) { if (!is_dir($to_file)) {
//echo "<br />Creating ".$to_file; //Debug //echo "<br />Creating ".$to_file; //Debug
umask(0000); umask(0000);
$status = mkdir($to_file,$CFG->directorypermissions); $status = mkdir($to_file,$CFG->directorypermissions);
} }
$dir = opendir($from_file); $dir = opendir($from_file);
while (false !== ($file=readdir($dir))) { while (false !== ($file=readdir($dir))) {
@ -387,7 +387,7 @@
$status = true; $status = true;
$status2 = true; $status2 = true;
$status = $DB->get_record("backup_ids", array("backup_code"=>$backup_unique_code, $status = $DB->get_record("backup_ids", array("backup_code"=>$backup_unique_code,
"table_name"=>$table, "old_id"=>$old_id)); "table_name"=>$table, "old_id"=>$old_id));
//If info field = "infile", get file contents //If info field = "infile", get file contents
@ -404,8 +404,8 @@
} else { } else {
//Only if status (record exists) //Only if status (record exists)
if (!empty($status->info)) { if (!empty($status->info)) {
if ($status->info === 'needed') { if ($status->info === 'needed') {
// TODO: ugly hack - fix before 1.9.1 // TODO: ugly hack - fix before 1.9.1
debugging('Incorrect string "needed" in $status->info, please fix the code (table:'.$table.'; old_id:'.$old_id.').', DEBUG_DEVELOPER); debugging('Incorrect string "needed" in $status->info, please fix the code (table:'.$table.'; old_id:'.$old_id.').', DEBUG_DEVELOPER);
} else { } else {
////First strip slashes ////First strip slashes
@ -753,7 +753,7 @@
backup_add_static_preferences($preferences); backup_add_static_preferences($preferences);
return $preferences; return $preferences;
} }
function add_to_backup_log($starttime,$courseid,$message, $backuptype) { function add_to_backup_log($starttime,$courseid,$message, $backuptype) {
global $DB; global $DB;
$log = new object(); $log = new object();
$log->courseid = $courseid; $log->courseid = $courseid;
@ -764,5 +764,3 @@
$DB->insert_record('backup_log', $log); $DB->insert_record('backup_log', $log);
} }
?>

View file

@ -1,4 +1,4 @@
<?php // $Id$ <?php
// log.php - old scheduled backups report. Now redirecting // log.php - old scheduled backups report. Now redirecting
// to the new admin one // to the new admin one
@ -9,5 +9,3 @@
require_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM)); require_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM));
redirect("$CFG->wwwroot/$CFG->admin/report/backups/index.php", '', 'admin', 1); redirect("$CFG->wwwroot/$CFG->admin/report/backups/index.php", '', 'admin', 1);
?>

View file

@ -1,4 +1,4 @@
<?php //$Id$ <?php
//This script is used to configure and execute the restore proccess. //This script is used to configure and execute the restore proccess.
//Define some globals for all the script //Define some globals for all the script
@ -186,5 +186,3 @@
//Print footer //Print footer
echo $OUTPUT->footer(); echo $OUTPUT->footer();
?>

View file

@ -1,4 +1,4 @@
<?php //$Id$ <?php
//This page receive all the restore_form data. Then, if existing course //This page receive all the restore_form data. Then, if existing course
//has been selected, shows a list of courses to select one. //has been selected, shows a list of courses to select one.
@ -56,7 +56,7 @@
// check for session objects // check for session objects
if (empty($info) or empty($course_header)) { if (empty($info) or empty($course_header)) {
print_error('sessionmissing', 'debug', '', print_error('sessionmissing', 'debug', '',
'info and course_header'); 'info and course_header');
} }
@ -375,4 +375,3 @@
print_error('error'); print_error('error');
} }
?>

View file

@ -1,4 +1,4 @@
<?php //$Id$ <?php
//This page receives the required info and executes the restore //This page receives the required info and executes the restore
//with the parameters suplied. Whe finished, delete temporary //with the parameters suplied. Whe finished, delete temporary
//data from backup_tables and temp directory //data from backup_tables and temp directory
@ -47,7 +47,7 @@
if (empty($to)) { if (empty($to)) {
print_error("cannotuseadminadminorteacher", '', $loginurl); print_error("cannotuseadminadminorteacher", '', $loginurl);
} else { } else {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to)) if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))
&& !has_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $to))) { && !has_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $to))) {
print_error("cannotuseadminadminorteacher", '', $loginurl); print_error("cannotuseadminadminorteacher", '', $loginurl);
} }
@ -74,8 +74,8 @@
echo $OUTPUT->box(get_string("restorefinished")); echo $OUTPUT->box(get_string("restorefinished"));
} else { } else {
echo $OUTPUT->box(get_string("importdatafinished")); echo $OUTPUT->box(get_string("importdatafinished"));
$file = $CFG->dataroot . '/' $file = $CFG->dataroot . '/'
. $SESSION->import_preferences->backup_course . $SESSION->import_preferences->backup_course
. '/backupdata/' . $SESSION->import_preferences->backup_name; . '/backupdata/' . $SESSION->import_preferences->backup_name;
if (is_readable($file)) { if (is_readable($file)) {
unlink($file); unlink($file);
@ -86,5 +86,3 @@
unset($SESSION->restore); unset($SESSION->restore);
} }
echo $OUTPUT->continue_button("$CFG->wwwroot/course/view.php?id=".$restore->course_id); echo $OUTPUT->continue_button("$CFG->wwwroot/course/view.php?id=".$restore->course_id);
?>

View file

@ -1,4 +1,4 @@
<?php //$Id$ <?php
//This page prints the restore form to select everything yo want //This page prints the restore form to select everything yo want
//to restore. Form is dinamically buid, depending of "info" object //to restore. Form is dinamically buid, depending of "info" object
//that contains the backup contents and depending of every mod //that contains the backup contents and depending of every mod
@ -796,4 +796,3 @@ function restore_is_samerole($testroleid, $rolefromxml) {
} }
return true; return true;
} }
?>

View file

@ -1,15 +1,15 @@
<?php // $Id$ <?php
//This page copies th zip to the temp directory, //This page copies th zip to the temp directory,
//unzip it, check that it is a valid backup file //unzip it, check that it is a valid backup file
//inform about its contents and fill all the necesary //inform about its contents and fill all the necesary
//variables to continue with the restore. //variables to continue with the restore.
//Checks we have the file variable //Checks we have the file variable
if (!isset($file)) { if (!isset($file)) {
print_error('nofile'); print_error('nofile');
} }
//Check login //Check login
require_login(); require_login();
$loginurl = get_login_url(); $loginurl = get_login_url();
@ -40,9 +40,7 @@
define('RESTORE_SILENTLY',true); define('RESTORE_SILENTLY',true);
} }
$status = restore_precheck($id,$file,$errorstr); $status = restore_precheck($id,$file,$errorstr);
if (!$status) { if (!$status) {
print_error("pleasereport"); print_error("pleasereport");
} }
?>

View file

@ -1,4 +1,4 @@
<?php //$Id$ <?php
//Functions used in restore //Functions used in restore
require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->libdir.'/gradelib.php');
@ -229,20 +229,20 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
} }
// For each block, call its encode_content_links method // For each block, call its encode_content_links method
static $blockobjects = null; static $blockobjects = null;
if (!isset($blockobjects)) { if (!isset($blockobjects)) {
$blockobjects = array(); $blockobjects = array();
if ($blocks = $DB->get_records('block', array('visible'=>1))) { if ($blocks = $DB->get_records('block', array('visible'=>1))) {
foreach ($blocks as $block) { foreach ($blocks as $block) {
if ($blockobject = block_instance($block->name)) { if ($blockobject = block_instance($block->name)) {
$blockobjects[] = $blockobject; $blockobjects[] = $blockobject;
} }
} }
} }
} }
foreach ($blockobjects as $blockobject) { foreach ($blockobjects as $blockobject) {
$content = $blockobject->decode_content_links($content,$restore); $content = $blockobject->decode_content_links($content,$restore);
} }
return $content; return $content;
@ -984,7 +984,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
// This will only be set if we come from 1.7 and above backups // This will only be set if we come from 1.7 and above backups
// Also, must do this before insert ($DB->insert_record unsets id) // Also, must do this before insert ($DB->insert_record unsets id)
if (!empty($instance->id)) { if (!empty($instance->id)) {
$oldid = $instance->id; $oldid = $instance->id;
} else { } else {
$oldid = 0; $oldid = 0;
@ -1233,7 +1233,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
} }
foreach($info->completiondata as $data) { foreach($info->completiondata as $data) {
// Convert cmid // Convert cmid
$newcmid=backup_getid($restore->backup_unique_code, 'course_modules', $data->coursemoduleid); $newcmid=backup_getid($restore->backup_unique_code, 'course_modules', $data->coursemoduleid);
if($newcmid) { if($newcmid) {
$data->coursemoduleid=$newcmid->new_id; $data->coursemoduleid=$newcmid->new_id;
@ -1273,7 +1273,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
if($status && !empty($info->availabilitydata) && count($info->availabilitydata)>0) { if($status && !empty($info->availabilitydata) && count($info->availabilitydata)>0) {
foreach($info->availabilitydata as $data) { foreach($info->availabilitydata as $data) {
// Convert cmid // Convert cmid
$newcmid=backup_getid($restore->backup_unique_code, 'course_modules', $data->coursemoduleid); $newcmid=backup_getid($restore->backup_unique_code, 'course_modules', $data->coursemoduleid);
if($newcmid) { if($newcmid) {
$data->coursemoduleid=$newcmid->new_id; $data->coursemoduleid=$newcmid->new_id;
@ -1284,7 +1284,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
continue; continue;
} }
// Convert source cmid // Convert source cmid
if($data->sourcecmid) { if($data->sourcecmid) {
$newcmid=backup_getid($restore->backup_unique_code, 'course_modules', $data->sourcecmid); $newcmid=backup_getid($restore->backup_unique_code, 'course_modules', $data->sourcecmid);
if($newcmid) { if($newcmid) {
@ -1980,7 +1980,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$oldoutcome = backup_todb($info['GRADE_ITEM']['#']['OUTCOMEID']['0']['#']); $oldoutcome = backup_todb($info['GRADE_ITEM']['#']['OUTCOMEID']['0']['#']);
if (empty($outcomes[$oldoutcome])) { if (empty($outcomes[$oldoutcome])) {
continue; // error! continue; // error!
} }
if (empty($outcomes[$oldoutcome]->id)) { if (empty($outcomes[$oldoutcome]->id)) {
$outcomes[$oldoutcome]->insert('restore'); $outcomes[$oldoutcome]->insert('restore');
$outcomes[$oldoutcome]->use_in($restore->course_id); $outcomes[$oldoutcome]->use_in($restore->course_id);
@ -2083,7 +2083,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
if ($status and !$importing and $restore_histories) { if ($status and !$importing and $restore_histories) {
/// following code is very inefficient /// following code is very inefficient
$gchcount = $DB->count_records('backup_ids', array('backup_code'=>$restore->backup_unique_code, 'table_name'=>'grade_categories_history')); $gchcount = $DB->count_records('backup_ids', array('backup_code'=>$restore->backup_unique_code, 'table_name'=>'grade_categories_history'));
$gghcount = $DB->count_records('backup_ids', array('backup_code'=>$restore->backup_unique_code, 'table_name'=>'grade_grades_history')); $gghcount = $DB->count_records('backup_ids', array('backup_code'=>$restore->backup_unique_code, 'table_name'=>'grade_grades_history'));
@ -2116,7 +2116,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//traverse_xmlize($info); //Debug //traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug //print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug //$GLOBALS['traverse_array']=""; //Debug
$oldobj = backup_getid($restore->backup_unique_code,"grade_categories", backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['OLDID']['0']['#'])); $oldobj = backup_getid($restore->backup_unique_code,"grade_categories", backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['OLDID']['0']['#']));
if (empty($oldobj->new_id)) { if (empty($oldobj->new_id)) {
// if the old object is not being restored, can't restoring its history // if the old object is not being restored, can't restoring its history
@ -2127,12 +2127,12 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$dbrec->action = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['ACTION']['0']['#']); $dbrec->action = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['ACTION']['0']['#']);
$dbrec->source = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['SOURCE']['0']['#']); $dbrec->source = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['SOURCE']['0']['#']);
$dbrec->timemodified = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['TIMEMODIFIED']['0']['#']); $dbrec->timemodified = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['TIMEMODIFIED']['0']['#']);
// loggeduser might not be restored, e.g. admin // loggeduser might not be restored, e.g. admin
if ($oldobj = backup_getid($restore->backup_unique_code,"user", backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['LOGGEDUSER']['0']['#']))) { if ($oldobj = backup_getid($restore->backup_unique_code,"user", backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['LOGGEDUSER']['0']['#']))) {
$dbrec->loggeduser = $oldobj->new_id; $dbrec->loggeduser = $oldobj->new_id;
} }
// this item might not have a parent at all, do not skip it if no parent is specified // this item might not have a parent at all, do not skip it if no parent is specified
if (backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['PARENT']['0']['#'])) { if (backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['PARENT']['0']['#'])) {
$oldobj = backup_getid($restore->backup_unique_code,"grade_categories", backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['PARENT']['0']['#'])); $oldobj = backup_getid($restore->backup_unique_code,"grade_categories", backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['PARENT']['0']['#']));
@ -2164,15 +2164,15 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$dbrec->aggregation = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['AGGRETGATION']['0']['#']); $dbrec->aggregation = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['AGGRETGATION']['0']['#']);
$dbrec->keephigh = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['KEEPHIGH']['0']['#']); $dbrec->keephigh = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['KEEPHIGH']['0']['#']);
$dbrec->droplow = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['DROPLOW']['0']['#']); $dbrec->droplow = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['DROPLOW']['0']['#']);
$dbrec->aggregateonlygraded = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['AGGREGATEONLYGRADED']['0']['#']); $dbrec->aggregateonlygraded = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['AGGREGATEONLYGRADED']['0']['#']);
$dbrec->aggregateoutcomes = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['AGGREGATEOUTCOMES']['0']['#']); $dbrec->aggregateoutcomes = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['AGGREGATEOUTCOMES']['0']['#']);
$dbrec->aggregatesubcats = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['AGGREGATESUBCATS']['0']['#']); $dbrec->aggregatesubcats = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['AGGREGATESUBCATS']['0']['#']);
$dbrec->courseid = $restore->course_id; $dbrec->courseid = $restore->course_id;
$DB->insert_record('grade_categories_history', $dbrec); $DB->insert_record('grade_categories_history', $dbrec);
unset($dbrec); unset($dbrec);
} }
//Increment counters //Increment counters
$counter++; $counter++;
@ -2190,7 +2190,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
} }
} }
} }
// process histories // process histories
if ($gghcount && $status) { if ($gghcount && $status) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
@ -2214,7 +2214,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//traverse_xmlize($info); //Debug //traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug //print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug //$GLOBALS['traverse_array']=""; //Debug
$oldobj = backup_getid($restore->backup_unique_code,"grade_grades", backup_todb($info['GRADE_GRADES_HISTORY']['#']['OLDID']['0']['#'])); $oldobj = backup_getid($restore->backup_unique_code,"grade_grades", backup_todb($info['GRADE_GRADES_HISTORY']['#']['OLDID']['0']['#']));
if (empty($oldobj->new_id)) { if (empty($oldobj->new_id)) {
// if the old object is not being restored, can't restoring its history // if the old object is not being restored, can't restoring its history
@ -2228,7 +2228,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
if ($oldobj = backup_getid($restore->backup_unique_code,"user", backup_todb($info['GRADE_GRADES_HISTORY']['#']['LOGGEDUSER']['0']['#']))) { if ($oldobj = backup_getid($restore->backup_unique_code,"user", backup_todb($info['GRADE_GRADES_HISTORY']['#']['LOGGEDUSER']['0']['#']))) {
$dbrec->loggeduser = $oldobj->new_id; $dbrec->loggeduser = $oldobj->new_id;
} }
$oldobj = backup_getid($restore->backup_unique_code,"grade_items", backup_todb($info['GRADE_GRADES_HISTORY']['#']['ITEMID']['0']['#'])); $oldobj = backup_getid($restore->backup_unique_code,"grade_items", backup_todb($info['GRADE_GRADES_HISTORY']['#']['ITEMID']['0']['#']));
$dbrec->itemid = $oldobj->new_id; $dbrec->itemid = $oldobj->new_id;
if (empty($dbrec->itemid)) { if (empty($dbrec->itemid)) {
@ -2243,12 +2243,12 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
if ($oldobj = backup_getid($restore->backup_unique_code,"user", backup_todb($info['GRADE_GRADES_HISTORY']['#']['USERMODIFIED']['0']['#']))) { if ($oldobj = backup_getid($restore->backup_unique_code,"user", backup_todb($info['GRADE_GRADES_HISTORY']['#']['USERMODIFIED']['0']['#']))) {
$dbrec->usermodified = $oldobj->new_id; $dbrec->usermodified = $oldobj->new_id;
} }
if (backup_todb($info['GRADE_GRADES_HISTORY']['#']['RAWSCALEID']['0']['#'])) { if (backup_todb($info['GRADE_GRADES_HISTORY']['#']['RAWSCALEID']['0']['#'])) {
$scale = backup_getid($restore->backup_unique_code,"scale",backup_todb($info['GRADE_GRADES_HISTORY']['#']['RAWSCALEID']['0']['#'])); $scale = backup_getid($restore->backup_unique_code,"scale",backup_todb($info['GRADE_GRADES_HISTORY']['#']['RAWSCALEID']['0']['#']));
$dbrec->rawscaleid = $scale->new_id; $dbrec->rawscaleid = $scale->new_id;
} }
$dbrec->finalgrade = backup_todb($info['GRADE_GRADES_HISTORY']['#']['FINALGRADE']['0']['#']); $dbrec->finalgrade = backup_todb($info['GRADE_GRADES_HISTORY']['#']['FINALGRADE']['0']['#']);
$dbrec->hidden = backup_todb($info['GRADE_GRADES_HISTORY']['#']['HIDDEN']['0']['#']); $dbrec->hidden = backup_todb($info['GRADE_GRADES_HISTORY']['#']['HIDDEN']['0']['#']);
$dbrec->locked = backup_todb($info['GRADE_GRADES_HISTORY']['#']['LOCKED']['0']['#']); $dbrec->locked = backup_todb($info['GRADE_GRADES_HISTORY']['#']['LOCKED']['0']['#']);
@ -2260,10 +2260,10 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$dbrec->feedbackformat = backup_todb($info['GRADE_TEXT_HISTORY']['#']['FEEDBACKFORMAT']['0']['#']); $dbrec->feedbackformat = backup_todb($info['GRADE_TEXT_HISTORY']['#']['FEEDBACKFORMAT']['0']['#']);
$dbrec->information = backup_todb($info['GRADE_TEXT_HISTORY']['#']['INFORMATION']['0']['#']); $dbrec->information = backup_todb($info['GRADE_TEXT_HISTORY']['#']['INFORMATION']['0']['#']);
$dbrec->informationformat = backup_todb($info['GRADE_TEXT_HISTORY']['#']['INFORMATIONFORMAT']['0']['#']); $dbrec->informationformat = backup_todb($info['GRADE_TEXT_HISTORY']['#']['INFORMATIONFORMAT']['0']['#']);
$DB->insert_record('grade_grades_history', $dbrec); $DB->insert_record('grade_grades_history', $dbrec);
unset($dbrec); unset($dbrec);
} }
//Increment counters //Increment counters
$counter++; $counter++;
@ -2281,9 +2281,9 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
} }
} }
} }
// process histories // process histories
if ($gihcount && $status) { if ($gihcount && $status) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<li>'.get_string('gradeitemshistory','grades').'</li>'; echo '<li>'.get_string('gradeitemshistory','grades').'</li>';
@ -2306,8 +2306,8 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//traverse_xmlize($info); //Debug //traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug //print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug //$GLOBALS['traverse_array']=""; //Debug
$oldobj = backup_getid($restore->backup_unique_code,"grade_items", backup_todb($info['GRADE_ITEM_HISTORY']['#']['OLDID']['0']['#'])); $oldobj = backup_getid($restore->backup_unique_code,"grade_items", backup_todb($info['GRADE_ITEM_HISTORY']['#']['OLDID']['0']['#']));
if (empty($oldobj->new_id)) { if (empty($oldobj->new_id)) {
// if the old object is not being restored, can't restoring its history // if the old object is not being restored, can't restoring its history
@ -2328,31 +2328,31 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$counter++; $counter++;
continue; // category not restored continue; // category not restored
} }
$dbrec->itemname= backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMNAME']['0']['#']); $dbrec->itemname= backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMNAME']['0']['#']);
$dbrec->itemtype = backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMTYPE']['0']['#']); $dbrec->itemtype = backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMTYPE']['0']['#']);
$dbrec->itemmodule = backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMMODULE']['0']['#']); $dbrec->itemmodule = backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMMODULE']['0']['#']);
// code from grade_items restore // code from grade_items restore
$iteminstance = backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMINSTANCE']['0']['#']); $iteminstance = backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMINSTANCE']['0']['#']);
// do not restore if this grade_item is a mod, and // do not restore if this grade_item is a mod, and
if ($dbrec->itemtype == 'mod') { if ($dbrec->itemtype == 'mod') {
if (!restore_userdata_selected($restore, $dbrec->itemmodule, $iteminstance)) { if (!restore_userdata_selected($restore, $dbrec->itemmodule, $iteminstance)) {
// module instance not selected when restored using granular // module instance not selected when restored using granular
// skip this item // skip this item
$counter++; $counter++;
continue; continue;
} }
// iteminstance should point to new mod // iteminstance should point to new mod
$mod = backup_getid($restore->backup_unique_code,$dbrec->itemmodule, $iteminstance); $mod = backup_getid($restore->backup_unique_code,$dbrec->itemmodule, $iteminstance);
$dbrec->iteminstance = $mod->new_id; $dbrec->iteminstance = $mod->new_id;
} else if ($dbrec->itemtype == 'category') { } else if ($dbrec->itemtype == 'category') {
// the item instance should point to the new grade category // the item instance should point to the new grade category
// only proceed if we are restoring all grade items // only proceed if we are restoring all grade items
if ($restoreall) { if ($restoreall) {
$category = backup_getid($restore->backup_unique_code,'grade_categories', $iteminstance); $category = backup_getid($restore->backup_unique_code,'grade_categories', $iteminstance);
@ -2367,16 +2367,16 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
// TODO any special code needed here to restore course item without duplicating it? // TODO any special code needed here to restore course item without duplicating it?
// find the course category with depth 1, and course id = current course id // find the course category with depth 1, and course id = current course id
// this would have been already restored // this would have been already restored
$cat = $DB->get_record('grade_categories', array('depth'=>1, 'courseid'=>$restore->course_id)); $cat = $DB->get_record('grade_categories', array('depth'=>1, 'courseid'=>$restore->course_id));
$dbrec->iteminstance = $cat->id; $dbrec->iteminstance = $cat->id;
} else { } else {
$counter++; $counter++;
continue; continue;
} }
} }
$dbrec->itemnumber = backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMNUMBER']['0']['#']); $dbrec->itemnumber = backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMNUMBER']['0']['#']);
$dbrec->iteminfo = backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMINFO']['0']['#']); $dbrec->iteminfo = backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMINFO']['0']['#']);
$dbrec->idnumber = backup_todb($info['GRADE_ITEM_HISTORY']['#']['IDNUMBER']['0']['#']); $dbrec->idnumber = backup_todb($info['GRADE_ITEM_HISTORY']['#']['IDNUMBER']['0']['#']);
@ -2403,10 +2403,10 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$dbrec->locked = backup_todb($info['GRADE_ITEM_HISTORY']['#']['LOCKED']['0']['#']); $dbrec->locked = backup_todb($info['GRADE_ITEM_HISTORY']['#']['LOCKED']['0']['#']);
$dbrec->locktime = backup_todb($info['GRADE_ITEM_HISTORY']['#']['LOCKTIME']['0']['#']); $dbrec->locktime = backup_todb($info['GRADE_ITEM_HISTORY']['#']['LOCKTIME']['0']['#']);
$dbrec->needsupdate = backup_todb($info['GRADE_ITEM_HISTORY']['#']['NEEDSUPDATE']['0']['#']); $dbrec->needsupdate = backup_todb($info['GRADE_ITEM_HISTORY']['#']['NEEDSUPDATE']['0']['#']);
$DB->insert_record('grade_items_history', $dbrec); $DB->insert_record('grade_items_history', $dbrec);
unset($dbrec); unset($dbrec);
} }
//Increment counters //Increment counters
$counter++; $counter++;
@ -2424,7 +2424,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
} }
} }
} }
// process histories // process histories
if ($gohcount && $status) { if ($gohcount && $status) {
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
@ -2448,7 +2448,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//traverse_xmlize($info); //Debug //traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug //print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug //$GLOBALS['traverse_array']=""; //Debug
$oldobj = backup_getid($restore->backup_unique_code,"grade_outcomes", backup_todb($info['GRADE_OUTCOME_HISTORY']['#']['OLDID']['0']['#'])); $oldobj = backup_getid($restore->backup_unique_code,"grade_outcomes", backup_todb($info['GRADE_OUTCOME_HISTORY']['#']['OLDID']['0']['#']));
if (empty($oldobj->new_id)) { if (empty($oldobj->new_id)) {
// if the old object is not being restored, can't restoring its history // if the old object is not being restored, can't restoring its history
@ -2468,10 +2468,10 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$oldobj = backup_getid($restore->backup_unique_code,"scale", backup_todb($info['GRADE_OUTCOME_HISTORY']['#']['SCALEID']['0']['#'])); $oldobj = backup_getid($restore->backup_unique_code,"scale", backup_todb($info['GRADE_OUTCOME_HISTORY']['#']['SCALEID']['0']['#']));
$dbrec->scaleid = $oldobj->new_id; $dbrec->scaleid = $oldobj->new_id;
$dbrec->description = backup_todb($info['GRADE_OUTCOME_HISTORY']['#']['DESCRIPTION']['0']['#']); $dbrec->description = backup_todb($info['GRADE_OUTCOME_HISTORY']['#']['DESCRIPTION']['0']['#']);
$DB->insert_record('grade_outcomes_history', $dbrec); $DB->insert_record('grade_outcomes_history', $dbrec);
unset($dbrec); unset($dbrec);
} }
//Increment counters //Increment counters
$counter++; $counter++;
@ -3396,7 +3396,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
function restore_group_getid($restore, $groupid) { function restore_group_getid($restore, $groupid) {
//We have to recode the groupid field //We have to recode the groupid field
$group = backup_getid($restore->backup_unique_code, 'groups', $groupid); $group = backup_getid($restore->backup_unique_code, 'groups', $groupid);
if ($restore->groups == RESTORE_GROUPS_NONE or $restore->groups == RESTORE_GROUPINGS_ONLY) { if ($restore->groups == RESTORE_GROUPS_NONE or $restore->groups == RESTORE_GROUPINGS_ONLY) {
$group->new_id = 0; $group->new_id = 0;
} }
@ -3410,7 +3410,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
function restore_grouping_getid($restore, $groupingid) { function restore_grouping_getid($restore, $groupingid) {
//We have to recode the groupid field //We have to recode the groupid field
$grouping = backup_getid($restore->backup_unique_code, 'groupings', $groupingid); $grouping = backup_getid($restore->backup_unique_code, 'groupings', $groupingid);
if ($restore->groups != RESTORE_GROUPS_GROUPINGS and $restore->groups != RESTORE_GROUPINGS_ONLY) { if ($restore->groups != RESTORE_GROUPS_GROUPINGS and $restore->groups != RESTORE_GROUPINGS_ONLY) {
$grouping->new_id = 0; $grouping->new_id = 0;
} }
@ -3544,7 +3544,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//We have to recode the userid field //We have to recode the userid field
if (!$user = backup_getid($restore->backup_unique_code,"user",$group_member->userid)) { if (!$user = backup_getid($restore->backup_unique_code,"user",$group_member->userid)) {
debugging("group membership can not be restored, user id $group_member->userid not present in backup"); debugging("group membership can not be restored, user id $group_member->userid not present in backup");
// do not not block the restore // do not not block the restore
continue; continue;
} }
@ -3624,7 +3624,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
// now fix the defaultgroupingid in course // now fix the defaultgroupingid in course
$course = $DB->get_record('course', array('id'=>$restore->course_id)); $course = $DB->get_record('course', array('id'=>$restore->course_id));
if ($course->defaultgroupingid) { if ($course->defaultgroupingid) {
if ($grouping = restore_grouping_getid($restore, $course->defaultgroupingid)) { if ($grouping = restore_grouping_getid($restore, $course->defaultgroupingid)) {
$DB->set_field('course', 'defaultgroupingid', $grouping->new_id, array('id'=>$course->id)); $DB->set_field('course', 'defaultgroupingid', $grouping->new_id, array('id'=>$course->id));
} else { } else {
$DB->set_field('course', 'defaultgroupingid', 0, array('id'=>$course->id)); $DB->set_field('course', 'defaultgroupingid', 0, array('id'=>$course->id));
@ -3876,7 +3876,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$counter = 0; $counter = 0;
// 'users' is the old users folder, 'user' is the new one, with a new hierarchy. Detect which one is here and treat accordingly // 'users' is the old users folder, 'user' is the new one, with a new hierarchy. Detect which one is here and treat accordingly
//in CFG->dataroot //in CFG->dataroot
$dest_dir = $CFG->dataroot."/user"; $dest_dir = $CFG->dataroot."/user";
$status = check_dir_exists($dest_dir,true); $status = check_dir_exists($dest_dir,true);
@ -3884,7 +3884,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//Now, we iterate over "user_files" records to check if that user dir must be //Now, we iterate over "user_files" records to check if that user dir must be
//copied (and renamed) to the "users" dir. //copied (and renamed) to the "users" dir.
$rootdir = $CFG->dataroot."/temp/backup/".$restore->backup_unique_code."/user_files"; $rootdir = $CFG->dataroot."/temp/backup/".$restore->backup_unique_code."/user_files";
//Check if directory exists //Check if directory exists
$userlist = array(); $userlist = array();
@ -3901,7 +3901,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
} }
} }
foreach ($userlist as $olduserid => $backup_location) { foreach ($userlist as $olduserid => $backup_location) {
//Look for dir like username in backup_ids //Look for dir like username in backup_ids
//If that user exists in backup_ids //If that user exists in backup_ids
if ($user = backup_getid($restore->backup_unique_code,"user",$olduserid)) { if ($user = backup_getid($restore->backup_unique_code,"user",$olduserid)) {
@ -4577,7 +4577,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
"SELECT id, course, instance "SELECT id, course, instance
FROM {course_modules} FROM {course_modules}
WHERE id = ? AND instance = 0", array($cm_module->new_id)); WHERE id = ? AND instance = 0", array($cm_module->new_id));
if($course_modules_inst_zero){ // Clean up the invalid instances if($course_modules_inst_zero){ // Clean up the invalid instances
foreach($course_modules_inst_zero as $course_modules_inst){ foreach($course_modules_inst_zero as $course_modules_inst){
$DB->delete_records('course_modules', array('id'=>$course_modules_inst->id)); $DB->delete_records('course_modules', array('id'=>$course_modules_inst->id));
@ -5752,7 +5752,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
if (!isset($this->temp)) { if (!isset($this->temp)) {
$this->temp = ""; $this->temp = "";
} }
$this->temp .= htmlspecialchars(trim($this->content))."</".$tagName.">"; $this->temp .= htmlspecialchars(trim($this->content))."</".$tagName.">";
//Dependig of different combinations, do different things //Dependig of different combinations, do different things
if ($this->level == 4) { if ($this->level == 4) {
@ -5767,7 +5767,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$this->temp; $xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$this->temp;
//Call to xmlize for this portion of xml data (one BLOCK) //Call to xmlize for this portion of xml data (one BLOCK)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug //echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize($xml_data,0); $data = xmlize($xml_data,0);
//echo strftime ("%X",time())."<p>"; //Debug //echo strftime ("%X",time())."<p>"; //Debug
//traverse_xmlize($data); //Debug //traverse_xmlize($data); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug //print_object ($GLOBALS['traverse_array']); //Debug
@ -5777,7 +5777,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//Get old id //Get old id
$oldid = $data['BLOCK']['#']['ID']['0']['#']; $oldid = $data['BLOCK']['#']['ID']['0']['#'];
//Get instancedata //Get instancedata
if ($data = $data['BLOCK']['#']['INSTANCEDATA']['0']['#']) { if ($data = $data['BLOCK']['#']['INSTANCEDATA']['0']['#']) {
//Restore code calls this multiple times - so might already have the newid //Restore code calls this multiple times - so might already have the newid
if ($newid = backup_getid($this->preferences->backup_unique_code,'block_instance',$oldid)) { if ($newid = backup_getid($this->preferences->backup_unique_code,'block_instance',$oldid)) {
@ -6015,7 +6015,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
isset($this->info->tempmod->availableuntil) ? $this->info->tempmod->availableuntil : 0; isset($this->info->tempmod->availableuntil) ? $this->info->tempmod->availableuntil : 0;
$this->info->tempsection->mods[$this->info->tempmod->id]->showavailability = $this->info->tempsection->mods[$this->info->tempmod->id]->showavailability =
isset($this->info->tempmod->showavailability) ? $this->info->tempmod->showavailability : 0; isset($this->info->tempmod->showavailability) ? $this->info->tempmod->showavailability : 0;
unset($this->info->tempmod); unset($this->info->tempmod);
} }
} }
@ -6209,7 +6209,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
switch($tagName) { switch($tagName) {
case 'COMPLETION': case 'COMPLETION':
// Got all data to make completion entry... // Got all data to make completion entry...
$this->info->tempcompletion->coursemoduleid=$this->info->tempmod->id; $this->info->tempcompletion->coursemoduleid=$this->info->tempmod->id;
$this->info->completiondata[]=$this->info->tempcompletion; $this->info->completiondata[]=$this->info->tempcompletion;
unset($this->info->tempcompletion); unset($this->info->tempcompletion);
$this->info->tempcompletion=new stdClass; $this->info->tempcompletion=new stdClass;
@ -6240,7 +6240,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
switch($tagName) { switch($tagName) {
case 'AVAILABILITY': case 'AVAILABILITY':
// Got all data to make completion entry... // Got all data to make completion entry...
$this->info->tempavailability->coursemoduleid=$this->info->tempmod->id; $this->info->tempavailability->coursemoduleid=$this->info->tempmod->id;
$this->info->availabilitydata[]=$this->info->tempavailability; $this->info->availabilitydata[]=$this->info->tempavailability;
unset($this->info->tempavailability); unset($this->info->tempavailability);
$this->info->tempavailability=new stdClass; $this->info->tempavailability=new stdClass;
@ -6419,7 +6419,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//Reset temp //Reset temp
unset($this->temp); unset($this->temp);
} }
if (($this->level == 5) and ($tagName == "GRADE_LETTER")) { if (($this->level == 5) and ($tagName == "GRADE_LETTER")) {
//Prepend XML standard header to info gathered //Prepend XML standard header to info gathered
$xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$this->temp; $xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$this->temp;
@ -6598,7 +6598,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$preference_id = $data["GRADE_PREFERENCE"]["#"]["ID"]["0"]["#"]; $preference_id = $data["GRADE_PREFERENCE"]["#"]["ID"]["0"]["#"];
$this->counter++; $this->counter++;
//Save to db //Save to db
$status = backup_putid($this->preferences->backup_unique_code, 'grade_preferences', $preference_id, $status = backup_putid($this->preferences->backup_unique_code, 'grade_preferences', $preference_id,
null,$data); null,$data);
//Create returning info //Create returning info
$this->info = $this->counter; $this->info = $this->counter;
@ -6621,7 +6621,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$letter_id = $data["GRADE_LETTER"]["#"]["ID"]["0"]["#"]; $letter_id = $data["GRADE_LETTER"]["#"]["ID"]["0"]["#"];
$this->counter++; $this->counter++;
//Save to db //Save to db
$status = backup_putid($this->preferences->backup_unique_code, 'grade_letter' ,$letter_id, $status = backup_putid($this->preferences->backup_unique_code, 'grade_letter' ,$letter_id,
null,$data); null,$data);
//Create returning info //Create returning info
$this->info = $this->counter; $this->info = $this->counter;
@ -7750,12 +7750,12 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
// MDL-9290 performance improvement on reading large xml // MDL-9290 performance improvement on reading large xml
$lasttime = time(); // crmas $lasttime = time(); // crmas
while ($data = fread($fp, 8192) and !$moodle_parser->finished) { while ($data = fread($fp, 8192) and !$moodle_parser->finished) {
if ((time() - $lasttime) > 5) { if ((time() - $lasttime) > 5) {
$lasttime = time(); $lasttime = time();
backup_flush(1); backup_flush(1);
} }
xml_parse($xml_parser, $data, feof($fp)) xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d", or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)), xml_error_string(xml_get_error_code($xml_parser)),
@ -8846,9 +8846,9 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
} }
// Availability system, if used, needs to find IDs for grade items // Availability system, if used, needs to find IDs for grade items
$rs=$DB->get_recordset_sql(" $rs=$DB->get_recordset_sql("
SELECT SELECT
cma.id,cma.gradeitemid cma.id,cma.gradeitemid
FROM FROM
{course_modules) cm {course_modules) cm
INNER JOIN {course_modules_availability} cma on cm.id=cma.coursemoduleid INNER JOIN {course_modules_availability} cma on cm.id=cma.coursemoduleid
WHERE WHERE
@ -9073,7 +9073,7 @@ WHERE
/// Restore the role contextlevels. /// Restore the role contextlevels.
if (isset($roledata->contextlevels)) { if (isset($roledata->contextlevels)) {
set_role_contextlevels($newroleid, $roledata->contextlevels); set_role_contextlevels($newroleid, $roledata->contextlevels);
} else { } else {
// Data was not in the backup file (must be a pre-2.0 backup). // Data was not in the backup file (must be a pre-2.0 backup).
// Allow this role to be assigned at all levels, which is // Allow this role to be assigned at all levels, which is
@ -9107,7 +9107,7 @@ WHERE
$rolename->roleid = $newrole->new_id; $rolename->roleid = $newrole->new_id;
$rolename->contextid = $coursecontext->id; $rolename->contextid = $coursecontext->id;
$rolename->name = $roledata->nameincourse; $rolename->name = $roledata->nameincourse;
$DB->insert_record('role_names', $rolename); $DB->insert_record('role_names', $rolename);
} }
} }
@ -9436,4 +9436,3 @@ WHERE
fclose($restorelog); fclose($restorelog);
} }
} }
?>

View file

@ -1,4 +1,4 @@
<?PHP //$Id$ <?PHP
require_once ("../config.php"); require_once ("../config.php");
require_once ("backup_scheduled.php"); require_once ("backup_scheduled.php");
require_once ("lib.php"); require_once ("lib.php");
@ -38,4 +38,3 @@
echo "End course ". format_string($course->fullname)." FAIL\n\n"; echo "End course ". format_string($course->fullname)." FAIL\n\n";
} }
} }
?>