From 65b34a4a07f443e83c9a542db8648f08f6438288 Mon Sep 17 00:00:00 2001 From: Rom1-B <8530352+Rom1-B@users.noreply.github.com> Date: Thu, 30 Jul 2026 08:15:38 +0200 Subject: [PATCH] Fix(CI): rector --- .gitignore | 4 +- hook.php | 24 ++++++++--- inc/config.class.php | 37 +++++++++-------- inc/preference.class.php | 1 + inc/profile.class.php | 1 + rector.php | 86 ++++++++++------------------------------ setup.php | 7 ++-- 7 files changed, 68 insertions(+), 92 deletions(-) diff --git a/.gitignore b/.gitignore index b2e56b0..7f7c897 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ dist/ vendor/ .gh_token -*.min.* \ No newline at end of file +*.min.* +var/ +.tokensave diff --git a/hook.php b/hook.php index 7bc20a2..a706ba3 100644 --- a/hook.php +++ b/hook.php @@ -116,7 +116,7 @@ function plugin_treeview_install() } // No autoload when plugin is not activated - require __DIR__ . '/inc/profile.class.php'; + require_once __DIR__ . '/inc/profile.class.php'; PluginTreeviewProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); @@ -158,6 +158,7 @@ function plugin_treeview_upgrade11to12() if ($DB->fieldExists('glpi_plugin_treeview_profiles', 'interface')) { $query .= ' DROP `interface`,'; } + if ($DB->fieldExists('glpi_plugin_treeview_profiles', 'is_default')) { $query .= ' DROP `is_default`'; } @@ -180,26 +181,33 @@ function plugin_treeview_upgrade12to13() $query = 'ALTER TABLE `glpi_plugin_treeview_displayprefs` '; if ($DB->fieldExists('glpi_plugin_treeview_displayprefs', 'ID')) { - $query .= " CHANGE `ID` `id` int {$default_key_sign} NOT NULL auto_increment,"; + $query .= sprintf(' CHANGE `ID` `id` int %s NOT NULL auto_increment,', $default_key_sign); } + if ($DB->fieldExists('glpi_plugin_treeview_displayprefs', 'folderLinks')) { $query .= " CHANGE `folderLinks` `folderLinks` tinyint NOT NULL default '0',"; } + if ($DB->fieldExists('glpi_plugin_treeview_displayprefs', 'useSelection')) { $query .= " CHANGE `useSelection` `useSelection` tinyint NOT NULL default '0',"; } + if ($DB->fieldExists('glpi_plugin_treeview_displayprefs', 'useLines')) { $query .= " CHANGE `useLines` `useLines` tinyint NOT NULL default '0',"; } + if ($DB->fieldExists('glpi_plugin_treeview_displayprefs', 'useIcons')) { $query .= " CHANGE `useIcons` `useIcons` tinyint NOT NULL default '0',"; } + if ($DB->fieldExists('glpi_plugin_treeview_displayprefs', 'closeSameLevel')) { $query .= " CHANGE `closeSameLevel` `closeSameLevel` tinyint NOT NULL default '0',"; } + if ($DB->fieldExists('glpi_plugin_treeview_displayprefs', 'itemName')) { $query .= " CHANGE `itemName` `itemName` int NOT NULL default '0',"; } + if ($DB->fieldExists('glpi_plugin_treeview_displayprefs', 'locationName')) { $query .= " CHANGE `locationName` `locationName` int NOT NULL default '0'"; } @@ -211,8 +219,9 @@ function plugin_treeview_upgrade12to13() $query = 'ALTER TABLE `glpi_plugin_treeview_profiles` '; if ($DB->fieldExists('glpi_plugin_treeview_profiles', 'ID')) { - $query .= " CHANGE `ID` `id` int {$default_key_sign} NOT NULL auto_increment"; + $query .= sprintf(' CHANGE `ID` `id` int %s NOT NULL auto_increment', $default_key_sign); } + $DB->doQuery($query); } @@ -222,14 +231,17 @@ function plugin_treeview_upgrade12to13() $query = 'ALTER TABLE `glpi_plugin_treeview_preferences` '; if ($DB->fieldExists('glpi_plugin_treeview_preferences', 'ID')) { - $query .= " CHANGE `ID` `id` int {$default_key_sign} NOT NULL auto_increment,"; + $query .= sprintf(' CHANGE `ID` `id` int %s NOT NULL auto_increment,', $default_key_sign); } + if ($DB->fieldExists('glpi_plugin_treeview_preferences', 'user_id')) { - $query .= " CHANGE `user_id` `users_id` int {$default_key_sign} NOT NULL default '0' COMMENT 'RELATION to glpi_users (id)',"; + $query .= sprintf(" CHANGE `user_id` `users_id` int %s NOT NULL default '0' COMMENT 'RELATION to glpi_users (id)',", $default_key_sign); } + if ($DB->fieldExists('glpi_plugin_treeview_preferences', 'show')) { $query .= " CHANGE `show` `show_on_load` int NOT NULL default '0'"; } + $DB->doQuery($query); } } @@ -261,7 +273,7 @@ function plugin_treeview_uninstall() ]; foreach ($tables as $table) { - $query = "DROP TABLE IF EXISTS `$table`;"; + $query = sprintf('DROP TABLE IF EXISTS `%s`;', $table); $DB->doQuery($query); } diff --git a/inc/config.class.php b/inc/config.class.php index 1f2ef74..105601f 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -64,19 +64,18 @@ public static function getTypeName($nb = 0) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - switch ($item->getType()) { - case "Config": - return self::createTabEntry(self::getTypeName(), 0, $item::getType(), self::getIcon()); + if ($item->getType() === "Config") { + return self::createTabEntry(self::getTypeName(), 0, $item::getType(), self::getIcon()); } + return ''; } public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { $config = new self(); - switch ($item->getType()) { - case "Config": - $config->showConfigForm(); + if ($item->getType() === "Config") { + $config->showConfigForm(); } return true; @@ -205,8 +204,8 @@ public function buildTreeview() $treeview_url = $CFG_GLPI['root_doc'] . "/plugins/treeview"; //necessary files needed for the tree to work. - echo ""; - echo ""; + echo sprintf("", $treeview_url); + echo sprintf("", $treeview_url); echo "