MDL-32119 course completion: Removed unused database structure
authorAaron Barnes <aaronb@catalyst.net.nz>
Mon, 21 May 2012 03:40:27 +0000 (15:40 +1200)
committerAaron Barnes <aaronb@catalyst.net.nz>
Tue, 29 May 2012 02:17:22 +0000 (14:17 +1200)
backup/moodle2/backup_stepslib.php
backup/moodle2/restore_stepslib.php
lib/completion/completion_completion.php
lib/completion/completion_criteria_completion.php
lib/db/install.xml
lib/db/upgrade.php
version.php

index d1be602..bc0ea97 100644 (file)
@@ -2017,15 +2017,11 @@ class backup_course_completion_structure_step extends backup_structure_step {
         $criteriacompletions = new backup_nested_element('course_completion_crit_completions');
 
         $criteriacomplete = new backup_nested_element('course_completion_crit_compl', array('id'), array(
-            'criteriaid', 'userid','gradefinal','unenrolled','deleted','timecompleted'
+            'criteriaid', 'userid', 'gradefinal', 'unenrolled', 'timecompleted'
         ));
 
         $coursecompletions = new backup_nested_element('course_completions', array('id'), array(
-            'userid', 'course', 'deleted', 'timenotified', 'timeenrolled','timestarted','timecompleted','reaggregate'
-        ));
-
-        $notify = new backup_nested_element('course_completion_notify', array('id'), array(
-            'course','role','message','timesent'
+            'userid', 'course', 'timeenrolled', 'timestarted', 'timecompleted', 'reaggregate'
         ));
 
         $aggregatemethod = new backup_nested_element('course_completion_aggr_methd', array('id'), array(
@@ -2036,7 +2032,6 @@ class backup_course_completion_structure_step extends backup_structure_step {
             $criteria->add_child($criteriacompletions);
                 $criteriacompletions->add_child($criteriacomplete);
         $cc->add_child($coursecompletions);
-        $cc->add_child($notify);
         $cc->add_child($aggregatemethod);
 
         // We need to get the courseinstances shortname rather than an ID for restore
@@ -2046,7 +2041,6 @@ class backup_course_completion_structure_step extends backup_structure_step {
                                    WHERE ccc.course = ?", array(backup::VAR_COURSEID));
 
 
-        $notify->set_source_table('course_completion_notify', array('course' => backup::VAR_COURSEID));
         $aggregatemethod->set_source_table('course_completion_aggr_methd', array('course' => backup::VAR_COURSEID));
 
         if ($userinfo) {
@@ -2057,7 +2051,6 @@ class backup_course_completion_structure_step extends backup_structure_step {
         $criteria->annotate_ids('role', 'role');
         $criteriacomplete->annotate_ids('user', 'userid');
         $coursecompletions->annotate_ids('user', 'userid');
-        $notify->annotate_ids('role', 'role');
 
         return $cc;
 
index d87cdb9..c1cb537 100644 (file)
@@ -1830,7 +1830,6 @@ class restore_course_completion_structure_step extends restore_structure_step {
 
         $paths = array();
         $paths[] = new restore_path_element('course_completion_criteria', '/course_completion/course_completion_criteria');
-        $paths[] = new restore_path_element('course_completion_notify', '/course_completion/course_completion_notify');
         $paths[] = new restore_path_element('course_completion_aggr_methd', '/course_completion/course_completion_aggr_methd');
 
         if ($userinfo) {
@@ -1934,9 +1933,6 @@ class restore_course_completion_structure_step extends restore_structure_step {
             if (isset($data->unenroled)) {
                 $params['unenroled'] = $data->unenroled;
             }
-            if (isset($data->deleted)) {
-                $params['deleted'] = $data->deleted;
-            }
             $DB->insert_record('course_completion_crit_compl', $params);
         }
     }
@@ -1959,8 +1955,6 @@ class restore_course_completion_structure_step extends restore_structure_step {
             $params = array(
                 'userid' => $data->userid,
                 'course' => $data->course,
-                'deleted' => $data->deleted,
-                'timenotified' => $this->apply_date_offset($data->timenotified),
                 'timeenrolled' => $this->apply_date_offset($data->timeenrolled),
                 'timestarted' => $this->apply_date_offset($data->timestarted),
                 'timecompleted' => $this->apply_date_offset($data->timecompleted),
@@ -1970,34 +1964,6 @@ class restore_course_completion_structure_step extends restore_structure_step {
         }
     }
 
-    /**
-     * Process course completion notification records.
-     *
-     * Note: As of Moodle 2.0 this table is not being used however it has been
-     * left in in the hopes that one day the functionality there will be completed
-     *
-     * @global moodle_database $DB
-     * @param stdClass $data
-     */
-    public function process_course_completion_notify($data) {
-        global $DB;
-
-        $data = (object)$data;
-
-        $data->course = $this->get_courseid();
-        if (!empty($data->role)) {
-            $data->role = $this->get_mappingid('role', $data->role);
-        }
-
-        $params = array(
-            'course' => $data->course,
-            'role' => $data->role,
-            'message' => $data->message,
-            'timesent' => $this->apply_date_offset($data->timesent),
-        );
-        $DB->insert_record('course_completion_notify', $params);
-    }
-
     /**
      * Process course completion aggregate methods
      *
index e6523ea..73c2446 100644 (file)
@@ -42,7 +42,7 @@ class completion_completion extends data_object {
     public $table = 'course_completions';
 
     /* @var array $required_fields Array of required table fields, must start with 'id'. */
-    public $required_fields = array('id', 'userid', 'course', 'deleted', 'timenotified',
+    public $required_fields = array('id', 'userid', 'course',
         'timeenrolled', 'timestarted', 'timecompleted', 'reaggregate');
 
     /* @var int $userid User ID */
@@ -51,12 +51,6 @@ class completion_completion extends data_object {
     /* @var int $course Course ID */
     public $course;
 
-    /* @var int $deleted set to 1 if this record has been deleted */
-    public $deleted;
-
-    /* @var int Timestamp the interested parties were notified of this user's completion. */
-    public $timenotified;
-
     /* @var int Time of course enrolment {@link completion_completion::mark_enrolled()} */
     public $timeenrolled;
 
@@ -80,7 +74,6 @@ class completion_completion extends data_object {
      * @return data_object instance of data_object or false if none found.
      */
     public static function fetch($params) {
-        $params['deleted'] = null;
         return self::fetch_helper('course_completions', __CLASS__, $params);
     }
 
index 7f44800..a2879db 100644 (file)
@@ -42,7 +42,7 @@ class completion_criteria_completion extends data_object {
     public $table = 'course_completion_crit_compl';
 
     /* @var array Array of required table fields, must start with 'id'. */
-    public $required_fields = array('id', 'userid', 'course', 'criteriaid', 'gradefinal', 'rpl', 'deleted', 'unenroled', 'timecompleted');
+    public $required_fields = array('id', 'userid', 'course', 'criteriaid', 'gradefinal', 'rpl', 'unenroled', 'timecompleted');
 
     /* @var array Array of unique fields, used in where clauses */
     public $unique_fields = array('userid', 'course', 'criteriaid');
@@ -62,9 +62,6 @@ class completion_criteria_completion extends data_object {
     /* @var string Record of prior learning, leave blank if none */
     public $rpl;
 
-    /* @var bool Course deleted flag */
-    public $deleted;
-
     /* @var int Timestamp of user unenrolment (if completing a unenrol criteria) */
     public $unenroled;
 
@@ -81,7 +78,6 @@ class completion_criteria_completion extends data_object {
      * @return data_object instance of data_object or false if none found.
      */
     public static function fetch($params) {
-        $params['deleted'] = null;
         return self::fetch_helper('course_completion_crit_compl', __CLASS__, $params);
     }
 
index 0463430..ccaa766 100644 (file)
         <INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
       </INDEXES>
     </TABLE>
-    <TABLE NAME="course_completion_crit_compl" COMMENT="Course completion user records" PREVIOUS="course_completion_criteria" NEXT="course_completion_notify">
+    <TABLE NAME="course_completion_crit_compl" COMMENT="Course completion user records" PREVIOUS="course_completion_criteria" NEXT="course_completions">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="userid"/>
         <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="course"/>
         <FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="userid" NEXT="criteriaid"/>
         <FIELD NAME="criteriaid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Completion criteria this references" PREVIOUS="course" NEXT="gradefinal"/>
         <FIELD NAME="gradefinal" TYPE="number" LENGTH="10" NOTNULL="false" SEQUENCE="false" DECIMALS="5" COMMENT="The final grade for the course (included regardless of whether a passing grade was required)" PREVIOUS="criteriaid" NEXT="unenroled"/>
-        <FIELD NAME="unenroled" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Timestamp when the user was unenroled" PREVIOUS="gradefinal" NEXT="deleted"/>
-        <FIELD NAME="deleted" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" PREVIOUS="unenroled" NEXT="timecompleted"/>
-        <FIELD NAME="timecompleted" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" PREVIOUS="deleted"/>
+        <FIELD NAME="unenroled" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Timestamp when the user was unenroled" PREVIOUS="gradefinal" NEXT="timecompleted"/>
+        <FIELD NAME="timecompleted" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" PREVIOUS="unenroled"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
         <INDEX NAME="timecompleted" UNIQUE="false" FIELDS="timecompleted" PREVIOUS="criteriaid"/>
       </INDEXES>
     </TABLE>
-    <TABLE NAME="course_completion_notify" COMMENT="Course completion notification emails" PREVIOUS="course_completion_crit_compl" NEXT="course_completions">
-      <FIELDS>
-        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="course"/>
-        <FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="role"/>
-        <FIELD NAME="role" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="ID of the role to receive this notification message when a course has been completed" PREVIOUS="course" NEXT="message"/>
-        <FIELD NAME="message" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="HTML formatted message to be sent" PREVIOUS="role" NEXT="timesent"/>
-        <FIELD NAME="timesent" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="message"/>
-      </FIELDS>
-      <KEYS>
-        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
-      </KEYS>
-      <INDEXES>
-        <INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
-      </INDEXES>
-    </TABLE>
-    <TABLE NAME="course_completions" COMMENT="Course completion records" PREVIOUS="course_completion_notify" NEXT="enrol">
+    <TABLE NAME="course_completions" COMMENT="Course completion records" PREVIOUS="course_completion_crit_compl" NEXT="enrol">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="userid"/>
         <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="course"/>
-        <FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="userid" NEXT="deleted"/>
-        <FIELD NAME="deleted" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" PREVIOUS="course" NEXT="timenotified"/>
-        <FIELD NAME="timenotified" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" PREVIOUS="deleted" NEXT="timeenrolled"/>
-        <FIELD NAME="timeenrolled" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timenotified" NEXT="timestarted"/>
+        <FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="userid" NEXT="timeenrolled"/>
+        <FIELD NAME="timeenrolled" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="course" NEXT="timestarted"/>
         <FIELD NAME="timestarted" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timeenrolled" NEXT="timecompleted"/>
         <FIELD NAME="timecompleted" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" PREVIOUS="timestarted" NEXT="reaggregate"/>
         <FIELD NAME="reaggregate" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecompleted"/>
       </KEYS>
     </TABLE>
   </TABLES>
-</XMLDB>
\ No newline at end of file
+</XMLDB>
index c74c724..4c7e95f 100644 (file)
@@ -648,5 +648,43 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint(true, 2012052100.00);
     }
 
+    if ($oldversion < 2012052500.05) {
+
+        // Drop "deleted" fields
+        $table = new xmldb_table('course_completions');
+        $table2 = new xmldb_table('course_completion_crit_compl');
+        $field = new xmldb_field('deleted');
+
+        // Conditionally launch drop field deleted from course_completions
+        if ($dbman->field_exists($table, $field)) {
+            $dbman->drop_field($table, $field);
+        }
+
+        // Conditionally launch drop field deleted from course_completion_crit_compl
+        if ($dbman->field_exists($table2, $field)) {
+            $dbman->drop_field($table2, $field);
+        }
+
+        // Drop unused table "course_completion_notify"
+        $table = new xmldb_table('course_completion_notify');
+
+        // Conditionally launch drop table course_completion_notify
+        if ($dbman->table_exists($table)) {
+            $dbman->drop_table($table);
+        }
+
+        // Drop "timenotified" field from course_completions
+        $table = new xmldb_table('course_completions');
+        $field = new xmldb_field('timenotified');
+
+        // Conditionally launch drop field timenotified from course_completions
+        if ($dbman->field_exists($table, $field)) {
+            $dbman->drop_field($table, $field);
+        }
+
+        // Main savepoint reached
+        upgrade_main_savepoint(true, 2012052500.05);
+    }
+
     return true;
 }
index 9a4c454..648308d 100644 (file)
@@ -30,7 +30,7 @@
 defined('MOODLE_INTERNAL') || die();
 
 
-$version  = 2012052500.01;              // YYYYMMDD      = weekly release date of this DEV branch
+$version  = 2012052500.05;              // YYYYMMDD      = weekly release date of this DEV branch
                                         //         RR    = release increments - 00 in DEV branches
                                         //           .XX = incremental changes