Skip to content

Commit

Permalink
No longer rely on state registered types to list rules
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher authored Dec 9, 2024
1 parent 103a18c commit 846fd74
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Glpi/Asset/Capacity/IsInventoriableCapacity.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function onClassBootstrap(string $classname): void
$this->registerToTypeConfig('agent_types', $classname);
$this->registerToTypeConfig('environment_types', $classname);
$this->registerToTypeConfig('process_types', $classname);
$this->registerToTypeConfig('ruleimportasset_types', $classname);

//copy rules from "inventory model" (Computer only for now)

Expand All @@ -117,6 +118,7 @@ public function onCapacityDisabled(string $classname): void
$this->unregisterFromTypeConfig('agent_types', $classname);
$this->unregisterFromTypeConfig('environment_types', $classname);
$this->unregisterFromTypeConfig('process_types', $classname);
$this->unregisterFromTypeConfig('ruleimportasset_types', $classname);

$env_item = new Item_Environment();
$env_item->deleteByCriteria([
Expand Down
2 changes: 1 addition & 1 deletion src/Glpi/Search/SearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static function getMetaItemtypeAvailable($itemtype): array
private static function getMetaParentItemtypesForTypesConfig(string $config_key): array
{
$matches = [];
if (preg_match('/^(.+)_types$/', $config_key, $matches) === 0) {
if (str_contains($config_key, 'rule') || preg_match('/^(.+)_types$/', $config_key, $matches) === 0) {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2468,7 +2468,7 @@ public function displayCriteriaSelectPattern($name, $ID, $condition, $value = ""
break;

case "dropdown_inventory_itemtype":
$types = $CFG_GLPI['state_types'];
$types = $CFG_GLPI['ruleimportasset_types'];
$types[''] = __('No item type defined');
Dropdown::showItemTypes($name, $types, ['value' => $value]);
$display = true;
Expand Down
4 changes: 2 additions & 2 deletions src/RuleImportAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ public function showSpecificCriteriasForPreview($fields)
}

/**
* Get itemtypes have state_type and unmanaged devices
* Get itemtypes
*
* @global array $CFG_GLPI
* @return array
Expand All @@ -1068,7 +1068,7 @@ public static function getItemTypesForRules()
global $CFG_GLPI;

$types = [];
foreach ($CFG_GLPI["state_types"] as $itemtype) {
foreach ($CFG_GLPI["ruleimportasset_types"] as $itemtype) {
if (class_exists($itemtype)) {
$item = new $itemtype();
$types[$itemtype] = $item->getTypeName();
Expand Down
2 changes: 1 addition & 1 deletion src/RuleImportAssetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
switch ($item::class) {
case self::class:
$ong = [];
$types = $CFG_GLPI['state_types'];
$types = $CFG_GLPI['ruleimportasset_types'];
foreach ($types as $type) {
if (class_exists($type)) {
$ong[$type] = $type::getTypeName();
Expand Down
8 changes: 8 additions & 0 deletions src/autoload/CFG_GLPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@
'Appliance', 'DatabaseInstance', 'Cable', 'Unmanaged', 'PassiveDCEquipment'
];

$CFG_GLPI["ruleimportasset_types"] = ['Computer', 'Monitor', 'NetworkEquipment',
'Peripheral', 'Phone', 'Printer', 'SoftwareLicense',
'Certificate', 'Enclosure', 'PDU', 'Line',
'Rack', 'SoftwareVersion', 'Cluster', 'Contract',
'Appliance', 'DatabaseInstance', 'Cable', 'Unmanaged', 'PassiveDCEquipment'
];


$CFG_GLPI["asset_types"] = ['Computer', 'Monitor', 'NetworkEquipment',
'Peripheral', 'Phone', 'Printer', 'SoftwareLicense',
'Certificate', 'Unmanaged', 'Appliance'
Expand Down

0 comments on commit 846fd74

Please sign in to comment.