diff --git a/composer.lock b/composer.lock index 298da167..90e8177e 100644 --- a/composer.lock +++ b/composer.lock @@ -154,16 +154,16 @@ }, { "name": "symfony/yaml", - "version": "v5.4.40", + "version": "v5.4.45", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "81cad0ceab3d61fe14fe941ff18a230ac9c80f83" + "reference": "a454d47278cc16a5db371fe73ae66a78a633371e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/81cad0ceab3d61fe14fe941ff18a230ac9c80f83", - "reference": "81cad0ceab3d61fe14fe941ff18a230ac9c80f83", + "url": "https://api.github.com/repos/symfony/yaml/zipball/a454d47278cc16a5db371fe73ae66a78a633371e", + "reference": "a454d47278cc16a5db371fe73ae66a78a633371e", "shasum": "" }, "require": { @@ -209,7 +209,7 @@ "description": "Loads and dumps YAML files", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/yaml/tree/v5.4.40" + "source": "https://github.com/symfony/yaml/tree/v5.4.45" }, "funding": [ { @@ -225,7 +225,7 @@ "type": "tidelift" } ], - "time": "2024-05-31T14:33:22+00:00" + "time": "2024-09-25T14:11:13+00:00" } ], "packages-dev": [ @@ -629,16 +629,16 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v3.66.0", + "version": "v3.68.5", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "5f5f2a142ff36b93c41885bca29cc5f861c013e6" + "reference": "7bedb718b633355272428c60736dc97fb96daf27" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/5f5f2a142ff36b93c41885bca29cc5f861c013e6", - "reference": "5f5f2a142ff36b93c41885bca29cc5f861c013e6", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/7bedb718b633355272428c60736dc97fb96daf27", + "reference": "7bedb718b633355272428c60736dc97fb96daf27", "shasum": "" }, "require": { @@ -655,17 +655,17 @@ "react/promise": "^2.0 || ^3.0", "react/socket": "^1.0", "react/stream": "^1.0", - "sebastian/diff": "^4.0 || ^5.0 || ^6.0", - "symfony/console": "^5.4 || ^6.0 || ^7.0", - "symfony/event-dispatcher": "^5.4 || ^6.0 || ^7.0", - "symfony/filesystem": "^5.4 || ^6.0 || ^7.0", - "symfony/finder": "^5.4 || ^6.0 || ^7.0", - "symfony/options-resolver": "^5.4 || ^6.0 || ^7.0", - "symfony/polyfill-mbstring": "^1.28", - "symfony/polyfill-php80": "^1.28", - "symfony/polyfill-php81": "^1.28", - "symfony/process": "^5.4 || ^6.0 || ^7.0 <7.2", - "symfony/stopwatch": "^5.4 || ^6.0 || ^7.0" + "sebastian/diff": "^4.0 || ^5.1 || ^6.0", + "symfony/console": "^5.4 || ^6.4 || ^7.0", + "symfony/event-dispatcher": "^5.4 || ^6.4 || ^7.0", + "symfony/filesystem": "^5.4 || ^6.4 || ^7.0", + "symfony/finder": "^5.4 || ^6.4 || ^7.0", + "symfony/options-resolver": "^5.4 || ^6.4 || ^7.0", + "symfony/polyfill-mbstring": "^1.31", + "symfony/polyfill-php80": "^1.31", + "symfony/polyfill-php81": "^1.31", + "symfony/process": "^5.4 || ^6.4 || ^7.2", + "symfony/stopwatch": "^5.4 || ^6.4 || ^7.0" }, "require-dev": { "facile-it/paraunit": "^1.3.1 || ^2.4", @@ -677,9 +677,9 @@ "php-cs-fixer/accessible-object": "^1.1", "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.5", "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.5", - "phpunit/phpunit": "^9.6.21 || ^10.5.38 || ^11.4.3", - "symfony/var-dumper": "^5.4.47 || ^6.4.15 || ^7.1.8", - "symfony/yaml": "^5.4.45 || ^6.4.13 || ^7.1.6" + "phpunit/phpunit": "^9.6.22 || ^10.5.40 || ^11.5.2", + "symfony/var-dumper": "^5.4.48 || ^6.4.15 || ^7.2.0", + "symfony/yaml": "^5.4.45 || ^6.4.13 || ^7.2.0" }, "suggest": { "ext-dom": "For handling output formats in XML", @@ -720,7 +720,7 @@ ], "support": { "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.66.0" + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.68.5" }, "funding": [ { @@ -728,7 +728,7 @@ "type": "github" } ], - "time": "2024-12-29T13:46:23+00:00" + "time": "2025-01-30T17:00:50+00:00" }, { "name": "glpi-project/tools", @@ -849,16 +849,16 @@ }, { "name": "phpstan/phpstan", - "version": "2.1.0", + "version": "2.1.2", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "2392d360fdf54ea253aa6c68cad1d4ba2e54e927" + "reference": "7d08f569e582ade182a375c366cbd896eccadd3a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/2392d360fdf54ea253aa6c68cad1d4ba2e54e927", - "reference": "2392d360fdf54ea253aa6c68cad1d4ba2e54e927", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/7d08f569e582ade182a375c366cbd896eccadd3a", + "reference": "7d08f569e582ade182a375c366cbd896eccadd3a", "shasum": "" }, "require": { @@ -903,7 +903,7 @@ "type": "github" } ], - "time": "2024-12-31T07:30:03+00:00" + "time": "2025-01-21T14:54:06+00:00" }, { "name": "psr/container", @@ -2873,16 +2873,16 @@ }, { "name": "twig/twig", - "version": "v3.11.2", + "version": "v3.11.3", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "5b580ec1882b54c98cbd8c0f8a3ca5d1904db6b1" + "reference": "3b06600ff3abefaf8ff55d5c336cd1c4253f8c7e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/5b580ec1882b54c98cbd8c0f8a3ca5d1904db6b1", - "reference": "5b580ec1882b54c98cbd8c0f8a3ca5d1904db6b1", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/3b06600ff3abefaf8ff55d5c336cd1c4253f8c7e", + "reference": "3b06600ff3abefaf8ff55d5c336cd1c4253f8c7e", "shasum": "" }, "require": { @@ -2937,7 +2937,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.11.2" + "source": "https://github.com/twigphp/Twig/tree/v3.11.3" }, "funding": [ { @@ -2949,7 +2949,7 @@ "type": "tidelift" } ], - "time": "2024-11-06T18:50:16+00:00" + "time": "2024-11-07T12:34:41+00:00" } ], "aliases": [], diff --git a/front/container.form.php b/front/container.form.php index fb263c21..b8dd3bca 100644 --- a/front/container.form.php +++ b/front/container.form.php @@ -46,7 +46,7 @@ Html::redirect(PLUGINFIELDS_WEB_DIR . '/front/container.php'); } elseif (isset($_REQUEST['purge'])) { $container->check($_REQUEST['id'], PURGE); - $container->delete($_REQUEST, 1); + $container->delete($_REQUEST, true); Html::redirect(PLUGINFIELDS_WEB_DIR . '/front/container.php'); } elseif (isset($_POST['update'])) { $container->check($_POST['id'], UPDATE); diff --git a/front/field.form.php b/front/field.form.php index 0d2f339a..4bd5ada5 100644 --- a/front/field.form.php +++ b/front/field.form.php @@ -48,7 +48,7 @@ Html::back(); } elseif (isset($_REQUEST['purge'])) { $field->check($_REQUEST['id'], PURGE); - $field->delete($_REQUEST, 1); + $field->delete($_REQUEST, true); $field->redirectToList(); } elseif (isset($_POST['update'])) { $field->check($_POST['id'], UPDATE); diff --git a/hook.php b/hook.php index 076b55f8..2ee27aa7 100644 --- a/hook.php +++ b/hook.php @@ -254,49 +254,46 @@ function plugin_fields_rule_matched($params = []) $container = new PluginFieldsContainer(); - switch ($params['sub_type']) { - case 'PluginFusioninventoryTaskpostactionRule': - /** @phpstan-ignore-next-line */ - $agent = new PluginFusioninventoryAgent(); - - if (isset($params['input']['plugin_fusioninventory_agents_id'])) { - foreach ($params['output'] as $field => $value) { - // check if current field is in a tab container - $iterator = $DB->request([ - 'SELECT' => 'glpi_plugin_fields_containers.id', - 'FROM' => 'glpi_plugin_fields_containers', - 'LEFT JOIN' => [ - 'glpi_plugin_fields_fields' => [ - 'FKEY' => [ - 'glpi_plugin_fields_containers' => 'id', - 'glpi_plugin_fields_fields' => 'plugin_fields_containers_id', - ], + if (class_exists('PluginFusioninventoryAgent') && $params['sub_type'] == 'PluginFusioninventoryTaskpostactionRule') { + $agent = new PluginFusioninventoryAgent(); + + if (isset($params['input']['plugin_fusioninventory_agents_id'])) { + foreach ($params['output'] as $field => $value) { + // check if current field is in a tab container + $iterator = $DB->request([ + 'SELECT' => 'glpi_plugin_fields_containers.id', + 'FROM' => 'glpi_plugin_fields_containers', + 'LEFT JOIN' => [ + 'glpi_plugin_fields_fields' => [ + 'FKEY' => [ + 'glpi_plugin_fields_containers' => 'id', + 'glpi_plugin_fields_fields' => 'plugin_fields_containers_id', ], ], - 'WHERE' => [ - 'glpi_plugin_fields_fields.name' => $field, + ], + 'WHERE' => [ + 'glpi_plugin_fields_fields.name' => $field, + ], + ]); + if (count($iterator) > 0) { + $data = $iterator->current(); + + //retrieve computer + $agents_id = $params['input']['plugin_fusioninventory_agents_id']; + $agent->getFromDB($agents_id); + + // update current field + $container->updateFieldsValues( + [ + 'plugin_fields_containers_id' => $data['id'], + $field => $value, + 'items_id' => $agent->fields['computers_id'], ], - ]); - if (count($iterator) > 0) { - $data = $iterator->current(); - - //retrieve computer - $agents_id = $params['input']['plugin_fusioninventory_agents_id']; - $agent->getFromDB($agents_id); - - // update current field - $container->updateFieldsValues( - [ - 'plugin_fields_containers_id' => $data['id'], - $field => $value, - 'items_id' => $agent->fields['computers_id'], - ], - Computer::getType(), - ); - } + Computer::getType(), + ); } } - break; + } } } diff --git a/inc/container.class.php b/inc/container.class.php index 2d40838c..f4ab39bf 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -253,7 +253,7 @@ public static function installUserData(Migration $migration, $version) $compcontainer->getFromDB($comptab); $fields = new PluginFieldsField(); - $fields = $fields->find(['plugin_fields_containers_id' => $ostab]); + $fieldsdata = $fields->find(['plugin_fields_containers_id' => $ostab]); $classname = self::getClassname(Computer::getType(), $oscontainer->fields['name']); $osdata = new $classname(); @@ -262,7 +262,7 @@ public static function installUserData(Migration $migration, $version) $fieldnames = []; //add fields to compcontainer - foreach ($fields as $field) { + foreach ($fieldsdata as $field) { $newname = $field['name']; $compfields = $fields->find(['plugin_fields_containers_id' => $comptab, 'name' => $newname]); if ($compfields) { @@ -492,11 +492,14 @@ public static function getSpecificValueToDisplay($field, $values, array $options continue; } $name_type = getItemForItemtype($type); - $obj .= $name_type->getTypeName(2); - if ($count > $i) { - $obj .= ', '; + + if ($name_type !== false) { + $obj .= $name_type->getTypeName(2); + if ($count > $i) { + $obj .= ', '; + } + $i++; } - $i++; } return $obj; @@ -617,9 +620,7 @@ public function prepareInputForAdd($input) } } - $input['itemtypes'] = isset($input['itemtypes']) - ? Sanitizer::dbEscape(json_encode($input['itemtypes'])) - : null; + $input['itemtypes'] = Sanitizer::dbEscape(json_encode($input['itemtypes'])); return $input; } @@ -856,11 +857,13 @@ public function showForm($ID, $options = []) } $name_type = getItemForItemtype($type); - $obj .= $name_type->getTypeName(2); - if ($count > $i) { - $obj .= ', '; + if ($name_type !== false) { + $obj .= $name_type->getTypeName(2); + if ($count > $i) { + $obj .= ', '; + } + $i++; } - $i++; } echo $obj; } else { @@ -1136,7 +1139,7 @@ public static function getUsedItemtypes($type = 'all', $must_be_active = false) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { $itemtypes = self::getEntries('tab', true); - if (isset($itemtypes[$item->getType()])) { + if (isset($itemtypes[$item->getType()]) && $item instanceof CommonDBTM) { $tabs_entries = []; $container = new self(); foreach ($itemtypes[$item->getType()] as $tab_name => $tab_label) { @@ -1169,7 +1172,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ { if ($withtemplate) { //Do not display tab from template or from item created from template - return []; + return false; } //retrieve container for current tab @@ -1293,7 +1296,7 @@ private function addRichTextFiles(CommonDBTM $object): void * @param int $items_id item id * @param string $itemtype item type * @param array $data values send by update form - * @param array $old_values old values, if empty -> values add + * @param object $field_obj field object * @return void */ public static function constructHistory( @@ -1513,10 +1516,9 @@ public static function validateValues($data, $itemtype, $massiveaction) if ( $field['mandatory'] == 1 && ( - $value === null + $value === null || $value === '' || (($field['type'] === 'dropdown' || preg_match('/^dropdown-.+/i', $field['type'])) && $value == 0) - || ($field['type'] === 'glpi_item' && $value === null) || (in_array($field['type'], ['date', 'datetime']) && $value == 'NULL') ) ) { @@ -1617,7 +1619,8 @@ public static function postItemAdd(CommonDBTM $item) return true; } - return $item->input = []; + $item->input = []; + return $item; } return true; @@ -1647,7 +1650,7 @@ public static function preItemUpdate(CommonDBTM $item) return true; } - return $item->input = []; + return false; } return true; @@ -1691,10 +1694,10 @@ public static function preItem(CommonDBTM $item) if (isset($_SESSION['glpiactiveprofile']['id']) && $_SESSION['glpiactiveprofile']['id'] != null && $c_id > 0) { $right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $c_id); if (($right > READ) === false) { - return; + return false; } } else { - return; + return false; } @@ -1706,7 +1709,7 @@ public static function preItem(CommonDBTM $item) //workaround: when a ticket is created from readdonly profile, //it is not initialized; see https://github.com/glpi-project/glpi/issues/1438 - if (!isset($item->fields) || count($item->fields) == 0) { + if (!empty($item->fields)) { $item->fields = $item->input; } @@ -1718,14 +1721,14 @@ public static function preItem(CommonDBTM $item) if (self::validateValues($data, $item::getType(), isset($_REQUEST['massiveaction'])) === false) { $item->input = []; - return []; + return false; } $item->input['_plugin_fields_data'] = $data; - return $data; + return true; } - return; + return false; } /** diff --git a/inc/containerdisplaycondition.class.php b/inc/containerdisplaycondition.class.php index eba2a041..43a20ef2 100644 --- a/inc/containerdisplaycondition.class.php +++ b/inc/containerdisplaycondition.class.php @@ -30,6 +30,7 @@ use Glpi\Application\View\TemplateRenderer; use Glpi\Toolbox\Sanitizer; +use GlpiPlugin\Scim\Controller\Common; class PluginFieldsContainerDisplayCondition extends CommonDBChild { @@ -156,6 +157,9 @@ public static function getTypeName($nb = 0) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { + if (!($item instanceof CommonDBTM)) { + return ''; + } return self::createTabEntry( self::getTypeName(Session::getPluralNumber()), countElementsInTable(self::getTable(), ['plugin_fields_containers_id' => $item->getID()]), @@ -479,8 +483,10 @@ public function checkCondition($item) public static function checkRegex($regex) { // Avoid php notice when validating the regular expression - set_error_handler(function ($errno, $errstr, $errfile, $errline) {}); - $isValid = !(preg_match($regex, null) === false); + set_error_handler(function ($errno, $errstr, $errfile, $errline) { + return true; + }); + $isValid = !(preg_match($regex, '') === false); restore_error_handler(); return $isValid; @@ -520,6 +526,9 @@ public function prepareInputForUpdate($input) public static function showForTabContainer(CommonGLPI $item, $options = []) { + if (!$item instanceof CommonDBTM) { + return; + } $displayCondition_id = $options['displaycondition_id'] ?? 0; $display_condition = null; diff --git a/inc/field.class.php b/inc/field.class.php index c0b82967..933a21c4 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -438,8 +438,6 @@ public function post_purgeItem() 'ranking' => ['>', $old_ranking], ], ); - - return true; } /** @@ -495,7 +493,7 @@ public function prepareName($input, bool $prevent_duplicated = true) // FIXME: see: https://bugs.mysql.com/bug.php?id=107165 if (strlen($field_name) > 52) { $rand = rand(); - $field_name = substr($field_name, 0, 52 - strlen($rand)) . $rand; + $field_name = substr($field_name, 0, 52 - strlen((string) $rand)) . $rand; } return $field_name; @@ -535,12 +533,14 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) if (!$withtemplate) { switch ($item->getType()) { case __CLASS__: - $ong[1] = $this->getTypeName(1); - - return $ong; + return $this->getTypeName(1); } } + if (!($item instanceof CommonDBTM)) { + return ''; + } + return self::createTabEntry( __('Fields', 'fields'), countElementsInTable( @@ -857,7 +857,7 @@ public static function showForTabContainer($c_id, $item) */ public static function showDomContainer($id, $item, $type = 'dom', $subtype = '', $field_options = []) { - if ($id !== false) { + if ($id != 0) { //get fields for this container $field_obj = new self(); $fields = $field_obj->find( @@ -908,7 +908,7 @@ public static function showForTab($params) if (isset($_REQUEST['c_id'])) { $c_id = $_REQUEST['c_id']; } elseif (!$c_id = PluginFieldsContainer::findContainer(get_Class($item), $type, $subtype)) { - return false; + return; } $right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $c_id); @@ -929,13 +929,13 @@ public static function showForTab($params) if ($item->isEntityAssign()) { $current_entity = $item->getEntityID(); if (!in_array($current_entity, $entities)) { - return false; + return; } } //parse REQUEST_URI if (!isset($_SERVER['REQUEST_URI'])) { - return false; + return; } $current_url = $_SERVER['REQUEST_URI']; if ( @@ -944,7 +944,7 @@ public static function showForTab($params) && strpos($current_url, '.public.php') === false && strpos($current_url, 'ajax/timeline.php') === false // ITILSolution load from timeline ) { - return false; + return; } //Retrieve dom container @@ -952,7 +952,7 @@ public static function showForTab($params) //if no dom containers defined for this itemtype, do nothing (in_array case insensitive) if (!in_array(strtolower($item::getType()), array_map('strtolower', $itemtypes))) { - return false; + return; } $html_id = 'plugin_fields_container_' . mt_rand(); diff --git a/inc/inventory.class.php b/inc/inventory.class.php index 6881601d..93c2e50f 100644 --- a/inc/inventory.class.php +++ b/inc/inventory.class.php @@ -55,25 +55,28 @@ public static function updateInventory($params = []) break; } - if ($itemtype == Computer::getType()) { - //load inventory from DB because - //FI not update XML file if computer is not update - /** @phpstan-ignore-next-line */ - $db_info = new PluginFusioninventoryInventoryComputerComputer(); - if ($db_info->getFromDBByCrit(['computers_id' => $items_id])) { - $arrayinventory = unserialize(gzuncompress($db_info->fields['serialized_inventory'])); - if (isset($arrayinventory['custom'])) { - self::updateFields($arrayinventory['custom']['container'], $itemtype, $items_id); + if (class_exists('PluginFusioninventoryInventoryComputerComputer')) { + if ($itemtype == Computer::getType()) { + //load inventory from DB because + //FI not update XML file if computer is not update + $db_info = new PluginFusioninventoryInventoryComputerComputer(); + if ($db_info->getFromDBByCrit(['computers_id' => $items_id])) { + $arrayinventory = unserialize(gzuncompress($db_info->fields['serialized_inventory'])); + if (isset($arrayinventory['custom'])) { + self::updateFields($arrayinventory['custom']['container'], $itemtype, $items_id); + } } - } - } else { - //Load XML file because FI always update XML file and don't store inventory into DB - $file = self::loadXMLFile($itemtype, $items_id); - if ($file !== false) { - /** @phpstan-ignore-next-line */ - $arrayinventory = PluginFusioninventoryFormatconvert::XMLtoArray($file); - if (isset($arrayinventory['CUSTOM'])) { - self::updateFields($arrayinventory['CUSTOM']['CONTAINER'], $itemtype, $items_id); + } else { + //Load XML file because FI always update XML file and don't store inventory into DB + $file = self::loadXMLFile($itemtype, $items_id); + if ( + $file !== false + && class_exists('PluginFusioninventoryFormatconvert') + ) { + $arrayinventory = PluginFusioninventoryFormatconvert::XMLtoArray($file); + if (isset($arrayinventory['CUSTOM'])) { + self::updateFields($arrayinventory['CUSTOM']['CONTAINER'], $itemtype, $items_id); + } } } } diff --git a/inc/labeltranslation.class.php b/inc/labeltranslation.class.php index 271f0a18..140d7a56 100644 --- a/inc/labeltranslation.class.php +++ b/inc/labeltranslation.class.php @@ -119,6 +119,9 @@ public static function createForItem(CommonDBTM $item) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { + if (!($item instanceof CommonDBTM)) { + return ''; + } $nb = countElementsInTable( self::getTable(), [ @@ -132,6 +135,10 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { + if (!($item instanceof CommonDBTM)) { + return false; + } + self::showTranslations($item); return true; @@ -237,7 +244,7 @@ public static function showTranslations(CommonDBTM $item) echo "" . __('No translation found') . ''; } - return true; + return; } /** @@ -290,7 +297,7 @@ public function showFormForItem($itemtype, $items_id, $id = -1) $this->showFormButtons(); - return true; + return; } /** diff --git a/inc/menu.class.php b/inc/menu.class.php index 5b309afa..e46b4c42 100644 --- a/inc/menu.class.php +++ b/inc/menu.class.php @@ -40,7 +40,7 @@ public static function getMenuName() public static function getMenuContent() { if (!Session::haveRight('entity', READ)) { - return; + return false; } $front_fields = Plugin::getPhpDir('fields', false) . '/front'; diff --git a/inc/migration.class.php b/inc/migration.class.php index 4cb3736d..81a32048 100644 --- a/inc/migration.class.php +++ b/inc/migration.class.php @@ -106,7 +106,7 @@ public static function getSQLFields(string $field_name, string $field_type, arra */ public static function checkDeadFields(bool $fix): array { - /** @var DBMysql $DB */ + /** @var DBmysql $DB */ global $DB; $dead_fields = []; @@ -144,7 +144,7 @@ public static function checkDeadFields(bool $fix): array } if ($fix) { - $migration = new PluginFieldsMigration(0); + $migration = new PluginFieldsMigration('0'); foreach ($dead_fields as $table => $fields) { foreach ($fields as $field) { @@ -191,7 +191,7 @@ private static function getValidFieldsForContainer(int $container_id): array private static function getCustomFieldsInContainerTable( string $table ): array { - /** @var DBMysql $DB */ + /** @var DBmysql $DB */ global $DB; // Read table fields diff --git a/inc/profile.class.php b/inc/profile.class.php index 72e991e2..1ca2c91c 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -91,6 +91,10 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { + if (!($item instanceof CommonDBTM)) { + return false; + } + $profile = new Profile(); $found_profiles = $profile->find(); diff --git a/inc/statusoverride.class.php b/inc/statusoverride.class.php index c6e7d31e..65715efa 100644 --- a/inc/statusoverride.class.php +++ b/inc/statusoverride.class.php @@ -92,7 +92,10 @@ public static function getTypeName($nb = 0) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - return self::createTabEntry(self::getTypeName(), self::countOverridesForContainer($item->getID())); + if ($item instanceof CommonDBTM) { + return self::createTabEntry(self::getTypeName(), self::countOverridesForContainer($item->getID())); + } + return ''; } public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) @@ -408,6 +411,9 @@ public static function getStatusDropdownForItemtype(string $itemtype, array $val public static function showForTabContainer(CommonGLPI $item, $options = []) { + if (!($item instanceof CommonDBTM)) { + return; + } $container_id = $item->getID(); $has_fields = countElementsInTable(PluginFieldsField::getTable(), [ 'plugin_fields_containers_id' => $container_id, diff --git a/inc/toolbox.class.php b/inc/toolbox.class.php index fbd7ba48..91c412d0 100644 --- a/inc/toolbox.class.php +++ b/inc/toolbox.class.php @@ -325,9 +325,8 @@ public static function getGlpiItemtypes(): array ]; $plugin = new Plugin(); - if ($plugin->isActivated('genericobject') && method_exists('PluginGenericobjectType', 'getTypes')) { + if ($plugin->isActivated('genericobject') && class_exists('PluginGenericobjectType')) { $go_itemtypes = []; - /** @phpstan-ignore-next-line */ foreach (array_keys(PluginGenericobjectType::getTypes()) as $go_itemtype) { if (!class_exists($go_itemtype)) { continue; diff --git a/phpstan.neon b/phpstan.neon index 8feb5069..455f2e74 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,7 @@ parameters: parallel: maximumNumberOfProcesses: 2 - level: 1 + level: 5 bootstrapFiles: - ../../inc/based_config.php paths: diff --git a/setup.php b/setup.php index d5d837b2..b349bad6 100644 --- a/setup.php +++ b/setup.php @@ -96,7 +96,7 @@ function plugin_init_fields() if ( !empty($_POST) && isset($_POST['_plugin_fields_type']) - && $_SERVER['REQUEST_URI'] ?? '' == Ticket::getFormURL() + && ($_SERVER['REQUEST_URI'] == Ticket::getFormURL()) ) { foreach ($_POST as $key => $value) { if (!is_array($value)) { @@ -385,7 +385,7 @@ function plugin_fields_exportBlockAsYaml($container_id = null) } } - if (count($yaml_conf)) { + if (!empty($yaml_conf['container'])) { $dump = Yaml::dump($yaml_conf, 10); $filename = GLPI_TMP_DIR . '/fields_conf.yaml'; file_put_contents($filename, $dump);