diff --git a/enrol/paypal/ipn.php b/enrol/paypal/ipn.php index a686f138fa2..388b9b7dbf2 100644 --- a/enrol/paypal/ipn.php +++ b/enrol/paypal/ipn.php @@ -35,7 +35,6 @@ define('NO_DEBUG_DISPLAY', true); // @codingStandardsIgnoreLine This script does not require login. require("../../config.php"); require_once("lib.php"); -require_once($CFG->libdir.'/eventslib.php'); require_once($CFG->libdir.'/enrollib.php'); require_once($CFG->libdir . '/filelib.php'); diff --git a/error/index.php b/error/index.php index 2e3280d70e4..dbb69cd3c0e 100644 --- a/error/index.php +++ b/error/index.php @@ -1,7 +1,6 @@ libdir.'/eventslib.php'); // Form submitted, do not check referer (original page unknown). if ($form = data_submitted()) { diff --git a/lib/adminlib.php b/lib/adminlib.php index c3e39cd1e1f..0c7b15667da 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -234,9 +234,6 @@ function uninstall_plugin($type, $name) { // delete the capabilities that were defined by this module capabilities_cleanup($component); - // remove event handlers and dequeue pending events - events_uninstall($component); - // Delete all remaining files in the filepool owned by the component. $fs = get_file_storage(); $fs->delete_component_files($component); diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index f025079e910..73e49b3c611 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -6607,3 +6607,136 @@ function groups_get_all_groups_for_courses($courses) { return $groups; } + +/** + * Gets the capabilities that have been cached in the database for this + * component. + * @deprecated since Moodle 3.6. Please use the Events 2 API. + * @todo final deprecation. To be removed in Moodle 4.0 + * + * @access protected To be used from eventslib only + * + * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results' + * @return array of events + */ +function events_get_cached($component) { + global $DB; + + debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.', + DEBUG_DEVELOPER); + + $cachedhandlers = array(); + + if ($storedhandlers = $DB->get_records('events_handlers', array('component'=>$component))) { + foreach ($storedhandlers as $handler) { + $cachedhandlers[$handler->eventname] = array ( + 'id' => $handler->id, + 'handlerfile' => $handler->handlerfile, + 'handlerfunction' => $handler->handlerfunction, + 'schedule' => $handler->schedule, + 'internal' => $handler->internal); + } + } + + return $cachedhandlers; +} + +/** + * Remove all event handlers and queued events + * @deprecated since Moodle 3.6. Please use the Events 2 API. + * @todo final deprecation. To be removed in Moodle 4.0 + * + * @category event + * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results' + */ +function events_uninstall($component) { + debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.', + DEBUG_DEVELOPER); + $cachedhandlers = events_get_cached($component); + events_cleanup($component, $cachedhandlers); + + events_get_handlers('reset'); +} + +/** + * Deletes cached events that are no longer needed by the component. + * @deprecated since Moodle 3.6. Please use the Events 2 API. + * @todo final deprecation. To be removed in Moodle 4.0 + * + * @access protected To be used from eventslib only + * + * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results' + * @param array $cachedhandlers array of the cached events definitions that will be + * @return int number of unused handlers that have been removed + */ +function events_cleanup($component, $cachedhandlers) { + global $DB; + debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.', + DEBUG_DEVELOPER); + $deletecount = 0; + foreach ($cachedhandlers as $eventname => $cachedhandler) { + if ($qhandlers = $DB->get_records('events_queue_handlers', array('handlerid'=>$cachedhandler['id']))) { + //debugging("Removing pending events from queue before deleting of event handler: $component - $eventname"); + foreach ($qhandlers as $qhandler) { + events_dequeue($qhandler); + } + } + $DB->delete_records('events_handlers', array('eventname'=>$eventname, 'component'=>$component)); + $deletecount++; + } + + return $deletecount; +} + +/** + * Removes this queued handler from the events_queued_handler table + * + * Removes events_queue record from events_queue if no more references to this event object exists + * @deprecated since Moodle 3.6. Please use the Events 2 API. + * @todo final deprecation. To be removed in Moodle 4.0 + * + * @access protected To be used from eventslib only + * + * @param stdClass $qhandler A row from the events_queued_handler table + */ +function events_dequeue($qhandler) { + global $DB; + debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.', + DEBUG_DEVELOPER); + // first delete the queue handler + $DB->delete_records('events_queue_handlers', array('id'=>$qhandler->id)); + + // if no more queued handler is pointing to the same event - delete the event too + if (!$DB->record_exists('events_queue_handlers', array('queuedeventid'=>$qhandler->queuedeventid))) { + $DB->delete_records('events_queue', array('id'=>$qhandler->queuedeventid)); + } +} + +/** + * Returns handlers for given event. Uses caching for better perf. + * @deprecated since Moodle 3.6. Please use the Events 2 API. + * @todo final deprecation. To be removed in Moodle 4.0 + * + * @access protected To be used from eventslib only + * + * @staticvar array $handlers + * @param string $eventname name of event or 'reset' + * @return array|false array of handlers or false otherwise + */ +function events_get_handlers($eventname) { + global $DB; + static $handlers = array(); + debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.', + DEBUG_DEVELOPER); + + if ($eventname === 'reset') { + $handlers = array(); + return false; + } + + if (!array_key_exists($eventname, $handlers)) { + $handlers[$eventname] = $DB->get_records('events_handlers', array('eventname'=>$eventname)); + } + + return $handlers[$eventname]; +} diff --git a/lib/eventslib.php b/lib/eventslib.php deleted file mode 100644 index 2474aa1313b..00000000000 --- a/lib/eventslib.php +++ /dev/null @@ -1,141 +0,0 @@ -. - -/** - * Library of functions for events manipulation. - * - * The public API is all at the end of this file. - * - * @package core - * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Gets the capabilities that have been cached in the database for this - * component. - * - * @access protected To be used from eventslib only - * - * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results' - * @return array of events - */ -function events_get_cached($component) { - global $DB; - - $cachedhandlers = array(); - - if ($storedhandlers = $DB->get_records('events_handlers', array('component'=>$component))) { - foreach ($storedhandlers as $handler) { - $cachedhandlers[$handler->eventname] = array ( - 'id' => $handler->id, - 'handlerfile' => $handler->handlerfile, - 'handlerfunction' => $handler->handlerfunction, - 'schedule' => $handler->schedule, - 'internal' => $handler->internal); - } - } - - return $cachedhandlers; -} - -/** - * 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'); -} - -/** - * Deletes cached events that are no longer needed by the component. - * - * @access protected To be used from eventslib only - * - * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results' - * @param array $cachedhandlers array of the cached events definitions that will be - * @return int number of unused handlers that have been removed - */ -function events_cleanup($component, $cachedhandlers) { - global $DB; - - $deletecount = 0; - foreach ($cachedhandlers as $eventname => $cachedhandler) { - if ($qhandlers = $DB->get_records('events_queue_handlers', array('handlerid'=>$cachedhandler['id']))) { - //debugging("Removing pending events from queue before deleting of event handler: $component - $eventname"); - foreach ($qhandlers as $qhandler) { - events_dequeue($qhandler); - } - } - $DB->delete_records('events_handlers', array('eventname'=>$eventname, 'component'=>$component)); - $deletecount++; - } - - return $deletecount; -} - -/** - * Removes this queued handler from the events_queued_handler table - * - * Removes events_queue record from events_queue if no more references to this event object exists - * - * @access protected To be used from eventslib only - * - * @param stdClass $qhandler A row from the events_queued_handler table - */ -function events_dequeue($qhandler) { - global $DB; - - // first delete the queue handler - $DB->delete_records('events_queue_handlers', array('id'=>$qhandler->id)); - - // if no more queued handler is pointing to the same event - delete the event too - if (!$DB->record_exists('events_queue_handlers', array('queuedeventid'=>$qhandler->queuedeventid))) { - $DB->delete_records('events_queue', array('id'=>$qhandler->queuedeventid)); - } -} - -/** - * Returns handlers for given event. Uses caching for better perf. - * - * @access protected To be used from eventslib only - * - * @staticvar array $handlers - * @param string $eventname name of event or 'reset' - * @return array|false array of handlers or false otherwise - */ -function events_get_handlers($eventname) { - global $DB; - static $handlers = array(); - - if ($eventname === 'reset') { - $handlers = array(); - return false; - } - - if (!array_key_exists($eventname, $handlers)) { - $handlers[$eventname] = $DB->get_records('events_handlers', array('eventname'=>$eventname)); - } - - return $handlers[$eventname]; -} diff --git a/lib/phpunit/classes/util.php b/lib/phpunit/classes/util.php index 3252bf6854d..965ce0f0584 100644 --- a/lib/phpunit/classes/util.php +++ b/lib/phpunit/classes/util.php @@ -210,7 +210,6 @@ class phpunit_util extends testing_util { accesslib_clear_all_caches(true); get_string_manager()->reset_caches(true); reset_text_filters_cache(true); - events_get_handlers('reset'); core_text::reset_caches(); get_message_processors(false, true, true); filter_manager::reset_caches(); diff --git a/lib/setup.php b/lib/setup.php index 8ee0219486f..1fc52f0a7f5 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -606,7 +606,6 @@ require_once($CFG->libdir .'/moodlelib.php'); // Other general-purpose fun require_once($CFG->libdir .'/enrollib.php'); // Enrolment related functions require_once($CFG->libdir .'/pagelib.php'); // Library that defines the moodle_page class, used for $PAGE require_once($CFG->libdir .'/blocklib.php'); // Library for controlling blocks -require_once($CFG->libdir .'/eventslib.php'); // Events functions require_once($CFG->libdir .'/grouplib.php'); // Groups functions require_once($CFG->libdir .'/sessionlib.php'); // All session and cookie related stuff require_once($CFG->libdir .'/editorlib.php'); // All text editor related functions and classes diff --git a/lib/tests/eventslib_test.php b/lib/tests/eventslib_test.php index 9f5f0005db2..ed6cfc218ed 100644 --- a/lib/tests/eventslib_test.php +++ b/lib/tests/eventslib_test.php @@ -53,7 +53,7 @@ class core_eventslib_testcase extends advanced_testcase { global $DB; events_update_definition('unittest'); - $this->assertDebuggingCalled(self::DEBUGGING_MSG, DEBUG_DEVELOPER); + $this->assertDebuggingCalledCount(4); $dbcount = $DB->count_records('events_handlers', array('component'=>'unittest')); $handlers = array(); @@ -68,9 +68,10 @@ class core_eventslib_testcase extends advanced_testcase { global $DB; events_update_definition('unittest'); - $this->assertDebuggingCalled(self::DEBUGGING_MSG, DEBUG_DEVELOPER); + $this->assertDebuggingCalledCount(4); events_uninstall('unittest'); + $this->assertDebuggingCalledCount(4); $this->assertEquals(0, $DB->count_records('events_handlers', array('component'=>'unittest')), 'All handlers should be uninstalled: %s'); } @@ -81,7 +82,7 @@ class core_eventslib_testcase extends advanced_testcase { global $DB; events_update_definition('unittest'); - $this->assertDebuggingCalled(self::DEBUGGING_MSG, DEBUG_DEVELOPER); + $this->assertDebuggingCalledCount(4); // First modify directly existing handler. $handler = $DB->get_record('events_handlers', array('component'=>'unittest', 'eventname'=>'test_instant')); @@ -93,7 +94,7 @@ class core_eventslib_testcase extends advanced_testcase { // Update the definition, it should revert the handler back. events_update_definition('unittest'); - $this->assertDebuggingCalled(self::DEBUGGING_MSG, DEBUG_DEVELOPER); + $this->assertDebuggingCalledCount(4); $handler = $DB->get_record('events_handlers', array('component'=>'unittest', 'eventname'=>'test_instant')); $this->assertSame($handler->handlerfunction, $original, 'update should sync db with file definition: %s'); } diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 565a8081189..6153094eaea 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -23,6 +23,12 @@ information provided here is intended especially for developers. - I set the field "" to multiline - I follow """ in the open menu * Removed the lib/password_compat/lib/password.php file. +* The eventslib.php file has been deleted and its functions have been moved to deprecatedlib.php. The affected functions are: + - events_get_cached() + - events_uninstall() + - events_cleanup() + - events_dequeue() + - events_get_handlers() === 3.5 === diff --git a/lib/upgradelib.php b/lib/upgradelib.php index 8dc6d316569..802fb25b300 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -573,7 +573,6 @@ function upgrade_plugins($type, $startcallback, $endcallback, $verbose) { update_capabilities($component); log_update_descriptions($component); external_update_descriptions($component); - events_update_definition($component); \core\task\manager::reset_scheduled_tasks_for_component($component); message_update_providers($component); \core\message\inbound\manager::update_handlers_for_component($component); @@ -612,7 +611,6 @@ function upgrade_plugins($type, $startcallback, $endcallback, $verbose) { update_capabilities($component); log_update_descriptions($component); external_update_descriptions($component); - events_update_definition($component); \core\task\manager::reset_scheduled_tasks_for_component($component); message_update_providers($component); \core\message\inbound\manager::update_handlers_for_component($component); @@ -646,7 +644,6 @@ function upgrade_plugins($type, $startcallback, $endcallback, $verbose) { update_capabilities($component); log_update_descriptions($component); external_update_descriptions($component); - events_update_definition($component); \core\task\manager::reset_scheduled_tasks_for_component($component); message_update_providers($component); \core\message\inbound\manager::update_handlers_for_component($component); @@ -754,7 +751,6 @@ function upgrade_plugins_modules($startcallback, $endcallback, $verbose) { update_capabilities($component); log_update_descriptions($component); external_update_descriptions($component); - events_update_definition($component); \core\task\manager::reset_scheduled_tasks_for_component($component); message_update_providers($component); \core\message\inbound\manager::update_handlers_for_component($component); @@ -789,7 +785,6 @@ function upgrade_plugins_modules($startcallback, $endcallback, $verbose) { update_capabilities($component); log_update_descriptions($component); external_update_descriptions($component); - events_update_definition($component); \core\task\manager::reset_scheduled_tasks_for_component($component); message_update_providers($component); \core\message\inbound\manager::update_handlers_for_component($component); @@ -826,7 +821,6 @@ function upgrade_plugins_modules($startcallback, $endcallback, $verbose) { update_capabilities($component); log_update_descriptions($component); external_update_descriptions($component); - events_update_definition($component); \core\task\manager::reset_scheduled_tasks_for_component($component); message_update_providers($component); \core\message\inbound\manager::update_handlers_for_component($component); @@ -948,7 +942,6 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) { update_capabilities($component); log_update_descriptions($component); external_update_descriptions($component); - events_update_definition($component); \core\task\manager::reset_scheduled_tasks_for_component($component); message_update_providers($component); \core\message\inbound\manager::update_handlers_for_component($component); @@ -989,7 +982,6 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) { update_capabilities($component); log_update_descriptions($component); external_update_descriptions($component); - events_update_definition($component); \core\task\manager::reset_scheduled_tasks_for_component($component); message_update_providers($component); \core\message\inbound\manager::update_handlers_for_component($component); @@ -1025,7 +1017,6 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) { update_capabilities($component); log_update_descriptions($component); external_update_descriptions($component); - events_update_definition($component); \core\task\manager::reset_scheduled_tasks_for_component($component); message_update_providers($component); \core\message\inbound\manager::update_handlers_for_component($component); @@ -1742,7 +1733,6 @@ function install_core($version, $verbose) { // Continue with the installation log_update_descriptions('moodle'); external_update_descriptions('moodle'); - events_update_definition('moodle'); \core\task\manager::reset_scheduled_tasks_for_component('moodle'); message_update_providers('moodle'); \core\message\inbound\manager::update_handlers_for_component('moodle'); @@ -1810,7 +1800,6 @@ function upgrade_core($version, $verbose) { update_capabilities('moodle'); log_update_descriptions('moodle'); external_update_descriptions('moodle'); - events_update_definition('moodle'); \core\task\manager::reset_scheduled_tasks_for_component('moodle'); message_update_providers('moodle'); \core\message\inbound\manager::update_handlers_for_component('moodle'); diff --git a/message/lib.php b/message/lib.php index 48c3686ad49..2c1df4ad8a2 100644 --- a/message/lib.php +++ b/message/lib.php @@ -22,8 +22,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -require_once($CFG->libdir.'/eventslib.php'); - define('MESSAGE_SHORTLENGTH', 300); define('MESSAGE_HISTORY_ALL', 1); diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 55f734cbbec..566c386aa1d 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -87,7 +87,6 @@ require_once($CFG->dirroot . '/mod/assign/feedbackplugin.php'); require_once($CFG->dirroot . '/mod/assign/submissionplugin.php'); require_once($CFG->dirroot . '/mod/assign/renderable.php'); require_once($CFG->dirroot . '/mod/assign/gradingtable.php'); -require_once($CFG->libdir . '/eventslib.php'); require_once($CFG->libdir . '/portfolio/caller.php'); use \mod_assign\output\grading_app; diff --git a/mod/assign/submission/file/locallib.php b/mod/assign/submission/file/locallib.php index 3b1959bf7f3..99b0309c012 100644 --- a/mod/assign/submission/file/locallib.php +++ b/mod/assign/submission/file/locallib.php @@ -24,8 +24,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -require_once($CFG->libdir.'/eventslib.php'); - defined('MOODLE_INTERNAL') || die(); // File areas for file submission assignment. diff --git a/mod/feedback/lib.php b/mod/feedback/lib.php index 0881cc9b868..0b2d3e534e7 100644 --- a/mod/feedback/lib.php +++ b/mod/feedback/lib.php @@ -25,8 +25,6 @@ defined('MOODLE_INTERNAL') || die(); -/** Include eventslib.php */ -require_once($CFG->libdir.'/eventslib.php'); // Include forms lib. require_once($CFG->libdir.'/formslib.php'); diff --git a/mod/forum/lib.php b/mod/forum/lib.php index e97ad191c28..d032f5756a6 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -25,7 +25,6 @@ defined('MOODLE_INTERNAL') || die(); /** Include required files */ require_once(__DIR__ . '/deprecatedlib.php'); require_once($CFG->libdir.'/filelib.php'); -require_once($CFG->libdir.'/eventslib.php'); /// CONSTANTS /////////////////////////////////////////////////////////// diff --git a/mod/lesson/essay.php b/mod/lesson/essay.php index a67623c2c23..19382e9d8fa 100644 --- a/mod/lesson/essay.php +++ b/mod/lesson/essay.php @@ -27,7 +27,6 @@ require_once('../../config.php'); require_once($CFG->dirroot.'/mod/lesson/locallib.php'); require_once($CFG->dirroot.'/mod/lesson/pagetypes/essay.php'); require_once($CFG->dirroot.'/mod/lesson/essay_form.php'); -require_once($CFG->libdir.'/eventslib.php'); $id = required_param('id', PARAM_INT); // Course Module ID $mode = optional_param('mode', 'display', PARAM_ALPHA); diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index dfa3046f806..a8caba469d2 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -28,7 +28,6 @@ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir . '/eventslib.php'); require_once($CFG->dirroot . '/calendar/lib.php'); diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index f6c72d6f89c..e27fbc8aeab 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -37,7 +37,6 @@ require_once($CFG->dirroot . '/mod/quiz/accessmanager_form.php'); require_once($CFG->dirroot . '/mod/quiz/renderer.php'); require_once($CFG->dirroot . '/mod/quiz/attemptlib.php'); require_once($CFG->libdir . '/completionlib.php'); -require_once($CFG->libdir . '/eventslib.php'); require_once($CFG->libdir . '/filelib.php'); require_once($CFG->libdir . '/questionlib.php');