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

createTicket respects alert/autorespond negatives #1435

Merged
merged 2 commits into from Dec 24, 2014
Merged

createTicket respects alert/autorespond negatives #1435

merged 2 commits into from Dec 24, 2014

Conversation

stevepacker
Copy link
Contributor

It was previously not possible to use the alert and autorespond flags in a negative way to prevent those two events, since the ternary operator would have used the false ternary value, which was true. This corrects that by allowing the default of true to be used only when the $data array does not have the appropriate keys set. Assigning $data['source'] was altered to use the same formatting and caution against an undefined index error.

It was previously not possible to use the `alert` and `autorespond` flags in a negative way to prevent those two events, since the ternary operator would have used the `false` ternary value, which was `true`.  This corrects that by allowing the default of `true` to be used only when the `$data` array does not have the appropriate keys set.  Assigning `$data['source']` was altered to use the same formatting and caution against an undefined index error.
$data['source'] = $data['source'] ? $data['source'] : 'API';
$alert = array_key_exists('alert', $data) ? $data['alert'] : true;
$autorespond = array_key_exists('autorespond', $data) ? $data['autorespond'] : true;
$data['source'] = array_key_exists('source', $data) ? $data['source'] : 'API';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary, right? You would never want to send false for the source, would you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$data['source'] was unrelated to the "false" fix. Since it was in the same code block, I thought it would have less code smell by formatting it in the same way while also preventing a possible undefined index error if the $data ever didn't include that value.

@protich
Copy link
Member

protich commented Nov 16, 2014

I'll advocate using isset instead of array_key_exists - The former returns false on NULL value - which is correct in my opinion since we are testing for boolean true/false.

@stevepacker
Copy link
Contributor Author

In that case, it's probably better to type-cast the value; the only way I see to provide a NULL value is via the JSON payload. Different means to the same end.

In the process of patching the patch, I think there's a case where an XML payload (according to the example in https://github.com/osTicket/osTicket-1.8/blob/develop/setup/doc/api.md ) will send a scalar "false" that should be interpreted as a boolean false too. I'll patch accordingly.

- Allows the string "false" to be used in the XML payload as the documentation demonstrates, and have that be interpreted as a boolean false.
- Switching $alert/$autorespond to use isset(), and forcing those variables to be type-casted to booleans.
@greezybacon
Copy link
Contributor

@stevepacker thanks for the patch

protich added a commit that referenced this pull request Dec 24, 2014
createTicket respects alert/autorespond negatives

Reviewed-By: Peter Rotich <peter@osticket.com>
@protich protich merged commit 50e0df5 into osTicket:develop Dec 24, 2014
@stevepacker stevepacker deleted the patch-1 branch December 31, 2014 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants