MDL-33587 Throw coding exception when trying to unlink a non-reference file
authorDavid Mudrak <david@moodle.com>
Thu, 7 Jun 2012 14:29:09 +0000 (16:29 +0200)
committerDavid Mudrak <david@moodle.com>
Thu, 7 Jun 2012 15:36:29 +0000 (17:36 +0200)
lib/filestorage/stored_file.php

index 75ab483..3041a52 100644 (file)
@@ -196,12 +196,19 @@ class stored_file {
     }
 
     /**
-     * Delete file reference
+     * Unlink the stored file from the referenced file
      *
+     * This methods destroys the link to the record in files_reference table. This effectively
+     * turns the stored file from being an alias to a plain copy. However, the caller has
+     * to make sure that the actual file's content has beed synced prior to calling this method.
      */
     public function delete_reference() {
         global $DB;
 
+        if (!$this->is_external_file()) {
+            throw new coding_exception('An attempt to unlink a non-reference file.');
+        }
+
         // Remove repository info.
         $this->repository = null;