Skip to content

Variable injection does not always work as expected #3763

@browniebraun

Description

@browniebraun

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUndesired behaviourresolvedA fixed issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions