mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
Merge branch 'dev_MDL-33147_transaction' of git://github.com/dongsheng/moodle
This commit is contained in:
commit
63f2813497
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user