Beispiel #1
0
/**
 * Function to call all event handlers when triggering an event
 *
 * @deprecated since 2.6
 *
 * @param string $eventname name of the event
 * @param mixed $eventdata event data object
 * @return int number of failed events
 */
function events_trigger($eventname, $eventdata)
{
    debugging('events_trigger() is deprecated, please use new events instead', DEBUG_DEVELOPER);
    return events_trigger_legacy($eventname, $eventdata);
}
Beispiel #2
0
 /**
  * Trigger event.
  */
 public final function trigger()
 {
     global $CFG;
     if ($this->restored) {
         throw new \coding_exception('Can not trigger restored event');
     }
     if ($this->triggered or $this->dispatched) {
         throw new \coding_exception('Can not trigger event twice');
     }
     $this->validate_before_trigger();
     $this->triggered = true;
     if (isset($CFG->loglifetime) and $CFG->loglifetime != -1) {
         if ($data = $this->get_legacy_logdata()) {
             call_user_func_array('add_to_log', $data);
         }
     }
     if (PHPUNIT_TEST and \phpunit_util::is_redirecting_events()) {
         $this->dispatched = true;
         \phpunit_util::event_triggered($this);
         return;
     }
     \core\event\manager::dispatch($this);
     $this->dispatched = true;
     if ($legacyeventname = static::get_legacy_eventname()) {
         events_trigger_legacy($legacyeventname, $this->get_legacy_eventdata());
     }
 }
Beispiel #3
0
 /**
  * Trigger event.
  */
 public final function trigger()
 {
     global $CFG;
     if ($this->restored) {
         throw new \coding_exception('Can not trigger restored event');
     }
     if ($this->triggered or $this->dispatched) {
         throw new \coding_exception('Can not trigger event twice');
     }
     $this->validate_before_trigger();
     $this->triggered = true;
     if (isset($CFG->loglifetime) and $CFG->loglifetime != -1) {
         if ($data = $this->get_legacy_logdata()) {
             $manager = get_log_manager();
             if (method_exists($manager, 'legacy_add_to_log')) {
                 if (is_array($data[0])) {
                     // Some events require several entries in 'log' table.
                     foreach ($data as $d) {
                         call_user_func_array(array($manager, 'legacy_add_to_log'), $d);
                     }
                 } else {
                     call_user_func_array(array($manager, 'legacy_add_to_log'), $data);
                 }
             }
         }
     }
     if (PHPUNIT_TEST and \phpunit_util::is_redirecting_events()) {
         $this->dispatched = true;
         \phpunit_util::event_triggered($this);
         return;
     }
     \core\event\manager::dispatch($this);
     $this->dispatched = true;
     if ($legacyeventname = static::get_legacy_eventname()) {
         events_trigger_legacy($legacyeventname, $this->get_legacy_eventdata());
     }
 }
Beispiel #4
0
/**
 * Delete all groupings from course
 *
 * @param int $courseid
 * @param bool $showfeedback
 * @return bool success
 */
function groups_delete_groupings($courseid, $showfeedback = false)
{
    global $DB, $OUTPUT;
    $groupings = $DB->get_recordset_select('groupings', 'courseid = ?', array($courseid));
    foreach ($groupings as $grouping) {
        groups_delete_grouping($grouping);
    }
    // Invalidate the grouping cache for the course.
    cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($courseid));
    // TODO MDL-41312 Remove events_trigger_legacy('groups_groupings_deleted').
    // This event is kept here for backwards compatibility, because it cannot be
    // translated to a new event as it is wrong.
    events_trigger_legacy('groups_groupings_deleted', $courseid);
    if ($showfeedback) {
        echo $OUTPUT->notification(get_string('deleted') . ' - ' . get_string('groupings', 'group'), 'notifysuccess');
    }
    return true;
}
Beispiel #5
0
 /**
  * Tests events_trigger_legacy() function when instant handler fails.
  */
 public function test_events_trigger__failed_instant()
 {
     global $CFG;
     events_update_definition('unittest');
     $this->assertDebuggingCalled(self::DEBUGGING_MSG, DEBUG_DEVELOPER);
     $olddebug = $CFG->debug;
     $this->assertEquals(1, events_trigger_legacy('test_instant', 'fail'), 'fail first event: %s');
     $this->assertDebuggingCalled(self::DEBUGGING_MSG, DEBUG_DEVELOPER);
     $this->assertEquals(1, events_trigger_legacy('test_instant', 'ok'), 'this one should fail too: %s');
     $this->assertDebuggingNotCalled();
     $this->assertEquals(0, events_cron('test_instant'), 'all events should stay in queue: %s');
     // events_cron + one for each dispatched event.
     $this->assertDebuggingCalledCount(3);
     $this->assertEquals(2, events_pending_count('test_instant'), 'two events should in queue: %s');
     $this->assertDebuggingCalled('events_pending_count() has been deprecated along with all Events 1 API in favour of Events 2' . ' API, please use it instead.', DEBUG_DEVELOPER);
     $this->assertEquals(0, eventslib_sample_function_handler('status'), 'verify no event dispatched yet: %s');
     eventslib_sample_function_handler('ignorefail');
     // Ignore "fail" eventdata from now on.
     $this->assertEquals(1, events_trigger_legacy('test_instant', 'ok'), 'this one should go to queue directly: %s');
     $this->assertDebuggingNotCalled();
     $this->assertEquals(3, events_pending_count('test_instant'), 'three events should in queue: %s');
     $this->assertDebuggingCalled('events_pending_count() has been deprecated along with all Events 1 API in favour of Events 2' . ' API, please use it instead.', DEBUG_DEVELOPER);
     $this->assertEquals(0, eventslib_sample_function_handler('status'), 'verify previous event was not dispatched: %s');
     $this->assertEquals(3, events_cron('test_instant'), 'all events should be dispatched: %s');
     // events_cron + one for each dispatched event.
     $this->assertDebuggingCalledCount(4);
     $this->assertEquals(3, eventslib_sample_function_handler('status'), 'verify three events were dispatched: %s');
     $this->assertEquals(0, events_pending_count('test_instant'), 'no events should in queue: %s');
     $this->assertDebuggingCalled('events_pending_count() has been deprecated along with all Events 1 API in favour of Events 2' . ' API, please use it instead.', DEBUG_DEVELOPER);
     $this->assertEquals(0, events_trigger_legacy('test_instant', 'ok'), 'this event should be dispatched immediately: %s');
     $this->assertDebuggingCalled(self::DEBUGGING_MSG, DEBUG_DEVELOPER);
     $this->assertEquals(4, eventslib_sample_function_handler('status'), 'verify event was dispatched: %s');
     $this->assertEquals(0, events_pending_count('test_instant'), 'no events should in queue: %s');
     $this->assertDebuggingCalled('events_pending_count() has been deprecated along with all Events 1 API in favour of Events 2' . ' API, please use it instead.', DEBUG_DEVELOPER);
 }
/**
 * Function to call all event handlers when triggering an event
 *
 * @deprecated since 2.6
 *
 * @param string $eventname name of the event
 * @param mixed $eventdata event data object
 * @return int number of failed events
 */
function events_trigger($eventname, $eventdata)
{
    // TODO: uncomment after conversion of all events in standard distribution
    // debugging('events_trigger() is deprecated, please use new events instead', DEBUG_DEVELOPER);
    return events_trigger_legacy($eventname, $eventdata);
}
Beispiel #7
0
 /**
  * Tests events_trigger_legacy() function when instant handler fails.
  */
 public function test_events_trigger__failed_instant()
 {
     global $CFG;
     $olddebug = $CFG->debug;
     $this->assertEquals(1, events_trigger_legacy('test_instant', 'fail'), 'fail first event: %s');
     $this->assertEquals(1, events_trigger_legacy('test_instant', 'ok'), 'this one should fail too: %s');
     $this->assertEquals(0, events_cron('test_instant'), 'all events should stay in queue: %s');
     $this->assertDebuggingCalled();
     $this->assertEquals(2, events_pending_count('test_instant'), 'two events should in queue: %s');
     $this->assertEquals(0, eventslib_sample_function_handler('status'), 'verify no event dispatched yet: %s');
     eventslib_sample_function_handler('ignorefail');
     // Ignore "fail" eventdata from now on.
     $this->assertEquals(1, events_trigger_legacy('test_instant', 'ok'), 'this one should go to queue directly: %s');
     $this->assertEquals(3, events_pending_count('test_instant'), 'three events should in queue: %s');
     $this->assertEquals(0, eventslib_sample_function_handler('status'), 'verify previous event was not dispatched: %s');
     $this->assertEquals(3, events_cron('test_instant'), 'all events should be dispatched: %s');
     $this->assertEquals(3, eventslib_sample_function_handler('status'), 'verify three events were dispatched: %s');
     $this->assertEquals(0, events_pending_count('test_instant'), 'no events should in queue: %s');
     $this->assertEquals(0, events_trigger_legacy('test_instant', 'ok'), 'this event should be dispatched immediately: %s');
     $this->assertEquals(4, eventslib_sample_function_handler('status'), 'verify event was dispatched: %s');
     $this->assertEquals(0, events_pending_count('test_instant'), 'no events should in queue: %s');
 }
Beispiel #8
0
 /**
  * Processes the 'queueornext' stage of the export
  *
  * @return bool whether or not to process the next stage. this is important as the control function is called recursively.
  */
 public function process_stage_queueorwait()
 {
     $wait = $this->instance->get_export_config('wait');
     if (empty($wait)) {
         // TODO MDL-42541 Removing usage of events_trigger().
         events_trigger_legacy('portfolio_send', $this->id);
         $this->queued = true;
         return $this->process_stage_finished(true);
     }
     return true;
 }