MDL-55956 db: Add priority column for event table
authorJun Pataleta <jun@moodle.com>
Wed, 11 Jan 2017 03:25:02 +0000 (11:25 +0800)
committerJun Pataleta <jun@moodle.com>
Mon, 6 Mar 2017 08:15:26 +0000 (16:15 +0800)
* New priority column in order to enable the rendering of a single,
relevant calendar event for a module that has user/group overrides.
* Insert refresh_mod_calendar_events_task record to task_adhoc
table to upgrade existing calendar events for mod plugins via cron
after upgrade process.

calendar/lib.php
lib/db/install.xml
lib/db/upgrade.php
lib/upgrade.txt
version.php

index f1e09a0..90b5f40 100644 (file)
@@ -120,6 +120,11 @@ define('CALENDAR_SUBSCRIPTION_UPDATE', 1);
  */
 define('CALENDAR_SUBSCRIPTION_REMOVE', 2);
 
+/**
+ * CALENDAR_EVENT_USER_OVERRIDE_PRIORITY - Constant for the user override priority.
+ */
+define('CALENDAR_EVENT_USER_OVERRIDE_PRIORITY', 9999999);
+
 /**
  * Return the days of the week
  *
index 1c86d11..b96da87 100644 (file)
         <FIELD NAME="sequence" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
         <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
         <FIELD NAME="subscriptionid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="The event_subscription id this event is associated with."/>
+        <FIELD NAME="priority" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="The event's display priority. For multiple events with the same module name, instance and eventtype (e.g. for group overrides), the one with the higher priority will be displayed."/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
index 0dc1482..e18a23b 100644 (file)
@@ -2555,5 +2555,29 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint(true, 2017021400.00);
     }
 
+    if ($oldversion < 2017030300.01) {
+
+        // Define field priority to be added to event.
+        $table = new xmldb_table('event');
+        $field = new xmldb_field('priority', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'subscriptionid');
+
+        // Conditionally launch add field priority.
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+        // Create adhoc task for upgrading of existing calendar events.
+        $record = new \stdClass();
+        $record->classname = "\\core\\task\\refresh_mod_calendar_events_task";
+        $record->component = 'core';
+        // Next run time based from nextruntime computation in \core\task\manager::queue_adhoc_task().
+        $nextruntime = time() - 1;
+        $record->nextruntime = $nextruntime;
+        $DB->insert_record('task_adhoc', $record);
+
+        // Main savepoint reached.
+        upgrade_main_savepoint(true, 2017030300.01);
+    }
+
     return true;
 }
index 20cd540..c6a7d87 100644 (file)
@@ -54,6 +54,7 @@ information provided here is intended especially for developers.
   the submitted capability. The parameter 'fieldsexceptid' will now accept context fields which can be used for preloading.
 * The caching option 'immutable' has been added to send_stored_file() and send_file().
 * New adhoc task refresh_mod_calendar_events_task that updates existing calendar events of modules.
+* New 'priority' column for the event table to determine which event to show in case of events with user and group overrides.
 
 === 3.2 ===
 
index 1d8ae47..fdd1a47 100644 (file)
@@ -29,7 +29,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$version  = 2017030300.00;              // YYYYMMDD      = weekly release date of this DEV branch.
+$version  = 2017030300.01;              // YYYYMMDD      = weekly release date of this DEV branch.
                                         //         RR    = release increments - 00 in DEV branches.
                                         //           .XX = incremental changes.