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

Variable injection does not always work as expected #3763

Closed
browniebraun opened this issue Aug 19, 2020 · 2 comments
Closed

Variable injection does not always work as expected #3763

browniebraun opened this issue Aug 19, 2020 · 2 comments
Labels
bug Undesired behaviour resolved A fixed issue
Milestone

Comments

@browniebraun
Copy link
Member

Describe the bug

Just checking my plugins before migrating from 1.1.38 to 1.2.14, but it seems to me that the rewrite of inject_form_variables() does not seem to work correctly.

My form had been described like shown below:

'rule_snmp_query' => array(
'friendly_name' => __('Data Query', 'linkit'),
'method' => 'drop_sql',
'max_length' => '255',
'description' => __('The SNMP Query that rule depends on', 'linkit'),
'sql' => 'SELECT b.id, b.name
FROM host_template_snmp_query AS a
INNER JOIN snmp_query AS b
ON b.id = a.snmp_query_id
LEFT JOIN (SELECT * FROM plugin_linkit_auto_template_snmp_query WHERE device_type_id = |arg1:device_type_id|) AS c
ON a.snmp_query_id = c.snmp_query_id
WHERE a.host_template_id = |arg1:host_template_id| AND c.id IS NOT NULL',
'value' => '|arg1:snmp_query_id|',
),

$rule_data given as argument:
(This is a new rule record, that's why the snmp_query_id is zero.)

Array
(
[snmp_query_name] =>
[snmp_query_id] => 0
[device_type_id] => 1
[device_type_name] => Cisco IOS Routers only (No CATOS)
[host_template_id] => 2
[host_template_name] => Cisco Router
)

returns:

[rule_snmp_query] => Array
(
[friendly_name] => Data Query
[method] => drop_sql
[max_length] => 255
[description] => The SNMP Query that rule depends on
[sql] => SELECT b.id, b.name
FROM host_template_snmp_query AS a
INNER JOIN snmp_query AS b
ON b.id = a.snmp_query_id
LEFT JOIN (SELECT * FROM plugin_linkit_auto_template_snmp_query WHERE device_type_id = 1) AS c
ON a.snmp_query_id = c.snmp_query_id
WHERE a.host_template_id = |arg1:host_template_id| AND c.id IS NOT NULL
[value] =>
)

Expected behavior

Quickly replacing that new function by the old one we had in 1.1.38 returns as expected:

[rule_snmp_query] => Array
(
[friendly_name] => Data Query
[method] => drop_sql
[max_length] => 255
[description] => The SNMP Query that rule depends on
[sql] => SELECT b.id, b.name
FROM host_template_snmp_query AS a
INNER JOIN snmp_query AS b
ON b.id = a.snmp_query_id
LEFT JOIN (SELECT * FROM plugin_linkit_auto_template_snmp_query WHERE device_type_id = 1) AS c
ON a.snmp_query_id = c.snmp_query_id
WHERE a.host_template_id = 2 AND c.id IS NOT NULL
[value] => 0
)

Additional context

PHP v7.3.21

@browniebraun browniebraun added bug Undesired behaviour unverified Some days we don't have a clue labels Aug 19, 2020
@TheWitness TheWitness added this to the 1.2.15 milestone Aug 26, 2020
@TheWitness
Copy link
Member

Hmm. Okay. I broke it, I better fix it.

TheWitness added a commit that referenced this issue Aug 30, 2020
Function inject_form_variables not replacing all arguments
@TheWitness
Copy link
Member

That's for the reproduce case. Made this pretty easy to follow. Please test the updated inject_form_variables() function and test again.

@TheWitness TheWitness added resolved A fixed issue and removed unverified Some days we don't have a clue labels Aug 30, 2020
@netniV netniV changed the title 1.2.14 - inject_form_variables not replacing all arguments Variable injection does not always work as expected Nov 2, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Feb 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Undesired behaviour resolved A fixed issue
Projects
None yet
Development

No branches or pull requests

2 participants