diff --git a/lib/filestorage/file_storage.php b/lib/filestorage/file_storage.php index edac5a52517..08013e03aec 100644 --- a/lib/filestorage/file_storage.php +++ b/lib/filestorage/file_storage.php @@ -1260,6 +1260,8 @@ class file_storage { $filerecord->timemodified = $now; } + $transaction = $DB->start_delegated_transaction(); + // Insert file reference record. try { $referencerecord = new stdClass; @@ -1292,6 +1294,8 @@ class file_storage { $this->create_directory($filerecord->contextid, $filerecord->component, $filerecord->filearea, $filerecord->itemid, $filerecord->filepath, $filerecord->userid); + $transaction->allow_commit(); + // Adding repositoryid and reference to file record to create stored_file instance $filerecord->repositoryid = $repositoryid; $filerecord->reference = $reference; diff --git a/lib/filestorage/stored_file.php b/lib/filestorage/stored_file.php index a17d45fef5a..c9367160fe6 100644 --- a/lib/filestorage/stored_file.php +++ b/lib/filestorage/stored_file.php @@ -205,6 +205,8 @@ class stored_file { // Remove repository info. $this->repository = null; + $transaction = $DB->start_delegated_transaction(); + // Remove reference info from DB. $DB->delete_records('files_reference', array('id'=>$this->file_record->referencefileid)); @@ -216,6 +218,8 @@ class stored_file { $filerecord->referencefileid = null; $this->update($filerecord); + $transaction->allow_commit(); + // unset object variable unset($this->file_record->repositoryid); unset($this->file_record->reference); @@ -247,6 +251,9 @@ class stored_file { */ public function delete() { global $DB; + + $transaction = $DB->start_delegated_transaction(); + // If other files referring to this file, we need convert them if ($files = $this->fs->get_references_by_storedfile($this)) { foreach ($files as $file) { @@ -256,6 +263,9 @@ class stored_file { // Now delete file records in DB $DB->delete_records('files', array('id'=>$this->file_record->id)); $DB->delete_records('files_reference', array('id'=>$this->file_record->referencefileid)); + + $transaction->allow_commit(); + // moves pool file to trash if content not needed any more $this->fs->deleted_file_cleanup($this->file_record->contenthash); return true; // BC only