Index: lib/file/file_storage.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/file/file_storage.php,v
retrieving revision 1.42
diff -u -r1.42 file_storage.php
--- lib/file/file_storage.php	28 May 2010 07:29:12 -0000	1.42
+++ lib/file/file_storage.php	11 Jun 2010 14:58:29 -0000
@@ -116,6 +116,29 @@
     }
 
     /**
+     * Converts a file record object or array into a pathname hash.
+     * @param mixed $file_record Object or array containing file fields
+     */
+    public function get_pathname_hash_by_record($file_record) {
+        // Support either object or array - casting to array and back removes 
+        // link with original object/array
+        $file_record = (array)$file_record;
+        $file_record = (object)$file_record;
+
+        // Clean parameters as done in get_file
+        $file_record->filepath = clean_param($file_record->filepath, PARAM_PATH);
+        $file_record->filename = clean_param($file_record->filename, PARAM_FILE);
+        if ($file_record->filename === '') {
+            $file_record->filename = '.';
+        }
+
+        // Return hash
+        return $this->get_pathname_hash($file_record->contextid, 
+                $file_record->filearea, $file_record->itemid, 
+                $file_record->filepath, $file_record->filename);
+    }
+
+    /**
      * Does this file exist?
      *
      * @param int $contextid
@@ -139,6 +162,15 @@
 
     /**
      * Does this file exist?
+     * @param mixed $file_record Object or array containing file fields
+     */
+    public function file_exists_by_record($file_record) {
+        $pathnamehash = $this->get_pathname_hash_from_record($file_record);
+        return $this->file_exists_by_hash($pathnamehash);
+    }
+
+    /**
+     * Does this file exist?
      *
      * @param string $pathnamehash
      * @return bool
@@ -209,6 +241,15 @@
     }
 
     /**
+     * Does this file exist?
+     * @param mixed $file_record Object or array containing file fields
+     */
+    public function get_file_by_record($file_record) {
+        $pathnamehash = $this->get_pathname_hash_from_record($file_record);
+        return $this->get_file_by_hash($pathnamehash);
+    }
+
+    /**
      * Returns all area files (optionally limited by itemid)
      *
      * @param int $contextid
