diff options
Diffstat (limited to 'classes/task')
-rw-r--r-- | classes/task/process_events_task.php | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/classes/task/process_events_task.php b/classes/task/process_events_task.php index 84b5c88..02e54a2 100644 --- a/classes/task/process_events_task.php +++ b/classes/task/process_events_task.php @@ -24,7 +24,11 @@ namespace local_webhooks\task; -defined( "MOODLE_INTERNAL" ) || die(); +global $CFG; + +require_once $CFG->dirroot . '/local/webhooks/lib.php'; + +defined('MOODLE_INTERNAL') || die(); /** * Class process_events_task @@ -36,26 +40,25 @@ defined( "MOODLE_INTERNAL" ) || die(); class process_events_task extends \core\task\adhoc_task { /** * Task handler. + * + * @throws \dml_exception + * @throws \moodle_exception */ public function execute() { - global $CFG; - - require_once( $CFG->dirroot . "/local/webhooks/lib.php" ); - - $services = \local_webhooks_api::get_services_by_event( $this->get_custom_data()->eventname ); + $services = \local_webhooks_api::get_services_by_event($this->get_custom_data()->eventname); - foreach ( $services as $service ) { - if ( empty( $service->status ) ) { + foreach ($services as $service) { + if ((bool) $service->status !== true) { return; } $curl = new \curl(); $event = (array) $this->get_custom_data(); - $event[ "token" ] = $service->token; + $event['token'] = $service->token; - $curl->setHeader( array( "Content-Type: " . $service->header ) ); - $curl->post( $service->point, json_encode( $event ) ); + $curl->setHeader(array('Content-Type: ' . $service->header)); + $curl->post($service->point, json_encode($event)); // TODO: Mark the log $curl->getResponse(); |