From 2fa8aea27987db2669a37b776e39342433282b87 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Thu, 7 Jun 2012 16:29:09 +0200 Subject: [PATCH] MDL-33587 Throw coding exception when trying to unlink a non-reference file --- lib/filestorage/stored_file.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/filestorage/stored_file.php b/lib/filestorage/stored_file.php index 75ab48312a2..3041a52a228 100644 --- a/lib/filestorage/stored_file.php +++ b/lib/filestorage/stored_file.php @@ -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;