MDL-33416 files: Remove unused reference fields in files table
authorMarina Glancy <marina@moodle.com>
Fri, 13 Sep 2013 06:46:25 +0000 (16:46 +1000)
committerMarina Glancy <marina@moodle.com>
Fri, 27 Sep 2013 06:50:08 +0000 (16:50 +1000)
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
lib/db/upgrade.php
lib/filestorage/file_storage.php
lib/filestorage/stored_file.php
repository/upgrade.txt
version.php

index b0c04d8..f8f65cc 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20130921" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20130927" COMMENT="XMLDB file for core Moodle tables"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
 >
         <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
         <FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="order of files"/>
         <FIELD NAME="referencefileid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Use to indicate file is a proxy for repository file"/>
-        <FIELD NAME="referencelastsync" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Last time the proxy file was synced with repository, defined for performance reasons"/>
-        <FIELD NAME="referencelifetime" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="How often do we have to sync proxy file with repository, defined for performance reasons"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
index d68ce28..3d453f4 100644 (file)
@@ -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;
 }
index 3783eee..f05a70a 100644 (file)
@@ -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);
index 93b7cda..e937405 100644 (file)
@@ -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 {
index 2e03f7a..6d021bb 100644 (file)
@@ -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 ===
 
index 14acbaa..a8830c7 100644 (file)
@@ -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.