MDL-33587 Delete the reference properly in stored_file::delete()

This commit is contained in:
David Mudrak
2012-06-07 18:02:12 +02:00
parent 1c0da8498f
commit 3b2465fee6
+8 -3
View File
@@ -266,15 +266,20 @@ class stored_file {
$transaction = $DB->start_delegated_transaction();
// If other files referring to this file, we need convert them
// If there are other files referring to this file, convert them to copies.
if ($files = $this->fs->get_references_by_storedfile($this)) {
foreach ($files as $file) {
$this->fs->import_external_file($file);
}
}
// Now delete file records in DB
// If this file is a reference (alias) to another file, unlink it first.
if ($this->is_external_file()) {
$this->delete_reference();
}
// Now delete the file record.
$DB->delete_records('files', array('id'=>$this->file_record->id));
$DB->delete_records('files_reference', array('id'=>$this->file_record->referencefileid));
$transaction->allow_commit();