/** * Remove all event handlers and queued events * * @category event * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results' */ function events_uninstall($component) { $cachedhandlers = events_get_cached($component); events_cleanup($component, $cachedhandlers); events_get_handlers('reset'); }
/** * Updates all of the event definitions within the database. * * Unfortunately this isn't as simple as removing them all and then readding * the updated event definitions. Chances are queued items are referencing the * existing definitions. * * Note that the absence of the db/events.php event definition file * will cause any queued events for the component to be removed from * the database. * * @category event * @deprecated since Moodle 3.1 * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results' * @return boolean always returns true */ function events_update_definition($component = 'moodle') { global $DB; // load event definition from events.php $filehandlers = events_load_def($component); if ($filehandlers) { debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.', DEBUG_DEVELOPER); } // load event definitions from db tables // if we detect an event being already stored, we discard from this array later // the remaining needs to be removed $cachedhandlers = events_get_cached($component); foreach ($filehandlers as $eventname => $filehandler) { if (!empty($cachedhandlers[$eventname])) { if ($cachedhandlers[$eventname]['handlerfile'] === $filehandler['handlerfile'] && $cachedhandlers[$eventname]['handlerfunction'] === serialize($filehandler['handlerfunction']) && $cachedhandlers[$eventname]['schedule'] === $filehandler['schedule'] && $cachedhandlers[$eventname]['internal'] == $filehandler['internal']) { // exact same event handler already present in db, ignore this entry unset($cachedhandlers[$eventname]); continue; } else { // same event name matches, this event has been updated, update the datebase $handler = new stdClass(); $handler->id = $cachedhandlers[$eventname]['id']; $handler->handlerfile = $filehandler['handlerfile']; $handler->handlerfunction = serialize($filehandler['handlerfunction']); // static class methods stored as array $handler->schedule = $filehandler['schedule']; $handler->internal = $filehandler['internal']; $DB->update_record('events_handlers', $handler); unset($cachedhandlers[$eventname]); continue; } } else { // if we are here, this event handler is not present in db (new) // add it $handler = new stdClass(); $handler->eventname = $eventname; $handler->component = $component; $handler->handlerfile = $filehandler['handlerfile']; $handler->handlerfunction = serialize($filehandler['handlerfunction']); // static class methods stored as array $handler->schedule = $filehandler['schedule']; $handler->status = 0; $handler->internal = $filehandler['internal']; $DB->insert_record('events_handlers', $handler); } } // clean up the left overs, the entries in cached events array at this points are deprecated event handlers // and should be removed, delete from db events_cleanup($component, $cachedhandlers); events_get_handlers('reset'); return true; }