diff --git a/classes/steps/actions/http_post_action_step.php b/classes/steps/actions/http_post_action_step.php index d7f5390..b802b11 100644 --- a/classes/steps/actions/http_post_action_step.php +++ b/classes/steps/actions/http_post_action_step.php @@ -156,7 +156,7 @@ public function execute($step, $trigger, $event, $stepresults) { $stepresults['http_response_status_code'] = $response->getStatusCode(); $stepresults['http_response_status_message'] = $response->getReasonPhrase(); - $stepresults['http_response_body'] = $response->getBody(); + $stepresults['http_response_body'] = $response->getBody()->getContents(); if ($response->getStatusCode() != $this->expectedresponse) { // If we weren't expecting this response, throw an exception. diff --git a/classes/steps/filters/stringcompare_filter_step.php b/classes/steps/filters/stringcompare_filter_step.php index d186e68..29267c6 100644 --- a/classes/steps/filters/stringcompare_filter_step.php +++ b/classes/steps/filters/stringcompare_filter_step.php @@ -112,6 +112,11 @@ protected function init() { $this->field2 = $this->data['field2']; $this->operator = $this->data['operator']; $this->wantmatch = (bool) $this->data['wantmatch']; + $this->erroronfail = false; + + if (!empty($this->data['erroronfail'])) { + $this->erroronfail = (bool) $this->data['erroronfail']; + } } /** @@ -161,6 +166,11 @@ public function execute($step, $trigger, $event, $stepresults) { // Check whether they wanted the pattern to match, or not match. $result = ($ismatch == $this->wantmatch); + // Check if we want it to error on failure, and the result was not true. + if (($this->erroronfail == true) && !$result) { + throw new \moodle_exception('erroronfail for stringcompare', 'tool_trigger'); + } + return [$result, $stepresults]; } @@ -212,6 +222,13 @@ public function form_definition_extra($form, $mform, $customdata) { $mform->addGroup($fields, 'stringcomparegroup', '', [' '], false); $mform->addRule('stringcomparegroup', get_string('required'), 'required'); + + // Error instead of failure. + $mform->addElement('advcheckbox', 'erroronfail', get_string ('erroronfail', 'tool_trigger'), + 'Enable', array(), array(0, 1)); + $mform->setType('erroronfail', PARAM_INT); + $mform->addHelpButton('erroronfail', 'erroronfail', 'tool_trigger'); + $mform->setDefault('erroronfail', 0); } /** diff --git a/lang/en/tool_trigger.php b/lang/en/tool_trigger.php index b16e039..e435bef 100644 --- a/lang/en/tool_trigger.php +++ b/lang/en/tool_trigger.php @@ -86,6 +86,8 @@ $string['emailcontent_help'] = 'The content to use in the email'; $string['emailactionstepname'] = 'Email'; $string['emailactionstepdesc'] = 'A step to allow an e-mail to be sent'; +$string['erroronfail'] = 'Error on failure'; +$string['erroronfail_help'] = 'Set the step to error instead of fail'; $string['event'] = 'Event'; $string['eventdescription'] = 'Event description'; $string['eventfields'] = 'Event fields';