Commit 120b3758 authored by moodler's avatar moodler
Browse files

MDL-10107 Fixed the definition of message providers ... it now works through...

MDL-10107   Fixed the definition of message providers ... it now works through files very similar to those for events and capabilities, which makes them easy to add/remove/change as necessary
parent e70e036c
...@@ -179,9 +179,13 @@ ...@@ -179,9 +179,13 @@
// Install the roles system. // Install the roles system.
moodle_install_roles(); moodle_install_roles();
// install core event handlers // Install core event handlers
events_update_definition(); events_update_definition();
// Install core message providers
require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions
message_update_providers();
/// This is used to handle any settings that must exist in $CFG but which do not exist in /// This is used to handle any settings that must exist in $CFG but which do not exist in
/// admin_get_root()/$ADMIN as admin_setting objects (there are some exceptions). /// admin_get_root()/$ADMIN as admin_setting objects (there are some exceptions).
apply_default_exception_settings(array('auth' => 'email', apply_default_exception_settings(array('auth' => 'email',
...@@ -332,9 +336,13 @@ ...@@ -332,9 +336,13 @@
print_error('cannotupgradecapabilities', 'debug'); print_error('cannotupgradecapabilities', 'debug');
} }
// update core events // Update core events
events_update_definition(); events_update_definition();
// Update core message providers
require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions
message_update_providers();
if (set_config("version", $version)) { if (set_config("version", $version)) {
remove_dir($CFG->dataroot . '/cache', true); // flush cache remove_dir($CFG->dataroot . '/cache', true); // flush cache
notify($strdatabasesuccess, "green"); notify($strdatabasesuccess, "green");
......
...@@ -160,6 +160,8 @@ $string['markunreadbutton'] = 'Mark<br />unread'; ...@@ -160,6 +160,8 @@ $string['markunreadbutton'] = 'Mark<br />unread';
$string['maxattachmentsize'] = 'Maximum attachment size'; $string['maxattachmentsize'] = 'Maximum attachment size';
$string['maxtimehaspassed'] = 'Sorry, but the maximum time for editing this post ($a) has passed!'; $string['maxtimehaspassed'] = 'Sorry, but the maximum time for editing this post ($a) has passed!';
$string['message'] = 'Message'; $string['message'] = 'Message';
$string['messageprovider:posts'] = 'Subscribed forum posts';
$string['messageprovider:digests'] = 'Subscribed forum digests';
$string['missingsearchterms'] = 'The following search terms occur only in the HTML markup of this message:'; $string['missingsearchterms'] = 'The following search terms occur only in the HTML markup of this message:';
$string['modeflatnewestfirst'] = 'Display replies flat, with newest first'; $string['modeflatnewestfirst'] = 'Display replies flat, with newest first';
$string['modeflatoldestfirst'] = 'Display replies flat, with oldest first'; $string['modeflatoldestfirst'] = 'Display replies flat, with oldest first';
......
...@@ -914,6 +914,8 @@ $string['maximumupload'] = 'Maximum upload size'; ...@@ -914,6 +914,8 @@ $string['maximumupload'] = 'Maximum upload size';
$string['maxsize'] = 'Max size: $a'; $string['maxsize'] = 'Max size: $a';
$string['memberincourse'] = 'People in the course'; $string['memberincourse'] = 'People in the course';
$string['messagebody'] = 'Message body'; $string['messagebody'] = 'Message body';
$string['messageprovider:errors'] = 'Important errors with the site';
$string['messageprovider:notices'] = 'Notices about minor problems';
$string['messagedselectedusers'] = 'Selected users have been messaged and the recipient list has been reset.'; $string['messagedselectedusers'] = 'Selected users have been messaged and the recipient list has been reset.';
$string['messagedselectedusersfailed'] = 'Something went wrong while messaging selected users. Some may have received the email.'; $string['messagedselectedusersfailed'] = 'Something went wrong while messaging selected users. Some may have received the email.';
$string['messageselect'] = 'Select this user as an email recipient'; $string['messageselect'] = 'Select this user as an email recipient';
......
...@@ -24,6 +24,7 @@ require_once($CFG->libdir.'/xmldb/xmldb_statement.php'); ...@@ -24,6 +24,7 @@ require_once($CFG->libdir.'/xmldb/xmldb_statement.php');
/// Add other libraries /// Add other libraries
require_once($CFG->libdir.'/xmlize.php'); require_once($CFG->libdir.'/xmlize.php');
require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions
function upgrade_main_savepoint($result, $version) { function upgrade_main_savepoint($result, $version) {
global $CFG; global $CFG;
...@@ -322,6 +323,9 @@ function upgrade_plugins($type, $dir, $return) { ...@@ -322,6 +323,9 @@ function upgrade_plugins($type, $dir, $return) {
/// Install events /// Install events
events_update_definition($type.'/'.$plug); events_update_definition($type.'/'.$plug);
/// Install message providers
message_update_providers($type.'/'.$plug);
/// Run local install function if there is one /// Run local install function if there is one
if (is_readable($fullplug .'/lib.php')) { if (is_readable($fullplug .'/lib.php')) {
include_once($fullplug .'/lib.php'); include_once($fullplug .'/lib.php');
...@@ -357,12 +361,17 @@ function upgrade_plugins($type, $dir, $return) { ...@@ -357,12 +361,17 @@ function upgrade_plugins($type, $dir, $return) {
} }
/// Now analyze upgrade results /// Now analyze upgrade results
if ($newupgrade_status) { // No upgrading failed if ($newupgrade_status) { // No upgrading failed
// OK so far, now update the plugins record /// OK so far, now update the plugins record
set_config($pluginversion, $plugin->version); set_config($pluginversion, $plugin->version);
if (!update_capabilities($type.'/'.$plug)) { if (!update_capabilities($type.'/'.$plug)) {
print_error('cannotupdateplugincap', '', '', $plugin->name); print_error('cannotupdateplugincap', '', '', $plugin->name);
} }
/// Update events
events_update_definition($type.'/'.$plug); events_update_definition($type.'/'.$plug);
/// Update message providers
message_update_providers($type.'/'.$plug);
notify(get_string('modulesuccess', '', $plugin->name), 'notifysuccess'); notify(get_string('modulesuccess', '', $plugin->name), 'notifysuccess');
} else { } else {
notify('Upgrading '. $plugin->name .' from '. $CFG->$pluginversion .' to '. $plugin->version .' FAILED!'); notify('Upgrading '. $plugin->name .' from '. $CFG->$pluginversion .' to '. $plugin->version .' FAILED!');
...@@ -518,8 +527,13 @@ function upgrade_activity_modules($return) { ...@@ -518,8 +527,13 @@ function upgrade_activity_modules($return) {
if (!update_capabilities('mod/'.$module->name)) { if (!update_capabilities('mod/'.$module->name)) {
print_error('cannotupdatemodcap', '', '', $module->name); print_error('cannotupdatemodcap', '', '', $module->name);
} }
/// Update events
events_update_definition('mod/'.$module->name); events_update_definition('mod/'.$module->name);
/// Update message providers
message_update_providers('mod/'.$module->name);
$updated_modules = true; $updated_modules = true;
} else { } else {
...@@ -566,6 +580,9 @@ function upgrade_activity_modules($return) { ...@@ -566,6 +580,9 @@ function upgrade_activity_modules($return) {
/// Events /// Events
events_update_definition('mod/'.$module->name); events_update_definition('mod/'.$module->name);
/// Message providers
message_update_providers('mod/'.$module->name);
/// Run local install function if there is one /// Run local install function if there is one
$installfunction = $module->name.'_install'; $installfunction = $module->name.'_install';
if (function_exists($installfunction)) { if (function_exists($installfunction)) {
......
...@@ -1310,7 +1310,13 @@ function upgrade_blocks_plugins($continueto) { ...@@ -1310,7 +1310,13 @@ function upgrade_blocks_plugins($continueto) {
print_error('nopermissiontoupdateblock', '', '', $block->name); print_error('nopermissiontoupdateblock', '', '', $block->name);
} }
// Update events
events_update_definition($component); events_update_definition($component);
// Update message providers
require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions
message_update_providers($component);
notify(get_string('blocksuccess', '', $blocktitle), 'notifysuccess'); notify(get_string('blocksuccess', '', $blocktitle), 'notifysuccess');
} else { } else {
notify('Upgrading block '. $block->name .' from '. $currblock->version .' to '. $block->version .' FAILED!'); notify('Upgrading block '. $block->name .' from '. $currblock->version .' to '. $block->version .' FAILED!');
...@@ -1378,7 +1384,13 @@ function upgrade_blocks_plugins($continueto) { ...@@ -1378,7 +1384,13 @@ function upgrade_blocks_plugins($continueto) {
notify('Could not set up '.$block->name.' capabilities!'); notify('Could not set up '.$block->name.' capabilities!');
} }
// Update events
events_update_definition($component); events_update_definition($component);
// Update message providers
require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions
message_update_providers($component);
notify(get_string('blocksuccess', '', $blocktitle), 'notifysuccess'); notify(get_string('blocksuccess', '', $blocktitle), 'notifysuccess');
if (!defined('CLI_UPGRADE')|| !CLI_UPGRADE) { if (!defined('CLI_UPGRADE')|| !CLI_UPGRADE) {
echo '<hr />'; echo '<hr />';
......
...@@ -31,34 +31,7 @@ ...@@ -31,34 +31,7 @@
$handlers = array ( $handlers = array (
/* /* Messaging required parameters (object):
* Messaging Events
*/
/*
* required parameters (object):
* modulename -
* modulefile -
*
*/
'message_provider_register' => array (
'handlerfile' => '/lib/messagelib.php',
'handlerfunction' => 'message_provider_register_handler',
'schedule' => 'instant'
),
/*
* required parameters (object):
* modulename -
*
*/
'message_provider_unregister' => array (
'handlerfile' => '/lib/messagelib.php',
'handlerfunction' => 'message_provider_unregister_handler',
'schedule' => 'instant'
),
/* required parameters (object):
* modulename - * modulename -
* userfrom * userfrom
* userto * userto
......
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20080630" COMMENT="XMLDB file for core Moodle tables" <XMLDB PATH="lib/db" VERSION="20080731" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd" xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
> >
...@@ -74,8 +74,7 @@ ...@@ -74,8 +74,7 @@
<FIELD NAME="enrolenddate" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="enrolstartdate" NEXT="enrol"/> <FIELD NAME="enrolenddate" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="enrolstartdate" NEXT="enrol"/>
<FIELD NAME="enrol" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="enrolenddate" NEXT="defaultrole"/> <FIELD NAME="enrol" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="enrolenddate" NEXT="defaultrole"/>
<FIELD NAME="defaultrole" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="The default role given to participants who self-enrol" PREVIOUS="enrol" NEXT="enablecompletion"/> <FIELD NAME="defaultrole" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="The default role given to participants who self-enrol" PREVIOUS="enrol" NEXT="enablecompletion"/>
<FIELD NAME="enablecompletion" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="1 = allow use of 'completion' progress-tracking on this course. <FIELD NAME="enablecompletion" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="1 = allow use of 'completion' progress-tracking on this course. 0 = disable completion tracking on this course." PREVIOUS="defaultrole"/>
0 = disable completion tracking on this course." PREVIOUS="defaultrole"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
...@@ -149,10 +148,7 @@ ...@@ -149,10 +148,7 @@
<FIELD NAME="groupmode" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="visibleold" NEXT="groupingid"/> <FIELD NAME="groupmode" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="visibleold" NEXT="groupingid"/>
<FIELD NAME="groupingid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="groupmode" NEXT="groupmembersonly"/> <FIELD NAME="groupingid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="groupmode" NEXT="groupmembersonly"/>
<FIELD NAME="groupmembersonly" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="only members of any group are allowed to access the activity" PREVIOUS="groupingid" NEXT="completion"/> <FIELD NAME="groupmembersonly" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="only members of any group are allowed to access the activity" PREVIOUS="groupingid" NEXT="completion"/>
<FIELD NAME="completion" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Whether the completion-tracking facilities are enabled for this activity. <FIELD NAME="completion" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Whether the completion-tracking facilities are enabled for this activity. 0 = not enabled (database default) 1 = manual tracking, user can tick this activity off (UI default for most activity types) 2 = automatic tracking, system should mark completion according to rules specified in course_moduleS_completion" PREVIOUS="groupmembersonly" NEXT="completiongradeitemnumber"/>
0 = not enabled (database default)
1 = manual tracking, user can tick this activity off (UI default for most activity types)
2 = automatic tracking, system should mark completion according to rules specified in course_moduleS_completion" PREVIOUS="groupmembersonly" NEXT="completiongradeitemnumber"/>
<FIELD NAME="completiongradeitemnumber" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="Grade-item number used to track automatic completion, if applicable." PREVIOUS="completion" NEXT="completionview"/> <FIELD NAME="completiongradeitemnumber" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="Grade-item number used to track automatic completion, if applicable." PREVIOUS="completion" NEXT="completionview"/>
<FIELD NAME="completionview" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Controls whether a page view is part of the automatic completion requirements for this activity. 0 = view not required 1 = view required" PREVIOUS="completiongradeitemnumber" NEXT="completionexpected"/> <FIELD NAME="completionview" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Controls whether a page view is part of the automatic completion requirements for this activity. 0 = view not required 1 = view required" PREVIOUS="completiongradeitemnumber" NEXT="completionexpected"/>
<FIELD NAME="completionexpected" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Date at which students are expected to complete this activity. This field is used when displaying student progress." PREVIOUS="completionview"/> <FIELD NAME="completionexpected" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Date at which students are expected to complete this activity. This field is used when displaying student progress." PREVIOUS="completionview"/>
...@@ -174,16 +170,8 @@ ...@@ -174,16 +170,8 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="coursemoduleid"/> <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="coursemoduleid"/>
<FIELD NAME="coursemoduleid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="Activity that has been completed (or not)." PREVIOUS="id" NEXT="userid"/> <FIELD NAME="coursemoduleid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="Activity that has been completed (or not)." PREVIOUS="id" NEXT="userid"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="ID of user who has (or hasn't) completed the activity." PREVIOUS="coursemoduleid" NEXT="completionstate"/> <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="ID of user who has (or hasn't) completed the activity." PREVIOUS="coursemoduleid" NEXT="completionstate"/>
<FIELD NAME="completionstate" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="Whether or not the user has completed the activity. Available states: <FIELD NAME="completionstate" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="Whether or not the user has completed the activity. Available states: 0 = not completed [if there's no row in this table, that also counts as 0] 1 = completed 2 = completed, show passed 3 = completed, show failed" PREVIOUS="userid" NEXT="viewed"/>
0 = not completed [if there's no row in this table, that also counts as 0] <FIELD NAME="viewed" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="Tracks whether or not this activity has been viewed. NULL = we are not tracking viewed for this activity 0 = not viewed 1 = viewed" PREVIOUS="completionstate" NEXT="timemodified"/>
1 = completed
2 = completed, show passed
3 = completed, show failed" PREVIOUS="userid" NEXT="viewed"/>
<FIELD NAME="viewed" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="Tracks whether or not this activity has been viewed.
NULL = we are not tracking viewed for this activity
0 = not viewed
1 = viewed" PREVIOUS="completionstate" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="Time at which the completion state last changed." PREVIOUS="viewed"/> <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="Time at which the completion state last changed." PREVIOUS="viewed"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
...@@ -192,7 +180,6 @@ NULL = we are not tracking viewed for this activity ...@@ -192,7 +180,6 @@ NULL = we are not tracking viewed for this activity
<INDEXES> <INDEXES>
<INDEX NAME="coursemoduleid" UNIQUE="false" FIELDS="coursemoduleid" COMMENT="For quick access via course-module (e.g. when displaying course module settings page and we need to determine whether anyone has completed it)." NEXT="userid"/> <INDEX NAME="coursemoduleid" UNIQUE="false" FIELDS="coursemoduleid" COMMENT="For quick access via course-module (e.g. when displaying course module settings page and we need to determine whether anyone has completed it)." NEXT="userid"/>
<INDEX NAME="userid" UNIQUE="false" FIELDS="userid" COMMENT="Index on user ID. Used when obtaining completion information for normal course page view." PREVIOUS="coursemoduleid"/> <INDEX NAME="userid" UNIQUE="false" FIELDS="userid" COMMENT="Index on user ID. Used when obtaining completion information for normal course page view." PREVIOUS="coursemoduleid"/>
</INDEXES> </INDEXES>
</TABLE> </TABLE>
<TABLE NAME="course_sections" COMMENT="to define the sections for each course" PREVIOUS="course_modules_completion" NEXT="course_request"> <TABLE NAME="course_sections" COMMENT="to define the sections for each course" PREVIOUS="course_modules_completion" NEXT="course_request">
...@@ -1762,13 +1749,17 @@ NULL = we are not tracking viewed for this activity ...@@ -1762,13 +1749,17 @@ NULL = we are not tracking viewed for this activity
</TABLE> </TABLE>
<TABLE NAME="message_providers" COMMENT="This table stores the message providers (modules and core systems)" PREVIOUS="portfolio_instance_user" NEXT="message_processors"> <TABLE NAME="message_providers" COMMENT="This table stores the message providers (modules and core systems)" PREVIOUS="portfolio_instance_user" NEXT="message_processors">
<FIELDS> <FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="modulename"/> <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="name"/>
<FIELD NAME="modulename" TYPE="char" LENGTH="166" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="Module Name" PREVIOUS="id" NEXT="modulefile"/> <FIELD NAME="name" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="The full name of the message provider in standard form" PREVIOUS="id" NEXT="component"/>
<FIELD NAME="modulefile" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="The main module file" PREVIOUS="modulename"/> <FIELD NAME="component" TYPE="char" LENGTH="200" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="The name of the component that produces these messages" PREVIOUS="name" NEXT="capability"/>
<FIELD NAME="capability" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="Optional: permission that is required on the user's setting screen to see this message provider." PREVIOUS="component"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me"/> <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me"/>
</KEYS> </KEYS>
<INDEXES>
<INDEX NAME="componentname" UNIQUE="true" FIELDS="component, name" COMMENT="Unique index"/>
</INDEXES>
</TABLE> </TABLE>
<TABLE NAME="message_processors" COMMENT="List of message output plugins" PREVIOUS="message_providers" NEXT="message_working"> <TABLE NAME="message_processors" COMMENT="List of message output plugins" PREVIOUS="message_providers" NEXT="message_working">
<FIELDS> <FIELDS>
...@@ -1813,7 +1804,7 @@ NULL = we are not tracking viewed for this activity ...@@ -1813,7 +1804,7 @@ NULL = we are not tracking viewed for this activity
<SENTENCE TEXT="(name, display_name, xmlrpc_server_url, sso_land_url) VALUES ('mahara','Mahara','/api/xmlrpc/server.php', '/auth/xmlrpc/land.php')" /> <SENTENCE TEXT="(name, display_name, xmlrpc_server_url, sso_land_url) VALUES ('mahara','Mahara','/api/xmlrpc/server.php', '/auth/xmlrpc/land.php')" />
</SENTENCES> </SENTENCES>
</STATEMENT> </STATEMENT>
<STATEMENT NAME="insert log_display" TYPE="insert" TABLE="log_display" COMMENT="Initial insert of records on table log_display" PREVIOUS="insert mnet_application" NEXT="insert message_providers"> <STATEMENT NAME="insert log_display" TYPE="insert" TABLE="log_display" COMMENT="Initial insert of records on table log_display" PREVIOUS="insert mnet_application">
<SENTENCES> <SENTENCES>
<SENTENCE TEXT="(module, action, mtable, field) VALUES ('user', 'view', 'user', 'CONCAT(firstname,&quot; &quot;,lastname)')" /> <SENTENCE TEXT="(module, action, mtable, field) VALUES ('user', 'view', 'user', 'CONCAT(firstname,&quot; &quot;,lastname)')" />
<SENTENCE TEXT="(module, action, mtable, field) VALUES ('course', 'user report', 'user', 'CONCAT(firstname,&quot; &quot;,lastname)')" /> <SENTENCE TEXT="(module, action, mtable, field) VALUES ('course', 'user report', 'user', 'CONCAT(firstname,&quot; &quot;,lastname)')" />
...@@ -1835,10 +1826,5 @@ NULL = we are not tracking viewed for this activity ...@@ -1835,10 +1826,5 @@ NULL = we are not tracking viewed for this activity
<SENTENCE TEXT="(module, action, mtable, field) VALUES ('group', 'view', 'groups', 'name')" /> <SENTENCE TEXT="(module, action, mtable, field) VALUES ('group', 'view', 'groups', 'name')" />
</SENTENCES> </SENTENCES>
</STATEMENT> </STATEMENT>
<STATEMENT NAME="insert message_providers" TYPE="insert" TABLE="message_providers" COMMENT="Initial insert of moodle record in message_providers" PREVIOUS="insert log_display">
<SENTENCES>
<SENTENCE TEXT="(modulename, modulefile) VALUES ('moodle', 'index.php')" />
</SENTENCES>
</STATEMENT>
</STATEMENTS> </STATEMENTS>
</XMLDB> </XMLDB>
\ No newline at end of file
<?php // $Id$
///////////////////////////////////////////////////////////////////////////
// Defines message providers (types of messages being sent) //
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
$messageproviders = array (
/// Notices that an admin might be interested in
'notices' => array (
'capability' => 'moodle/site:config'
),
/// Important errors that an admin ought to know about
'errors' => array (
'capability' => 'moodle/site:config'
)
);
?>
...@@ -264,26 +264,13 @@ function xmldb_main_upgrade($oldversion=0) { ...@@ -264,26 +264,13 @@ function xmldb_main_upgrade($oldversion=0) {
} }
if ($result && $oldversion < 2008072400) { if ($result && $oldversion < 2008072400) {
/// Create the database tables for message_processors and message_providers /// Create the database tables for message_processors
$table = new xmldb_table('message_providers');
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->add_field('modulename', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null);
$table->add_field('modulefile', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$dbman->create_table($table);
$table = new xmldb_table('message_processors'); $table = new xmldb_table('message_processors');
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null); $table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null);
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$dbman->create_table($table); $dbman->create_table($table);
$provider = new object();
$provider->modulename = 'moodle';
$provider->modulefile = 'index.php';
$DB->insert_record('message_providers', $provider);
/// delete old and create new fields /// delete old and create new fields
$table = new xmldb_table('message'); $table = new xmldb_table('message');
$field = new xmldb_field('messagetype'); $field = new xmldb_field('messagetype');
...@@ -450,6 +437,34 @@ function xmldb_main_upgrade($oldversion=0) { ...@@ -450,6 +437,34 @@ function xmldb_main_upgrade($oldversion=0) {
/// Main savepoint reached /// Main savepoint reached
upgrade_main_savepoint($result, 2008073000); upgrade_main_savepoint($result, 2008073000);
} }
if ($result && $oldversion < 2008073104) {
/// Drop old table that might exist for some people
$table = new xmldb_table('message_providers');
if ($dbman->table_exists($table)) {
$dbman->drop_table($table);
}
/// Define table message_providers to be created
$table = new xmldb_table('message_providers');
/// Adding fields to table message_providers
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null);
$table->add_field('component', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null, null, null);
$table->add_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
/// Adding keys to table message_providers
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Adding indexes to table message_providers
$table->add_index('componentname', XMLDB_INDEX_UNIQUE, array('component', 'name'));
/// Create table for message_providers
$dbman->create_table($table);
upgrade_main_savepoint($result, 2008073104);
}
/* /*
* TODO: * TODO:
......
...@@ -24,9 +24,9 @@ ...@@ -24,9 +24,9 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/** /**
* messagelib.php - Contains the events handlers for the message system * messagelib.php - Contains generic messaging functions for the message system
* *
* @author Luis Rodrigues * @author Luis Rodrigues and Martin Dougiamas
* @version $Id$ * @version $Id$
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package * @package
...@@ -35,42 +35,11 @@ ...@@ -35,42 +35,11 @@
define('TIMETOSHOWUSERS', 300); define('TIMETOSHOWUSERS', 300);
/**
* Is trigged by an events_trigger in the MODULE_install function when
* a module wants to be a message provider provider.
* @param object $eventdata the information about the message provider (name and file)
* @return boolean success
*/
function message_provider_register_handler($eventdata) {
global $DB;
$return = true;
$provider = new object();
$provider->modulename = $eventdata->modulename;
$provider->modulefile = $eventdata->modulefile;
if (!$DB->insert_record('message_providers', $provider)) {
$return = false;
}
// everything ok :-)
return $return;
}
/**
* To be used to ungegister a message provider (curently not used)
* @param object $eventdata the information about the message provider (name and file)
* @return boolean success
*/
function message_provider_unregister_handler($eventdata) {
// everything ok :-)
return true;
}
/** /**
* Triggered when a message provider wants to send a message. * Triggered when a message provider wants to send a message.
* This functions checks the user's processor configuration to send the given type of message, * This functions checks the user's processor configuration to send the given type of message,
* then tries to send it. * then tries to send it.
* @param object $eventdata information about he message (origin, destination, type, content) * @param object $eventdata information about the message (origin, destination, type, content)
* @return boolean success * @return boolean success
*/ */
function message_send_handler($eventdata){ function message_send_handler($eventdata){
...@@ -107,7 +76,7 @@ function message_send_handler($eventdata){ ...@@ -107,7 +76,7 @@ function message_send_handler($eventdata){
// to be able to distinguish between a user who has no settings and one who doesn't want contact // to be able to distinguish between a user who has no settings and one who doesn't want contact
// ... perhaps a "none" setting // ... perhaps a "none" setting
$processor = get_user_preferences('message_provider_'.$eventdata->modulename.'_'.$userstate, 'email', $eventdata->userto->id); $processor = get_user_preferences('message_provider_'.$eventdata->component.$eventdata->name.'_'.$userstate, 'email', $eventdata->userto->id);
/// Now process the message /// Now process the message
...@@ -150,4 +119,164 @@ function message_send_handler($eventdata){ ...@@ -150,4 +119,164 @@ function message_send_handler($eventdata){
return true; return true;
} }
/**
* This code updates the message_providers table with the current set of providers
* @param $component - examples: 'moodle', 'mod/forum', 'block/quiz_results'
* @return boolean
*/
function message_update_providers($component='moodle') {
global $DB;
// load message providers from files
$fileproviders = message_get_providers_from_file($component);
// load message providers from the database
$dbproviders = message_get_providers_from_db($component);
foreach ($fileproviders as $messagename => $fileprovider) {
if (!empty($dbproviders[$messagename])) { // Already exists in the database
if ($dbproviders[$messagename]->capability == $fileprovider['capability']) { // Same, so ignore
// exact same message provider already present in db, ignore this entry