Skip to content

Commit

Permalink
Merge pull request #157 from catalyst/http-and-stringcompare-updates
Browse files Browse the repository at this point in the history
HTTP action and Stringcompare filter updates.
  • Loading branch information
nhoobin authored Nov 5, 2021
2 parents 51899f3 + f8edb18 commit 151ea4d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion classes/steps/actions/http_post_action_step.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions classes/steps/filters/stringcompare_filter_step.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
}

/**
Expand Down Expand Up @@ -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];
}

Expand Down Expand Up @@ -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);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions lang/en/tool_trigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 151ea4d

Please sign in to comment.