From: mjollnir_ Date: Mon, 20 Sep 2004 05:51:42 +0000 (+0000) Subject: Logging new file paths from backup/restore. Since the files don't have any metadata... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=8930f90071735d7acaa6297695125e7778db9616;p=moodle.git Logging new file paths from backup/restore. Since the files don't have any metadata, we're logging against the logged in user (ie, the teacher restoring the course). These patches are maintained in an publicly accessible Arch repository, see: http://lists.eduforge.org/cgi-bin/archzoom.cgi/arch-eduforge@catalyst.net.nz--2004-MIRROR/moodle--eduforge--1.3.3 Index of arch patches in this commit: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-85 2004-09-20 05:33:06 GMT Penny Leach adding log entries when restoring files arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-86 2004-09-20 05:34:59 GMT Penny Leach fix related to logging uploads Full logs: Revision: moodle--eduforge--1.3.3--patch-85 Archive: arch-eduforge@catalyst.net.nz--2004 Creator: Penny Leach Date: Mon Sep 20 17:33:06 NZST 2004 Standard-date: 2004-09-20 05:33:06 GMT Modified-files: backup/lib.php New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-85 Summary: adding log entries when restoring files Keywords: Revision: moodle--eduforge--1.3.3--patch-86 Archive: arch-eduforge@catalyst.net.nz--2004 Creator: Penny Leach Date: Mon Sep 20 17:34:59 NZST 2004 Standard-date: 2004-09-20 05:34:59 GMT Modified-files: lib/uploadlib.php New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-86 Summary: fix related to logging uploads Keywords: --- diff --git a/backup/lib.php b/backup/lib.php index 4683a62680..ab63a1597d 100644 --- a/backup/lib.php +++ b/backup/lib.php @@ -2,6 +2,8 @@ //This file contains all the general function needed (file manipulation...) //not directly part of the backup/restore utility + require_once($CFG->dirroot.'/lib/uploadlib.php'); + //Sets a name/value pair in backup_config table function backup_set_config($name, $value) { if (get_field("backup_config", "name", "name", $name)) { @@ -286,7 +288,11 @@ //$perms=fileperms($from_file); //return copy($from_file,$to_file) && chmod($to_file,$perms); umask(0000); - return copy($from_file,$to_file) && chmod($to_file,$CFG->directorypermissions); + if (copy($from_file,$to_file) && chmod($to_file,$CFG->directorypermissions)) { + clam_log_upload($to_file,null,true); + return true; + } + return false; } else if (is_dir($from_file)) { return backup_copy_dir($from_file,$to_file); diff --git a/lib/uploadlib.php b/lib/uploadlib.php index 8e99cf699c..66e81e2755 100644 --- a/lib/uploadlib.php +++ b/lib/uploadlib.php @@ -611,7 +611,7 @@ function get_clam_error_code($returncode) { /** * adds a file upload to the log table so that clam can resolve the filename to the user later if necessary */ -function clam_log_upload($newfilepath,$course=null) { +function clam_log_upload($newfilepath,$course=null,$nourl=false) { global $CFG,$USER; // get rid of any double // that might have appeared $newfilepath = preg_replace('/\/\//','/',$newfilepath); @@ -622,7 +622,7 @@ function clam_log_upload($newfilepath,$course=null) { if ($course) { $courseid = $course->id; } - add_to_log($courseid,"upload","upload",$_SERVER['HTTP_REFERER'],$newfilepath); + add_to_log($courseid,"upload","upload",((!$nourl) ? substr($_SERVER['HTTP_REFERER'],0,100) : ''),$newfilepath); } /** @@ -649,10 +649,28 @@ function clam_log_infected($oldfilepath='',$newfilepath='',$userid=0) { /** * some of the modules allow moving attachments (glossary), in which case we need to hunt down an original log and change the path. + * @param oldpath - the old path to the file (should be in the log) + * @param newpath - new path + * @param update - if true, will overwrite old record (used for forum moving etc). */ -function clam_change_log($oldpath,$newpath) { +function clam_change_log($oldpath,$newpath,$update=true) { global $CFG; - $sql = "UPDATE {$CFG->prefix}log SET info = '$newpath' WHERE module = 'upload' AND info = '$oldpath'"; - execute_sql($sql); + + if (!$record = get_record("log","info",$oldpath,"module","upload")) { + error_log("couldn't find record"); + return false; + } + $record->info = $newpath; + if ($update) { + if (update_record("log",$record)) { + error_log("updated record"); + } + } + else { + unset($record->id); + if (insert_record("log",$record)) { + error_log("inserted record"); + } + } } ?> \ No newline at end of file