mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
Merge branch 'dev_MDL-33147_transaction' of git://github.com/dongsheng/moodle
This commit is contained in:
commit
63f2813497
2 changed files with 14 additions and 0 deletions
|
@ -1260,6 +1260,8 @@ class file_storage {
|
||||||
$filerecord->timemodified = $now;
|
$filerecord->timemodified = $now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$transaction = $DB->start_delegated_transaction();
|
||||||
|
|
||||||
// Insert file reference record.
|
// Insert file reference record.
|
||||||
try {
|
try {
|
||||||
$referencerecord = new stdClass;
|
$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);
|
$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
|
// Adding repositoryid and reference to file record to create stored_file instance
|
||||||
$filerecord->repositoryid = $repositoryid;
|
$filerecord->repositoryid = $repositoryid;
|
||||||
$filerecord->reference = $reference;
|
$filerecord->reference = $reference;
|
||||||
|
|
|
@ -205,6 +205,8 @@ class stored_file {
|
||||||
// Remove repository info.
|
// Remove repository info.
|
||||||
$this->repository = null;
|
$this->repository = null;
|
||||||
|
|
||||||
|
$transaction = $DB->start_delegated_transaction();
|
||||||
|
|
||||||
// Remove reference info from DB.
|
// Remove reference info from DB.
|
||||||
$DB->delete_records('files_reference', array('id'=>$this->file_record->referencefileid));
|
$DB->delete_records('files_reference', array('id'=>$this->file_record->referencefileid));
|
||||||
|
|
||||||
|
@ -216,6 +218,8 @@ class stored_file {
|
||||||
$filerecord->referencefileid = null;
|
$filerecord->referencefileid = null;
|
||||||
$this->update($filerecord);
|
$this->update($filerecord);
|
||||||
|
|
||||||
|
$transaction->allow_commit();
|
||||||
|
|
||||||
// unset object variable
|
// unset object variable
|
||||||
unset($this->file_record->repositoryid);
|
unset($this->file_record->repositoryid);
|
||||||
unset($this->file_record->reference);
|
unset($this->file_record->reference);
|
||||||
|
@ -247,6 +251,9 @@ class stored_file {
|
||||||
*/
|
*/
|
||||||
public function delete() {
|
public function delete() {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
|
$transaction = $DB->start_delegated_transaction();
|
||||||
|
|
||||||
// If other files referring to this file, we need convert them
|
// If other files referring to this file, we need convert them
|
||||||
if ($files = $this->fs->get_references_by_storedfile($this)) {
|
if ($files = $this->fs->get_references_by_storedfile($this)) {
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
@ -256,6 +263,9 @@ class stored_file {
|
||||||
// Now delete file records in DB
|
// Now delete file records in DB
|
||||||
$DB->delete_records('files', array('id'=>$this->file_record->id));
|
$DB->delete_records('files', array('id'=>$this->file_record->id));
|
||||||
$DB->delete_records('files_reference', array('id'=>$this->file_record->referencefileid));
|
$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
|
// moves pool file to trash if content not needed any more
|
||||||
$this->fs->deleted_file_cleanup($this->file_record->contenthash);
|
$this->fs->deleted_file_cleanup($this->file_record->contenthash);
|
||||||
return true; // BC only
|
return true; // BC only
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue