General developer forum

Local plugin handlers not working at all

 
Picture of dark jasmines
Local plugin handlers not working at all
 

Hi,

I'm building a simple plugin to handle the event "user completes a course".

This is my structure:

/local/myplugin/db/events.php:

<?php
defined('MOODLE_INTERNAL') || die();
$handlers = array (
    'course_completed' => array (
        'handlerfile'      => '/local/myplugin/lib.php',
        'handlerfunction'  => 'local_myplugin_course_completed',
        'schedule'         => 'instant',
        'internal'         => 1,
    )
);

/local/myplugin/lib.php:

<?php
function local_myplugin_course_completed($eventdata)
{
ob_flush();
ob_start();
var_dump($eventdata);
file_put_contents("dump.txt", ob_get_flush());
}

Well, as in the subject, when a user completes a course, nothing happens...


 
Average of ratings: -
Davo
Re: Local plugin handlers not working at all
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developers

What version of Moodle?

If it's any recent version (2.7? or above), then you should be using observers, not event handlers: https://docs.moodle.org/dev/Event_2#Event_observers


 
Average of ratings: -