From 8c69b757176814d8ef2297c8e765c6b4fe3d762f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 Nov 2023 04:13:32 +0000 Subject: [PATCH 1/3] Bump glpi-project/tools from 0.6.4 to 0.7.1 Bumps [glpi-project/tools](https://github.com/glpi-project/tools) from 0.6.4 to 0.7.1. - [Changelog](https://github.com/glpi-project/tools/blob/develop/CHANGELOG.md) - [Commits](https://github.com/glpi-project/tools/compare/0.6.4...0.7.1) --- updated-dependencies: - dependency-name: glpi-project/tools dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7aca1bd..1e794b5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,7 @@ jobs: uses: "actions/checkout@v4" - name: "Build package" id: "build-package" - uses: "glpi-project/tools/github-actions/build-package@0.6.4" + uses: "glpi-project/tools/github-actions/build-package@0.7.1" with: plugin-version: ${{ env.tag_name }} - name: "Create release" From 877ea7932db70414764e6f3b15024e34708b8978 Mon Sep 17 00:00:00 2001 From: Curtis Conard Date: Wed, 8 Nov 2023 08:12:22 -0500 Subject: [PATCH 2/3] fix credential type fk in join --- inc/databaseparam.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/databaseparam.class.php b/inc/databaseparam.class.php index a3ffedb..1f0e591 100644 --- a/inc/databaseparam.class.php +++ b/inc/databaseparam.class.php @@ -147,7 +147,7 @@ public function getCredentialTypeLinked() 'JOIN' => [ $credential_table => [ 'ON' => [ - $credential_table => 'plugin_databaseinventory_credentials_types_id', + $credential_table => 'plugin_databaseinventory_credentialtypes_id', $credential_type_table => 'id' ] ], From 47fc06fe2cb20178c36cc76bcf2ba4efe12ae5cc Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Tue, 14 Nov 2023 22:26:44 +0100 Subject: [PATCH 3/3] Feature/ci (#9) * phpstan lvl 1 * Some lvl 2 fixes; but cannot force since all is not fixed * Update CI config * Check also setup * phpstan lvl 2 * phpstan lvl 3 * phpstan lvl 4 fixes, not enforced * Fix withtemplate * improve phpdoc --- .github/workflows/continuous-integration.yml | 31 ++++++++ composer.json | 3 +- composer.lock | 80 ++++++++++++++++++-- front/menu.php | 13 ++-- inc/computergroup.class.php | 6 +- inc/computergroupdynamic.class.php | 12 ++- inc/computergroupstatic.class.php | 13 ++-- inc/contactlog.class.php | 37 +++------ inc/credential.class.php | 2 + inc/credentialtype.class.php | 14 +--- inc/databaseparam.class.php | 3 + inc/databaseparam_computergroup.class.php | 13 ++-- inc/databaseparam_credential.class.php | 13 ++-- inc/inventoryaction.class.php | 3 +- inc/menu.class.php | 32 ++++---- inc/task.class.php | 26 ++++--- phpstan.neon | 19 +++++ setup.php | 3 +- 18 files changed, 209 insertions(+), 114 deletions(-) create mode 100644 .github/workflows/continuous-integration.yml create mode 100644 phpstan.neon diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 0000000..f8093d9 --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,31 @@ +name: "Continuous integration" + +on: + push: + branches: + - "main" + tags: + - "*" + pull_request: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +jobs: + ci: + name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}" + strategy: + fail-fast: false + matrix: + include: + - {glpi-version: "10.0.x", php-version: "7.4", db-image: "mysql:5.7"} + - {glpi-version: "10.0.x", php-version: "8.0", db-image: "mysql:8.0"} + - {glpi-version: "10.0.x", php-version: "8.1", db-image: "mariadb:10.2"} + - {glpi-version: "10.0.x", php-version: "8.2", db-image: "mariadb:11.0"} + - {glpi-version: "10.0.x", php-version: "8.3-rc", db-image: "mysql:8.0"} + uses: "glpi-project/plugin-ci-workflows/.github/workflows/continuous-integration.yml@v1" + with: + plugin-key: "databaseinventory" + glpi-version: "${{ matrix.glpi-version }}" + php-version: "${{ matrix.php-version }}" + db-image: "${{ matrix.db-image }}" diff --git a/composer.json b/composer.json index 9ac6eb9..60223c5 100644 --- a/composer.json +++ b/composer.json @@ -3,8 +3,9 @@ "php": ">=7.4" }, "require-dev": { - "glpi-project/tools": "^0.6", + "glpi-project/tools": "^0.7.1", "php-parallel-lint/php-parallel-lint": "^1.3", + "phpstan/phpstan": "^1.10", "squizlabs/php_codesniffer": "^3.7" }, "config": { diff --git a/composer.lock b/composer.lock index 7b680f2..d21a0f2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,27 +4,31 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "dcfa1cccfc615cf14840495fef4497bb", + "content-hash": "fc6c417f71dc479b026d089b5d21af9a", "packages": [], "packages-dev": [ { "name": "glpi-project/tools", - "version": "0.6.4", + "version": "0.7.1", "source": { "type": "git", "url": "https://github.com/glpi-project/tools.git", - "reference": "8ef917fa2967e716eaed198bb803f418a80cd621" + "reference": "4bc5a725d9f4da0ee946ad3cbdd54a782d2f40fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/glpi-project/tools/zipball/8ef917fa2967e716eaed198bb803f418a80cd621", - "reference": "8ef917fa2967e716eaed198bb803f418a80cd621", + "url": "https://api.github.com/repos/glpi-project/tools/zipball/4bc5a725d9f4da0ee946ad3cbdd54a782d2f40fb", + "reference": "4bc5a725d9f4da0ee946ad3cbdd54a782d2f40fb", "shasum": "" }, "require": { "symfony/console": "^5.4 || ^6.0", "twig/twig": "^3.3" }, + "require-dev": { + "nikic/php-parser": "^4.13", + "phpstan/phpstan-src": "^1.10" + }, "bin": [ "bin/extract-locales", "bin/licence-headers-check", @@ -33,7 +37,7 @@ "type": "library", "autoload": { "psr-4": { - "Glpi\\": "src/" + "GlpiProject\\Tools\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -57,7 +61,7 @@ "issues": "https://github.com/glpi-project/tools/issues", "source": "https://github.com/glpi-project/tools" }, - "time": "2023-07-27T12:32:25+00:00" + "time": "2023-10-16T11:40:35+00:00" }, { "name": "php-parallel-lint/php-parallel-lint", @@ -116,6 +120,68 @@ }, "time": "2022-02-21T12:50:22+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.10.40", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "93c84b5bf7669920d823631e39904d69b9c7dc5d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/93c84b5bf7669920d823631e39904d69b9c7dc5d", + "reference": "93c84b5bf7669920d823631e39904d69b9c7dc5d", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2023-10-30T14:48:31+00:00" + }, { "name": "psr/container", "version": "1.1.2", diff --git a/front/menu.php b/front/menu.php index f0bc239..5fa48b6 100644 --- a/front/menu.php +++ b/front/menu.php @@ -30,6 +30,9 @@ include("../../../inc/includes.php"); +/** @var array $CFG_GLPI */ +global $CFG_GLPI; + Html::header( __('Database Inventory', 'databaseinventory'), $_SERVER['PHP_SELF'], @@ -42,12 +45,10 @@ echo ""; echo ""; - if (PluginDatabaseinventoryDatabaseParam::canView()) { - echo ""; - echo ""; - echo ""; - } + echo ""; + echo ""; + echo ""; if (PluginDatabaseinventoryCredential::canView()) { echo ""; diff --git a/inc/computergroup.class.php b/inc/computergroup.class.php index 27a847b..8461941 100644 --- a/inc/computergroup.class.php +++ b/inc/computergroup.class.php @@ -146,7 +146,6 @@ public function showForm($ID, array $options = []) $this->initForm($ID, $options); $this->showFormHeader($options); - $rand = mt_rand(); echo ""; echo ""; - $header_bottom .= ""; - } - $header_end .= ""; $header_end .= ""; $header_end .= ""; @@ -165,6 +151,7 @@ private static function showForDatabaseParams(PluginDatabaseinventoryDatabasePar private static function showForAgent(Agent $agent) { + /** @var DBmysql $DB */ global $DB; $ID = $agent->getField('id'); @@ -186,7 +173,6 @@ private static function showForAgent(Agent $agent) $rand = mt_rand(); $canread = $agent->can($ID, READ); - $canedit = false; echo "
"; if ($canread) { echo "
"; @@ -196,13 +182,6 @@ private static function showForAgent(Agent $agent) $header_bottom = ''; $header_end = ''; - if ($canedit) { - $header_top .= "
"; - $header_bottom .= ""; - } - $header_end .= ""; $header_end .= ""; $header_end .= ""; @@ -240,6 +219,7 @@ private static function showForAgent(Agent $agent) public static function install(Migration $migration) { + /** @var DBmysql $DB */ global $DB; $default_charset = DBConnection::getDefaultCharset(); @@ -269,6 +249,7 @@ public static function install(Migration $migration) public static function uninstall(Migration $migration) { + /** @var DBmysql $DB */ global $DB; $table = self::getTable(); if ($DB->tableExists($table)) { diff --git a/inc/credential.class.php b/inc/credential.class.php index 9a29d04..4358f0a 100644 --- a/inc/credential.class.php +++ b/inc/credential.class.php @@ -206,6 +206,7 @@ public function prepareInputForUpdate($input) public static function install(Migration $migration) { + /** @var DBmysql $DB */ global $DB; $default_charset = DBConnection::getDefaultCharset(); @@ -259,6 +260,7 @@ public static function install(Migration $migration) public static function uninstall(Migration $migration) { + /** @var DBmysql $DB */ global $DB; $table = self::getTable(); if ($DB->tableExists($table)) { diff --git a/inc/credentialtype.class.php b/inc/credentialtype.class.php index 837e767..39a7385 100644 --- a/inc/credentialtype.class.php +++ b/inc/credentialtype.class.php @@ -92,22 +92,16 @@ public static function getModuleKeyById($credential_type_id) switch ($credential_type_id) { case self::MYSQL: return 'mysql'; - break; case self::ORACLE: return 'oracle'; - break; case self::DB2: return 'db2'; - break; case self::MSSQL: return 'mssql'; - break; case self::POSTGRE_SQL: return 'postgresql'; - break; case self::MONGO_DB: return 'mongodb'; - break; } } @@ -116,27 +110,22 @@ public static function getModuleKeyByName($credential_type) switch ($credential_type) { case 'mysql': return self::MYSQL; - break; case 'oracle': return self::ORACLE; - break; case 'db2': return self::DB2; - break; case 'mssql': return self::MSSQL; - break; case 'postgresql': return self::POSTGRE_SQL; - break; case 'mongodb': return self::MONGO_DB; - break; } } public static function install(Migration $migration) { + /** @var DBmysql $DB */ global $DB; $default_charset = DBConnection::getDefaultCharset(); @@ -183,6 +172,7 @@ public static function install(Migration $migration) public static function uninstall() { + /** @var DBmysql $DB */ global $DB; $DB->query("DROP TABLE IF EXISTS `" . self::getTable() . "`") or die($DB->error()); } diff --git a/inc/databaseparam.class.php b/inc/databaseparam.class.php index 1f0e591..984cc0a 100644 --- a/inc/databaseparam.class.php +++ b/inc/databaseparam.class.php @@ -130,6 +130,7 @@ public function rawSearchOptions() public function getCredentialTypeLinked() { + /** @var DBmysql $DB */ global $DB; $databaseparam_credential_table = PluginDatabaseinventoryDatabaseParam_Credential::getTable(); @@ -228,6 +229,7 @@ public function showForm($ID, array $options = []) public static function install(Migration $migration) { + /** @var DBmysql $DB */ global $DB; $default_charset = DBConnection::getDefaultCharset(); @@ -267,6 +269,7 @@ public static function install(Migration $migration) public static function uninstall(Migration $migration) { + /** @var DBmysql $DB */ global $DB; $table = self::getTable(); if ($DB->tableExists($table)) { diff --git a/inc/databaseparam_computergroup.class.php b/inc/databaseparam_computergroup.class.php index ee8d751..13954df 100644 --- a/inc/databaseparam_computergroup.class.php +++ b/inc/databaseparam_computergroup.class.php @@ -64,12 +64,9 @@ public static function getTypeName($nb = 0) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - if (get_class($item) == PluginDatabaseinventoryDatabaseParam::getType()) { - $count = 0; + if ($item instanceof PluginDatabaseinventoryDatabaseParam) { $count = countElementsInTable(PluginDatabaseinventoryDatabaseParam_ComputerGroup::getTable(), ['plugin_databaseinventory_databaseparams_id' => $item->getID()]); - $ong = []; - $ong[1] = self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count); - return $ong; + return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count); } return ''; } @@ -86,6 +83,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ private static function showForItem(PluginDatabaseinventoryDatabaseParam $databaseparams) { + /** @var DBmysql $DB */ global $DB; $ID = $databaseparams->getField('id'); @@ -108,9 +106,10 @@ private static function showForItem(PluginDatabaseinventoryDatabaseParam $databa } $number = count($datas); + $rand = mt_rand(); + echo "
"; if ($databaseparams->canAddItem('itemtype')) { - $rand = mt_rand(); echo "
"; echo ""; @@ -213,6 +212,7 @@ private static function showForItem(PluginDatabaseinventoryDatabaseParam $databa public static function install(Migration $migration) { + /** @var DBmysql $DB */ global $DB; $default_charset = DBConnection::getDefaultCharset(); @@ -241,6 +241,7 @@ public static function install(Migration $migration) public static function uninstall(Migration $migration) { + /** @var DBmysql $DB */ global $DB; $table = self::getTable(); if ($DB->tableExists($table)) { diff --git a/inc/databaseparam_credential.class.php b/inc/databaseparam_credential.class.php index faa01cb..d009dcc 100644 --- a/inc/databaseparam_credential.class.php +++ b/inc/databaseparam_credential.class.php @@ -64,12 +64,9 @@ public static function getTypeName($nb = 0) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - if (get_class($item) == PluginDatabaseinventoryDatabaseParam::getType()) { - $count = 0; + if ($item instanceof PluginDatabaseinventoryDatabaseParam) { $count = countElementsInTable(PluginDatabaseinventoryDatabaseParam_Credential::getTable(), ['plugin_databaseinventory_databaseparams_id' => $item->getID()]); - $ong = []; - $ong[1] = self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count); - return $ong; + return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count); } return ''; } @@ -86,6 +83,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ private static function showForItem(PluginDatabaseinventoryDatabaseParam $databaseparams) { + /** @var DBmysql $DB */ global $DB; $ID = $databaseparams->getField('id'); @@ -108,9 +106,10 @@ private static function showForItem(PluginDatabaseinventoryDatabaseParam $databa } $number = count($datas); + $rand = mt_rand(); + echo "
"; if ($databaseparams->canAddItem('itemtype')) { - $rand = mt_rand(); echo "
"; echo ""; @@ -214,6 +213,7 @@ private static function showForItem(PluginDatabaseinventoryDatabaseParam $databa public static function install(Migration $migration) { + /** @var DBmysql $DB */ global $DB; $default_charset = DBConnection::getDefaultCharset(); @@ -242,6 +242,7 @@ public static function install(Migration $migration) public static function uninstall(Migration $migration) { + /** @var DBmysql $DB */ global $DB; $table = self::getTable(); if ($DB->tableExists($table)) { diff --git a/inc/inventoryaction.class.php b/inc/inventoryaction.class.php index 650aa3f..b470301 100644 --- a/inc/inventoryaction.class.php +++ b/inc/inventoryaction.class.php @@ -47,7 +47,8 @@ public static function showMassiveActionsSubForm(MassiveAction $ma) public static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { if ($ma->getAction() !== self::MA_PARTIAL) { - return parent::processMassiveActionsForOneItemtype($ma, $item, $ids); + parent::processMassiveActionsForOneItemtype($ma, $item, $ids); + return; } switch ($item->getType()) { diff --git a/inc/menu.class.php b/inc/menu.class.php index 92cabf6..99d79f2 100644 --- a/inc/menu.class.php +++ b/inc/menu.class.php @@ -38,7 +38,7 @@ public static function getMenuName() public static function getMenuContent() { $menu = [ - 'title' => self::getMenuName(2), + 'title' => self::getMenuName(), 'page' => self::getSearchURL(false), 'icon' => 'fas fa-database', ]; @@ -50,12 +50,10 @@ public static function getMenuContent() 'icon' => PluginDatabaseinventoryDatabaseParam::getIcon(), ]; - if (true) { - $menu['options']['databaseparam']['links'] = [ - 'search' => PluginDatabaseinventoryDatabaseParam::getSearchURL(false), - 'add' => PluginDatabaseinventoryDatabaseParam::getFormURL(false), - ]; - } + $menu['options']['databaseparam']['links'] = [ + 'search' => PluginDatabaseinventoryDatabaseParam::getSearchURL(false), + 'add' => PluginDatabaseinventoryDatabaseParam::getFormURL(false), + ]; } if (PluginDatabaseinventoryComputerGroup::canView()) { @@ -65,12 +63,10 @@ public static function getMenuContent() 'icon' => PluginDatabaseinventoryComputerGroup::getIcon(), ]; - if (true) { - $menu['options']['computergroup']['links'] = [ - 'search' => PluginDatabaseinventoryComputerGroup::getSearchURL(false), - 'add' => PluginDatabaseinventoryComputerGroup::getFormURL(false), - ]; - } + $menu['options']['computergroup']['links'] = [ + 'search' => PluginDatabaseinventoryComputerGroup::getSearchURL(false), + 'add' => PluginDatabaseinventoryComputerGroup::getFormURL(false), + ]; } if (PluginDatabaseinventoryCredential::canView()) { @@ -80,12 +76,10 @@ public static function getMenuContent() 'icon' => PluginDatabaseinventoryCredential::getIcon(), ]; - if (true) { - $menu['options']['credential']['links'] = [ - 'search' => PluginDatabaseinventoryCredential::getSearchURL(false), - 'add' => PluginDatabaseinventoryCredential::getFormURL(false), - ]; - } + $menu['options']['credential']['links'] = [ + 'search' => PluginDatabaseinventoryCredential::getSearchURL(false), + 'add' => PluginDatabaseinventoryCredential::getFormURL(false), + ]; } return $menu; diff --git a/inc/task.class.php b/inc/task.class.php index 46c2d34..d9ab611 100644 --- a/inc/task.class.php +++ b/inc/task.class.php @@ -32,6 +32,7 @@ class PluginDatabaseinventoryTask extends CommonGLPI { public static function inventoryGetParams(array $params) { + /** @var DBmysql $DB */ global $DB; $agent = $params['item']; $content = $params['options']['content']; @@ -128,11 +129,14 @@ public static function inventoryGetParams(array $params) public static function handleInventoryTask(array $params) { + /** @var DBmysql $DB */ global $DB; // get asset related to the agent $computer = $params['item']->getLinkedItem(); + $database_param_found = []; + // only Computer type if (get_class($computer) == Computer::getType()) { $database_param_table = PluginDatabaseinventoryDatabaseParam::getTable() ; @@ -141,8 +145,6 @@ public static function handleInventoryTask(array $params) $computer_group_dynamic_table = PluginDatabaseinventoryComputerGroupDynamic::getTable(); $computer_group_table = PluginDatabaseinventoryComputerGroup::getTable(); - $database_param_found = []; - /* * First step : * try to load all active 'PluginDatabaseinventoryDatabaseParam' @@ -232,17 +234,17 @@ public static function handleInventoryTask(array $params) $database_param_table . ".is_active" => 1, ]; } - } - // check if Dynamic group match computer - // if true, store databaseparam - $iterator = $DB->request($criteria); - foreach ($iterator as $data) { - $dynamic_group = new PluginDatabaseinventoryComputerGroupDynamic(); - $dynamic_group->getFromDB($data['id']); - if ($dynamic_group->isDynamicSearchMatchComputer($computer)) { - if (!in_array($data['database_param_id'], $database_param_found)) { - $database_param_found[] = $data['database_param_id']; + // check if Dynamic group match computer + // if true, store databaseparam + $iterator = $DB->request($criteria); + foreach ($iterator as $data) { + $dynamic_group = new PluginDatabaseinventoryComputerGroupDynamic(); + $dynamic_group->getFromDB($data['id']); + if ($dynamic_group->isDynamicSearchMatchComputer($computer)) { + if (!in_array($data['database_param_id'], $database_param_found)) { + $database_param_found[] = $data['database_param_id']; + } } } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..ba0ed17 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,19 @@ +parameters: + parallel: + maximumNumberOfProcesses: 2 + level: 3 + bootstrapFiles: + - ../../inc/based_config.php + paths: + - inc + - front + - ajax + - hook.php + - setup.php + scanDirectories: + - ../../inc + - ../../src + stubFiles: + - ../../stubs/glpi_constants.php +rules: + - GlpiProject\Tools\PHPStan\Rules\GlobalVarTypeRule diff --git a/setup.php b/setup.php index 455067f..a5cf8f2 100644 --- a/setup.php +++ b/setup.php @@ -43,6 +43,7 @@ */ function plugin_init_databaseinventory() { + /** @var array $PLUGIN_HOOKS */ global $PLUGIN_HOOKS; $PLUGIN_HOOKS['csrf_compliant']['databaseinventory'] = true; @@ -50,7 +51,7 @@ function plugin_init_databaseinventory() $PLUGIN_HOOKS['config_page']['databaseinventory'] = 'front/menu.php'; if (!Plugin::isPluginActive('databaseinventory')) { - return false; + return; } $PLUGIN_HOOKS['handle_inventory_task']['databaseinventory'] = ['PluginDatabaseinventoryTask', 'handleInventoryTask'];
" . __('Database Inventory', 'databaseinventory') . "
" - . PluginDatabaseinventoryDatabaseParam::getTypeName(2) . "
" + . PluginDatabaseinventoryDatabaseParam::getTypeName(2) . "
"; echo Html::input( @@ -169,6 +168,7 @@ public function showForm($ID, array $options = []) public function countDynamicItem() { + /** @var DBmysql $DB */ global $DB; $count = 0; @@ -192,8 +192,8 @@ public function countDynamicItem() public function countStaticItem() { + /** @var DBmysql $DB */ global $DB; - $count = 0; $params = [ 'SELECT' => '*', @@ -209,6 +209,7 @@ public function countStaticItem() public static function install(Migration $migration) { + /** @var DBmysql $DB */ global $DB; $default_charset = DBConnection::getDefaultCharset(); @@ -248,6 +249,7 @@ public static function install(Migration $migration) public static function uninstall(Migration $migration) { + /** @var DBmysql $DB */ global $DB; $table = self::getTable(); if ($DB->tableExists($table)) { diff --git a/inc/computergroupdynamic.class.php b/inc/computergroupdynamic.class.php index 258a042..a0b9fea 100644 --- a/inc/computergroupdynamic.class.php +++ b/inc/computergroupdynamic.class.php @@ -49,7 +49,7 @@ public static function canPurge() public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - if (get_class($item) == PluginDatabaseinventoryComputerGroup::getType()) { + if ($item instanceof PluginDatabaseinventoryComputerGroup) { $count = 0; $computergroup_dynamic = new self(); if ( @@ -59,9 +59,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) ) { $count = $computergroup_dynamic->countDynamicItems(); } - $ong = []; - $ong[1] = self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count); - return $ong; + return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count); } return ''; } @@ -82,6 +80,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options return ($count) ? $count : ' 0 '; case '_virtual_dynamic_list': + /** @var array $CFG_GLPI */ global $CFG_GLPI; $value = " "; $out = " "; @@ -149,7 +148,6 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ private function countDynamicItems() { - $count = 0; $search_params = Search::manageParams('Computer', unserialize($this->fields['search'])); $data = Search::prepareDatasForSearch('Computer', $search_params); Search::constructSQL($data); @@ -160,8 +158,6 @@ private function countDynamicItems() public function isDynamicSearchMatchComputer(Computer $computer) { - $count = 0; - // add new criteria to force computer ID $search = unserialize($this->fields['search']); $search['criteria'][] = [ @@ -248,6 +244,7 @@ function() { public static function install(Migration $migration) { + /** @var DBmysql $DB */ global $DB; $default_charset = DBConnection::getDefaultCharset(); @@ -272,6 +269,7 @@ public static function install(Migration $migration) public static function uninstall(Migration $migration) { + /** @var DBmysql $DB */ global $DB; $table = self::getTable(); if ($DB->tableExists($table)) { diff --git a/inc/computergroupstatic.class.php b/inc/computergroupstatic.class.php index 32e9ae2..b00fcd6 100644 --- a/inc/computergroupstatic.class.php +++ b/inc/computergroupstatic.class.php @@ -64,12 +64,9 @@ public static function canPurge() public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - if (get_class($item) == PluginDatabaseinventoryComputerGroup::getType()) { - $count = 0; + if ($item instanceof PluginDatabaseinventoryComputerGroup) { $count = countElementsInTable(self::getTable(), ['plugin_databaseinventory_computergroups_id' => $item->getID()]); - $ong = []; - $ong[1] = self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count); - return $ong; + return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count); } return ''; } @@ -86,6 +83,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ private static function showForItem(PluginDatabaseinventoryComputerGroup $computergroup) { + /** @var DBmysql $DB */ global $DB; $ID = $computergroup->getField('id'); @@ -108,9 +106,10 @@ private static function showForItem(PluginDatabaseinventoryComputerGroup $comput } $number = count($datas); + $rand = mt_rand(); + echo "
"; if ($computergroup->canAddItem('itemtype')) { - $rand = mt_rand(); echo "
"; echo "
tableExists($table)) { diff --git a/inc/contactlog.class.php b/inc/contactlog.class.php index f5e78bd..802a69a 100644 --- a/inc/contactlog.class.php +++ b/inc/contactlog.class.php @@ -55,20 +55,13 @@ public static function getTypeName($nb = 0) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - switch ($item->getType()) { - case PluginDatabaseinventoryDatabaseParam::getType(): - $count = 0; + switch (get_class($item)) { + case PluginDatabaseinventoryDatabaseParam::class: $count = countElementsInTable(self::getTable(), ['plugin_databaseinventory_databaseparams_id' => $item->getID()]); - $ong = []; - $ong[1] = self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count); - return $ong; - break; - case Agent::getType(): - $count = 0; + return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count); + case Agent::class: $count = countElementsInTable(self::getTable(), ['agents_id' => $item->getID()]); - $ong = []; - $ong[2] = self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count); - return $ong; + return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count); } return ''; } @@ -88,6 +81,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ private static function showForDatabaseParams(PluginDatabaseinventoryDatabaseParam $databaseparams) { + /** @var DBmysql $DB */ global $DB; $ID = $databaseparams->getField('id'); @@ -109,7 +103,6 @@ private static function showForDatabaseParams(PluginDatabaseinventoryDatabasePar $rand = mt_rand(); $canread = $databaseparams->can($ID, READ); - $canedit = false; echo "
"; if ($canread) { echo "
"; @@ -119,13 +112,6 @@ private static function showForDatabaseParams(PluginDatabaseinventoryDatabasePar $header_bottom = ''; $header_end = ''; - if ($canedit) { - $header_top .= "
" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); - $header_top .= "" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); - $header_bottom .= "" . PluginDatabaseinventoryCredential::getTypeName(0) . "" . Agent::getTypeName(0) . "" . __('Date') . "" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); - $header_top .= "" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); - $header_bottom .= "" . PluginDatabaseinventoryCredential::getTypeName(0) . "" . PluginDatabaseinventoryDatabaseParam::getTypeName(0) . "" . __('Date') . "