Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP action and Stringcompare filter updates. (master branch) #157

Merged
merged 2 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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