Commit d68a0027 authored by Penny Leach's avatar Penny Leach Committed by Penny Leach

implemented core event subscriptions

parent 5bd281e5
......@@ -139,7 +139,8 @@ function activity_get_users($activitytype, $userids=null, $userobjs=null, $admin
* this function inserts a default set of activity preferences for a given user
* id
*/
function activity_set_defaults($user_id) {
function activity_set_defaults($eventdata) {
$user_id = $eventdata['id'];
$activitytypes = get_records_array('activity_type', 'admin', 0);
$haveemail = in_array('email', array_map(create_function('$a', 'return $a->name;'),
plugins_installed('notification')));
......
......@@ -22,6 +22,18 @@
<KEY NAME="primary" TYPE="primary" FIELDS="name" />
</KEYS>
</TABLE>
<TABLE NAME="event_subscription">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="event" TYPE="char" LENGTH="50" NOTNULL="true" />
<FIELD NAME="callfunction" TYPE="char" LENGTH="255" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="eventfk" TYPE="foreign" FIELDS="event" REFTABLE="event_type" REFFIELDS="name" />
<KEY NAME="subscruk" TYPE="unique" FIELDS="event,callfunction" />
</KEYS>
</TABLE>
<TABLE NAME="institution">
<FIELDS>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true"/>
......
......@@ -1301,6 +1301,22 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2008091600) {
$table = new XMLDBTable('event_subscription');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED,
XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('event', XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, XMLDB_NOTNULL);
$table->addFieldInfo('callfunction', XMLDB_TYPE_CHAR, 255, XMLDB_UNSIGNED, XMLDB_NOTNULL);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('eventfk', XMLDB_KEY_FOREIGN, array('event'), 'event_type', array('name'));
$table->addKeyInfo('subscruk', XMLDB_KEY_UNIQUE, array('event', 'callfunction'));
create_table($table);
insert_record('event_subscription', (object)array('event' => 'createuser', 'callfunction' => 'activity_set_defaults'));
}
return $status;
}
......
......@@ -1013,10 +1013,16 @@ function handle_event($event, $data) {
$data = array('id' => $data);
}
// this is here because the core can't listen to events
// @todo, this is VERY ugly, and someone should fix it
if ($event == 'createuser') {
activity_set_defaults($data['id']);
if ($coreevents = get_records_array('event_subscription', 'event', $event)) {
foreach ($coreevents as $ce) {
if (function_exists($ce->callfunction)) {
call_user_func($ce->callfunction, $data);
}
else {
log_warn("Event $event caused a problem with a core subscription "
. " $ce->callfunction, which wasn't callable. Continuing with event handlers");
}
}
}
$plugintypes = plugin_types_installed();
......
......@@ -659,6 +659,18 @@ function core_install_firstcoredata_defaults() {
insert_record('event_type', $e);
}
// install the core event subscriptions
$subs = array(
array(
'event' => 'createuser',
'callfunction' => 'activity_set_defaults',
)
);
foreach ($subs as $sub) {
insert_record('event_subscription', (object)$sub);
}
// install the activity types
$activitytypes = array(
array('maharamessage', 0, 0),
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2008091500;
$config->version = 2008091600;
$config->release = '1.1.0alpha2dev';
$config->minupgradefrom = 2007080700;
$config->minupgraderelease = '0.8.0 (release tag 0.8.0_RELEASE)';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment