From 674b30f5f79986ba9ee26ac386fca7861bb29e78 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sun, 4 May 2003 23:24:48 +0000 Subject: [PATCH] Begin the execute process. Created temporary structures (dir) --- backup/backup.php | 11 +-- backup/backup_execute.html | 169 ++++++++----------------------------- backup/lib.php | 93 ++++++++++++++++++-- 3 files changed, 129 insertions(+), 144 deletions(-) diff --git a/backup/backup.php b/backup/backup.php index 511775f760..ba24c15d77 100644 --- a/backup/backup.php +++ b/backup/backup.php @@ -113,13 +113,10 @@ //Call the form, depending the step we are if (!$launch) { include_once("backup_form.html"); - } else { - if ($launch == "check") { - include_once("backup_check.html"); - } - if ($launch == "execute") { - include_once("backup_execute.html"); - } + } else if ($launch == "check") { + include_once("backup_check.html"); + } else if ($launch == "execute") { + include_once("backup_execute.html"); } print_simple_box_end(); diff --git a/backup/backup_execute.html b/backup/backup_execute.html index a2660ed674..7fc8005e4f 100644 --- a/backup/backup_execute.html +++ b/backup/backup_execute.html @@ -49,154 +49,59 @@ $backup_course_files = 2; } + if (!isset($id)) { + error ("Course not specified"); + } + + if (!isset($backup_name)) { + error ("Backup name not specified"); + } + + if (!isset($backup_unique_code)) { + error ("Backup unique code not specified"); + } + if ($count == 0) { notice("No backupable modules are installed!"); } -?> - -
action=""> - -"; //Now print the Backup Name tr echo ""; echo ""; - - //Calculate the backup unique code to allow simultaneus backups (to define - //the temp-directory name and records in backup temp tables - $backup_unique_code = time(); - //Add as hidden name - echo ""; - //Line - echo ""; - - //Now print the To Do list - echo ""; - echo ""; - - //This is tha align to every ingo table - $table->align = array ("LEFT","RIGHT"); + //Start the main tr, where all the backup progress is done + echo ""; + echo ""; - echo ""; - } - } - } - //Line - echo ""; + //Delete old_entries from backup tables + echo "
  • Deteting old data"; + $status = backup_delete_old_data(); + if (!$status) { + error ("An error has ocurred"); + } - //Now print the Users tr - echo "
  • "; - echo ""; + //Check for temp and backup and backup_unique_code directory + //Create them as needed + echo "
  • Creating temporary structures"; + $status = check_and_create_backup_dir($backup_unique_code); + //Empty dir + if ($status) { + $status = clear_backup_dir($backup_unique_code); + } + if (!$status) { + error ("An error has ocurred"); + } - //Now print the Logs tr conditionally - if ($backup_logs) { - echo "
  • "; - echo ""; - } - //Add as hidden name - echo ""; - //Now print the User Files tr conditionally - if ($backup_user_files) { - echo ""; - echo ""; - } - //Add as hidden name - echo ""; + //End the main tr, where all the backup is done - //Now print the Course Files tr conditionally - if ($backup_course_files) { - echo ""; - echo ""; - } - //Add as hidden name - echo ""; - } + //End the main table + echo "

    "; echo get_string("name").":"; echo "

    "; - //Calculate the backup string - $backup_name = strtolower(get_string("backup")); - //If non-translated, use "backup" - if (substr($backup_name,0,1) == "[") { - $backup_name = "backup"; - } - //Calculate the format string - $backup_name_format = get_string("backupnameformat"); - //If non-translated, use "%Y%m%d-%H%M" - if (substr($backup_name_format,0,1) == "[") { - $backup_name_format = "%%Y%%m%%d-%%H%%M"; - } - $backup_name .= "-".strtolower($course->shortname)."-".userdate(time(),$backup_name_format,99,false).".zip"; echo $backup_name; - //Add as hidden name - echo ""; echo "

    "; - echo get_string("backupdetails").":"; - echo "

    "; - if ($allmods = get_records("modules") ) { - foreach ($allmods as $mod) { - $modname = $mod->name; - $modbackup = $modname."_backup_mods"; - //If exists the lib & function - $var = "exists_".$modname; - if ($$var) { - //Add hidden fields - $var = "backup_".$modname; - echo ""; - $var = "backup_user_info_".$modname; - echo ""; - $var = "backup_".$modname; - //Only if selected - if ($$var == 1) { - //Print the full tr - echo "

    "; - //Print the mod name - echo "

  • ".get_string("include")." ".get_string("modulenameplural",$modname)." "; - //Now look for user-data status - $backup_user_options[0] = get_string("withoutuserdata"); - $backup_user_options[1] = get_string("withuserdata"); - $var = "backup_user_info_".$modname; - //Print the user info - echo $backup_user_options[$$var]."

    "; - //Call the check function to show more info - $modcheckbackup = $modname."_check_backup_mods"; - $table->data = $modcheckbackup($id,$$var,$backup_unique_code); - print_table($table); - echo "


  • "; - $user_options[0] = get_string("includeallusers"); - $user_options[1] = get_string("includecourseusers"); - ///$user_options[2] = get_string("includeneededusers");--->NOT IMPLEMENTED - echo "

  • ".$user_options[$backup_users]."

    "; - //Add as hidden name - echo ""; - //Print info - $table->data = user_check_backup($id,$backup_unique_code,$backup_users); - print_table($table); - echo "

  • "; - echo "

  • ".get_string("includelogentries")."

    "; - //Print info - $table->data = log_check_backup($id); - print_table($table); - echo "

  • "; - echo "

  • ".get_string("includeuserfiles")."

    "; - //Print info - $table->data = user_files_check_backup($id,$backup_unique_code); - print_table($table); - echo "

  • "; - echo "

  • ".get_string("includecoursefiles")."

    "; - //Print info - $table->data = course_files_check_backup($id,$backup_unique_code); - print_table($table); - echo "

  • "; ?> - -
    -
    - - -"> -"> -
    -
    diff --git a/backup/lib.php b/backup/lib.php index 16dd25842d..860c990c07 100644 --- a/backup/lib.php +++ b/backup/lib.php @@ -177,16 +177,99 @@ //Delete old data in backup tables (if exists) //Two days seems to be apropiate function backup_delete_old_data() { + + global $CFG; + //Change this if you want !! $days = 2; //End change this - $seconds = days * 24 * 60 * 60; + $seconds = $days * 24 * 60 * 60; $delete_from = time()-$seconds; //Now delete from tables - $status = execute_sql("DELETE FROM {$CFG->prefix}backup_ids b - WHERE b.backup_code < '$delete_from'",false); - $status = execute_sql("DELETE FROM {$CFG->prefix}backup_files b - WHERE b.backup_code < '$delete_from'",false); + $status = execute_sql("DELETE FROM {$CFG->prefix}backup_ids + WHERE backup_code < '$delete_from'",false); + if ($status) { + $status = execute_sql("DELETE FROM {$CFG->prefix}backup_files + WHERE backup_code < '$delete_from'",false); + } return($status); } + + //Function to check if a directory exists + //and, optionally, create it + function check_dir_exists($dir,$create=false) { + + global $CFG; + + $status = true; + if(!is_dir($dir)) { + if (!$create) { + $status = false; + } else { + $status = mkdir ($dir,$CFG->directorypermissions); + } + } + return $status; + } + + //Function to check and create the needed dir to + //save all the backup + function check_and_create_backup_dir($backup_unique_code) { + + global $CFG; + + $status = check_dir_exists($CFG->dataroot."/temp",true); + if ($status) { + $status = check_dir_exists($CFG->dataroot."/temp/backup",true); + } + if ($status) { + $status = check_dir_exists($CFG->dataroot."/temp/backup/".$backup_unique_code,true); + } + + return $status; + } + + //Function to delete all the directory contents recursively + //Copied from admin/delete.php + function delete_dir_contents ($rootdir) { + + $dir = opendir($rootdir); + + $status = true; + + while ($file = readdir($dir)) { + if ($file != "." and $file != "..") { + $fullfile = "$rootdir/$file"; + if (filetype($fullfile) == "dir") { + delete_dir_contents($fullfile); + if (!rmdir($fullfile)) { + $status = false;; + } + } else { + if (!unlink("$fullfile")) { + $status = false;; + } + } + } + } + closedir($dir); + + return $status; + + } + + //Function to clear (empty) the contents of the backup_dir + //Copied from admin/delete.php + function clear_backup_dir($backup_unique_code) { + + global $CFG; + + $rootdir = $CFG->dataroot."/temp/backup/".$backup_unique_code; + + //Delete recursively + $status = delete_dir_contents($rootdir); + + return $status; + } + ?> -- 2.39.5