From e2a61ee3dbc5dfbcdc83533acda56dfe8b07b0ed Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Fri, 13 Sep 2013 16:46:25 +1000 Subject: [PATCH] MDL-33416 files: Remove unused reference fields in files table Fields files.referencelastsync and files.referencelifetime just waste the space and actually duplicate the fields files_reference.lifetime and files_reference.lastsync --- lib/db/install.xml | 4 +--- lib/db/upgrade.php | 24 ++++++++++++++++++++++++ lib/filestorage/file_storage.php | 6 +----- lib/filestorage/stored_file.php | 6 ------ repository/upgrade.txt | 3 ++- version.php | 2 +- 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/lib/db/install.xml b/lib/db/install.xml index b0c04d8825e..f8f65cc6cdc 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -2437,8 +2437,6 @@ - - diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index d68ce2833d9..3d453f45641 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2555,5 +2555,29 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2013092001.02); } + if ($oldversion < 2013092700.01) { + + $table = new xmldb_table('files'); + + // Define field referencelastsync to be dropped from files. + $field = new xmldb_field('referencelastsync'); + + // Conditionally launch drop field referencelastsync. + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + // Define field referencelifetime to be dropped from files. + $field = new xmldb_field('referencelifetime'); + + // Conditionally launch drop field referencelifetime. + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2013092700.01); + } + return true; } diff --git a/lib/filestorage/file_storage.php b/lib/filestorage/file_storage.php index 3783eeeba52..f05a70aaa85 100644 --- a/lib/filestorage/file_storage.php +++ b/lib/filestorage/file_storage.php @@ -1400,10 +1400,6 @@ class file_storage { $filerecord->sortorder = 0; } - // TODO MDL-33416 [2.4] fields referencelastsync and referencelifetime to be removed from {files} table completely - unset($filerecord->referencelastsync); - unset($filerecord->referencelifetime); - $filerecord->mimetype = empty($filerecord->mimetype) ? $this->mimetype($filerecord->filename) : $filerecord->mimetype; $filerecord->userid = empty($filerecord->userid) ? null : $filerecord->userid; $filerecord->source = empty($filerecord->source) ? null : $filerecord->source; @@ -2345,7 +2341,7 @@ class file_storage { 'lastsync' => $lastsync, 'lifetime' => $lifetime); $DB->execute('UPDATE {files} SET contenthash = :contenthash, filesize = :filesize, - status = :status, referencelastsync = :lastsync, referencelifetime = :lifetime + status = :status WHERE referencefileid = :referencefileid', $params); $data = array('id' => $referencefileid, 'lastsync' => $lastsync, 'lifetime' => $lifetime); $DB->update_record('files_reference', (object)$data); diff --git a/lib/filestorage/stored_file.php b/lib/filestorage/stored_file.php index 93b7cda0c80..e9374059610 100644 --- a/lib/filestorage/stored_file.php +++ b/lib/filestorage/stored_file.php @@ -156,12 +156,6 @@ class stored_file { } } - if ($field === 'referencelastsync' or $field === 'referencelifetime') { - // do not update those fields - // TODO MDL-33416 [2.4] fields referencelastsync and referencelifetime to be removed from {files} table completely - continue; - } - // adding the field $this->file_record->$field = $value; } else { diff --git a/repository/upgrade.txt b/repository/upgrade.txt index 2e03f7a6987..6d021bbf6fd 100644 --- a/repository/upgrade.txt +++ b/repository/upgrade.txt @@ -10,7 +10,8 @@ http://docs.moodle.org/dev/Repository_API * The function repository_attach_id() was removed, it was never used and was not useful. * New functions send_relative_file() and supports_relative_file() to allow sending relative linked files - see filesystem repository for example. - +* DB fields files.referencelifetime and files.referencelastsync are deleted. + Their values are stored only in files_reference.lastsync and files_reference.lifetime. === 2.5 === diff --git a/version.php b/version.php index 14acbaabe85..a8830c706e4 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2013092700.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2013092700.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes.