diff --git a/inc/inventoryruleimport.class.php b/inc/inventoryruleimport.class.php index b50a97b6a8..8a716fd8e8 100644 --- a/inc/inventoryruleimport.class.php +++ b/inc/inventoryruleimport.class.php @@ -349,8 +349,10 @@ function findWithGlobalCriteria($input) { $sql_from = ''; $sql_where_computer= ''; $sql_where_domain = ''; + $sql_where_model = ''; $sql_from_computer = ''; $sql_from_domain = ''; + $sql_from_model = ''; $continue = TRUE; $entityRestrict = FALSE; $global_criteria = array('model', @@ -477,15 +479,11 @@ function findWithGlobalCriteria($input) { switch ($criteria->fields['criteria']) { case 'model': - $sql_from_temp = " LEFT JOIN `glpi_".strtolower("[typename]")."models` - ON (`glpi_".strtolower("[typename]")."models`.`id` = ". - "`[typetable]`.`".strtolower("[typename]models_id")."` - AND `glpi_networkports`.`itemtype` = '[typename]') "; - $sql_where_temp = " AND `[typetable]`.`".strtolower("[typename]")."models_id` = '". + $sql_from_model = " LEFT JOIN `glpi_[typenamefortable]models` + ON (`glpi_[typenamefortable]models`.`id` = ". + "`[typetable]`.`[typenamefortable]models_id`) "; + $sql_where_model = " AND `[typetable]`.`[typenamefortable]models_id` = '". $input["model"]."'"; - - $sql_from .= $sql_from_temp; - $sql_where .= $sql_where_temp; break; case 'mac': @@ -603,6 +601,11 @@ function findWithGlobalCriteria($input) { $sql_where_temp .= $sql_where_domain; } + if ($itemtype != 'PluginFusioninventoryUnmanaged') { + $sql_from_temp .= $sql_from_model; + $sql_where_temp .= $sql_where_model; + } + if ($entityRestrict) { if (isset($_SESSION['plugin_fusioninventory_entityrestrict'])) { $sql_where_temp .= " AND `[typetable]`.`entities_id`='". @@ -626,6 +629,7 @@ function findWithGlobalCriteria($input) { } $sql_glpi = str_replace("[typetable]", $item->getTable(), $sql_glpi); $sql_glpi = str_replace("[typename]", $itemtype, $sql_glpi); + $sql_glpi = str_replace("[typenamefortable]", strtolower($itemtype), $sql_glpi); PluginFusioninventoryToolbox::logIfExtradebug( "pluginFusioninventory-rules", diff --git a/phpunit/2_Integration/RuleImportTest.php b/phpunit/2_Integration/RuleImportTest.php index c6d014bea0..808844f7e9 100644 --- a/phpunit/2_Integration/RuleImportTest.php +++ b/phpunit/2_Integration/RuleImportTest.php @@ -56,15 +56,43 @@ protected function setUp() { SET `is_active`='0' WHERE `sub_type`='PluginFusioninventoryInventoryRuleImport'"); + $rule = new Rule(); + // Add a rule test check model + $input = array(); + $input['is_active']=1; + $input['name']='Printer model'; + $input['match']='AND'; + $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport'; + $input['ranking'] = 198; + $rule_id = $rule->add($input); + + // Add criteria + $rulecriteria = new RuleCriteria(); + $input = array(); + $input['rules_id'] = $rule_id; + $input['criteria'] = "model"; + $input['pattern']= '1'; + $input['condition']=10; + $rulecriteria->add($input); + + // Add action + $ruleaction = new RuleAction(); + $input = array(); + $input['rules_id'] = $rule_id; + $input['action_type'] = 'assign'; + $input['field'] = '_fusion'; + $input['value'] = '1'; + $ruleaction->add($input); + + // Add a rule to ignore import // Create rule for import into unknown devices - $rule = new Rule(); $input = array(); $input['is_active']=1; $input['name']='Import pinter'; $input['match']='AND'; $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport'; - $input['ranking'] = 198; + $input['ranking'] = 199; $rule_id = $rule->add($input); // Add criteria @@ -113,7 +141,7 @@ protected function setUp() { $input['name']='Import pinter'; $input['match']='AND'; $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport'; - $input['ranking'] = 199; + $input['ranking'] = 200; $rule_id = $rule->add($input); // Add criteria diff --git a/phpunit/2_Integration/RuleLocationTest.php b/phpunit/2_Integration/RuleLocationTest.php index 8879fd02ee..6853960d9f 100644 --- a/phpunit/2_Integration/RuleLocationTest.php +++ b/phpunit/2_Integration/RuleLocationTest.php @@ -100,7 +100,7 @@ public function RegexpRuleResultAssignTest() { $a_references = array( 'locations_id' => 1, - '_ruleid' => 50 + '_ruleid' => $rules_id ); $this->assertEquals($a_references, $loc, 'Location result assign_result'); @@ -159,7 +159,7 @@ public function RegexpRuleResultRegexpTest() { $a_references = array( 'locations_id' => 1, - '_ruleid' => 51 + '_ruleid' => $rules_id ); $this->assertEquals($a_references, $loc, 'Location result regexp_result');