diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a5d02c9..ac8aba9 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -20,7 +20,7 @@ jobs: name: "Generate CI matrix" uses: "glpi-project/plugin-ci-workflows/.github/workflows/generate-ci-matrix.yml@v1" with: - glpi-version: "11.0.x" + glpi-version: "12.0.x" ci: name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}" needs: "generate-ci-matrix" diff --git a/CHANGELOG.md b/CHANGELOG.md index 350398e..cc74e0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [UNRELEASED] +### Added + +- GLPI 12 compatibility + ### Fixed - Fix leftover data (profile rights and config values) after plugin uninstall diff --git a/ajax/cron.php b/ajax/cron.php index 78a88aa..9f585d4 100644 --- a/ajax/cron.php +++ b/ajax/cron.php @@ -40,7 +40,7 @@ Html::header_nocache(); -Session::checkRight('config', UPDATE); +Session::checkRight(Config::$rightname, UPDATE); /** @var DBmysql $DB */ global $DB; diff --git a/composer.json b/composer.json index ca7a0a3..3084ecd 100644 --- a/composer.json +++ b/composer.json @@ -2,9 +2,6 @@ "require": { "php": ">=8.2" }, - "require-dev": { - "glpi-project/tools": "^0.8.1" - }, "config": { "optimize-autoloader": true, "platform": { diff --git a/composer.lock b/composer.lock index 5a090aa..e798ec8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,876 +4,9 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0bb7734a8837cdd118f20d259d3613e7", + "content-hash": "4cacb822b12bf0d2a0dbcf952b20ef7b", "packages": [], - "packages-dev": [ - { - "name": "glpi-project/tools", - "version": "0.8.3", - "source": { - "type": "git", - "url": "https://github.com/glpi-project/tools.git", - "reference": "8ea2a7d4702a858f4b0360ba7d4f1841a5e77026" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/glpi-project/tools/zipball/8ea2a7d4702a858f4b0360ba7d4f1841a5e77026", - "reference": "8ea2a7d4702a858f4b0360ba7d4f1841a5e77026", - "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", - "tools/plugin-release" - ], - "type": "library", - "autoload": { - "psr-4": { - "GlpiProject\\Tools\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "GPL-3.0-or-later" - ], - "authors": [ - { - "name": "Teclib'", - "email": "glpi@teclib.com", - "homepage": "http://teclib-group.com" - } - ], - "description": "Various tools for GLPI and its plugins", - "keywords": [ - "glpi", - "plugins", - "tools" - ], - "support": { - "issues": "https://github.com/glpi-project/tools/issues", - "source": "https://github.com/glpi-project/tools" - }, - "time": "2025-10-14T10:26:06+00:00" - }, - { - "name": "psr/container", - "version": "2.0.2", - "source": { - "type": "git", - "url": "https://github.com/php-fig/container.git", - "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963", - "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963", - "shasum": "" - }, - "require": { - "php": ">=7.4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Container\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common Container Interface (PHP FIG PSR-11)", - "homepage": "https://github.com/php-fig/container", - "keywords": [ - "PSR-11", - "container", - "container-interface", - "container-interop", - "psr" - ], - "support": { - "issues": "https://github.com/php-fig/container/issues", - "source": "https://github.com/php-fig/container/tree/2.0.2" - }, - "time": "2021-11-05T16:47:00+00:00" - }, - { - "name": "symfony/console", - "version": "v6.4.27", - "source": { - "type": "git", - "url": "https://github.com/symfony/console.git", - "reference": "13d3176cf8ad8ced24202844e9f95af11e2959fc" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/13d3176cf8ad8ced24202844e9f95af11e2959fc", - "reference": "13d3176cf8ad8ced24202844e9f95af11e2959fc", - "shasum": "" - }, - "require": { - "php": ">=8.1", - "symfony/deprecation-contracts": "^2.5|^3", - "symfony/polyfill-mbstring": "~1.0", - "symfony/service-contracts": "^2.5|^3", - "symfony/string": "^5.4|^6.0|^7.0" - }, - "conflict": { - "symfony/dependency-injection": "<5.4", - "symfony/dotenv": "<5.4", - "symfony/event-dispatcher": "<5.4", - "symfony/lock": "<5.4", - "symfony/process": "<5.4" - }, - "provide": { - "psr/log-implementation": "1.0|2.0|3.0" - }, - "require-dev": { - "psr/log": "^1|^2|^3", - "symfony/config": "^5.4|^6.0|^7.0", - "symfony/dependency-injection": "^5.4|^6.0|^7.0", - "symfony/event-dispatcher": "^5.4|^6.0|^7.0", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/lock": "^5.4|^6.0|^7.0", - "symfony/messenger": "^5.4|^6.0|^7.0", - "symfony/process": "^5.4|^6.0|^7.0", - "symfony/stopwatch": "^5.4|^6.0|^7.0", - "symfony/var-dumper": "^5.4|^6.0|^7.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Console\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Eases the creation of beautiful and testable command line interfaces", - "homepage": "https://symfony.com", - "keywords": [ - "cli", - "command-line", - "console", - "terminal" - ], - "support": { - "source": "https://github.com/symfony/console/tree/v6.4.27" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://github.com/nicolas-grekas", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2025-10-06T10:25:16+00:00" - }, - { - "name": "symfony/deprecation-contracts", - "version": "v3.6.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62", - "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "type": "library", - "extra": { - "thanks": { - "url": "https://github.com/symfony/contracts", - "name": "symfony/contracts" - }, - "branch-alias": { - "dev-main": "3.6-dev" - } - }, - "autoload": { - "files": [ - "function.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "A generic function and convention to trigger deprecation notices", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.6.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2024-09-25T14:21:43+00:00" - }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.33.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/a3cc8b044a6ea513310cbd48ef7333b384945638", - "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638", - "shasum": "" - }, - "require": { - "php": ">=7.2" - }, - "provide": { - "ext-ctype": "*" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "thanks": { - "url": "https://github.com/symfony/polyfill", - "name": "symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.33.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://github.com/nicolas-grekas", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2024-09-09T11:45:10+00:00" - }, - { - "name": "symfony/polyfill-intl-grapheme", - "version": "v1.33.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "380872130d3a5dd3ace2f4010d95125fde5d5c70" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/380872130d3a5dd3ace2f4010d95125fde5d5c70", - "reference": "380872130d3a5dd3ace2f4010d95125fde5d5c70", - "shasum": "" - }, - "require": { - "php": ">=7.2" - }, - "suggest": { - "ext-intl": "For best performance" - }, - "type": "library", - "extra": { - "thanks": { - "url": "https://github.com/symfony/polyfill", - "name": "symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Intl\\Grapheme\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for intl's grapheme_* functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "grapheme", - "intl", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.33.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://github.com/nicolas-grekas", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2025-06-27T09:58:17+00:00" - }, - { - "name": "symfony/polyfill-intl-normalizer", - "version": "v1.33.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "3833d7255cc303546435cb650316bff708a1c75c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/3833d7255cc303546435cb650316bff708a1c75c", - "reference": "3833d7255cc303546435cb650316bff708a1c75c", - "shasum": "" - }, - "require": { - "php": ">=7.2" - }, - "suggest": { - "ext-intl": "For best performance" - }, - "type": "library", - "extra": { - "thanks": { - "url": "https://github.com/symfony/polyfill", - "name": "symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Intl\\Normalizer\\": "" - }, - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for intl's Normalizer class and related functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "intl", - "normalizer", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.33.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://github.com/nicolas-grekas", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2024-09-09T11:45:10+00:00" - }, - { - "name": "symfony/polyfill-mbstring", - "version": "v1.33.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "6d857f4d76bd4b343eac26d6b539585d2bc56493" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493", - "reference": "6d857f4d76bd4b343eac26d6b539585d2bc56493", - "shasum": "" - }, - "require": { - "ext-iconv": "*", - "php": ">=7.2" - }, - "provide": { - "ext-mbstring": "*" - }, - "suggest": { - "ext-mbstring": "For best performance" - }, - "type": "library", - "extra": { - "thanks": { - "url": "https://github.com/symfony/polyfill", - "name": "symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for the Mbstring extension", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "mbstring", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.33.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://github.com/nicolas-grekas", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2024-12-23T08:48:59+00:00" - }, - { - "name": "symfony/service-contracts", - "version": "v3.6.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/service-contracts.git", - "reference": "45112560a3ba2d715666a509a0bc9521d10b6c43" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/45112560a3ba2d715666a509a0bc9521d10b6c43", - "reference": "45112560a3ba2d715666a509a0bc9521d10b6c43", - "shasum": "" - }, - "require": { - "php": ">=8.1", - "psr/container": "^1.1|^2.0", - "symfony/deprecation-contracts": "^2.5|^3" - }, - "conflict": { - "ext-psr": "<1.1|>=2" - }, - "type": "library", - "extra": { - "thanks": { - "url": "https://github.com/symfony/contracts", - "name": "symfony/contracts" - }, - "branch-alias": { - "dev-main": "3.6-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Contracts\\Service\\": "" - }, - "exclude-from-classmap": [ - "/Test/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Generic abstractions related to writing services", - "homepage": "https://symfony.com", - "keywords": [ - "abstractions", - "contracts", - "decoupling", - "interfaces", - "interoperability", - "standards" - ], - "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.6.1" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://github.com/nicolas-grekas", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2025-07-15T11:30:57+00:00" - }, - { - "name": "symfony/string", - "version": "v7.4.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/string.git", - "reference": "d50e862cb0a0e0886f73ca1f31b865efbb795003" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/d50e862cb0a0e0886f73ca1f31b865efbb795003", - "reference": "d50e862cb0a0e0886f73ca1f31b865efbb795003", - "shasum": "" - }, - "require": { - "php": ">=8.2", - "symfony/deprecation-contracts": "^2.5|^3.0", - "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-intl-grapheme": "~1.33", - "symfony/polyfill-intl-normalizer": "~1.0", - "symfony/polyfill-mbstring": "~1.0" - }, - "conflict": { - "symfony/translation-contracts": "<2.5" - }, - "require-dev": { - "symfony/emoji": "^7.1|^8.0", - "symfony/http-client": "^6.4|^7.0|^8.0", - "symfony/intl": "^6.4|^7.0|^8.0", - "symfony/translation-contracts": "^2.5|^3.0", - "symfony/var-exporter": "^6.4|^7.0|^8.0" - }, - "type": "library", - "autoload": { - "files": [ - "Resources/functions.php" - ], - "psr-4": { - "Symfony\\Component\\String\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way", - "homepage": "https://symfony.com", - "keywords": [ - "grapheme", - "i18n", - "string", - "unicode", - "utf-8", - "utf8" - ], - "support": { - "source": "https://github.com/symfony/string/tree/v7.4.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://github.com/nicolas-grekas", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2025-11-27T13:27:24+00:00" - }, - { - "name": "twig/twig", - "version": "v3.22.0", - "source": { - "type": "git", - "url": "https://github.com/twigphp/Twig.git", - "reference": "4509984193026de413baf4ba80f68590a7f2c51d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/4509984193026de413baf4ba80f68590a7f2c51d", - "reference": "4509984193026de413baf4ba80f68590a7f2c51d", - "shasum": "" - }, - "require": { - "php": ">=8.1.0", - "symfony/deprecation-contracts": "^2.5|^3", - "symfony/polyfill-ctype": "^1.8", - "symfony/polyfill-mbstring": "^1.3" - }, - "require-dev": { - "phpstan/phpstan": "^2.0", - "psr/container": "^1.0|^2.0", - "symfony/phpunit-bridge": "^5.4.9|^6.4|^7.0" - }, - "type": "library", - "autoload": { - "files": [ - "src/Resources/core.php", - "src/Resources/debug.php", - "src/Resources/escaper.php", - "src/Resources/string_loader.php" - ], - "psr-4": { - "Twig\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com", - "homepage": "http://fabien.potencier.org", - "role": "Lead Developer" - }, - { - "name": "Twig Team", - "role": "Contributors" - }, - { - "name": "Armin Ronacher", - "email": "armin.ronacher@active-4.com", - "role": "Project Founder" - } - ], - "description": "Twig, the flexible, fast, and secure template language for PHP", - "homepage": "https://twig.symfony.com", - "keywords": [ - "templating" - ], - "support": { - "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.22.0" - }, - "funding": [ - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/twig/twig", - "type": "tidelift" - } - ], - "time": "2025-10-29T15:56:47+00:00" - } - ], + "packages-dev": [], "aliases": [], "minimum-stability": "stable", "stability-flags": {}, @@ -886,5 +19,5 @@ "platform-overrides": { "php": "8.2.99" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.9.0" } diff --git a/front/menu.php b/front/menu.php index b6dc5b9..2012964 100644 --- a/front/menu.php +++ b/front/menu.php @@ -64,7 +64,7 @@ TemplateRenderer::getInstance()->display('@jamf/menu.html.twig', [ 'links' => $links, - 'can_configure' => Session::haveRight('config', UPDATE), + 'can_configure' => Session::haveRight(Config::$rightname, UPDATE), 'config_url' => Config::getFormURL() . '?forcetab=PluginJamfConfig$1', ]); diff --git a/hook.php b/hook.php index 8aceb30..51120d6 100644 --- a/hook.php +++ b/hook.php @@ -75,7 +75,7 @@ function plugin_jamf_getAddSearchOptions($itemtype) $opt = []; $plugin = new Plugin(); if ($plugin->isActivated('jamf') && ($itemtype === 'Computer' || $itemtype === 'Phone')) { - $opt = [ + return [ '22002' => [ 'table' => 'glpi_plugin_jamf_devices', 'field' => 'last_inventory', @@ -236,9 +236,7 @@ function plugin_jamf_getAddSearchOptions($itemtype) function plugin_jamf_dashboardCards($cards = []) { - if (is_null($cards)) { - $cards = []; - } + $cards ??= []; $cards = array_merge($cards, PluginJamfExtensionAttribute::dashboardCards()); diff --git a/inc/abstractdevice.class.php b/inc/abstractdevice.class.php index 4d0e147..9a1adcb 100644 --- a/inc/abstractdevice.class.php +++ b/inc/abstractdevice.class.php @@ -35,13 +35,13 @@ */ abstract class PluginJamfAbstractDevice extends CommonDBChild { - public static $itemtype = 'itemtype'; + public static string $itemtype = 'itemtype'; - public static $items_id = 'items_id'; + public static string $items_id = 'items_id'; public static $jamftype_name; - public static $mustBeAttached = false; + public static bool $mustBeAttached = false; /** * Display the extra information for Jamf devices on the main Computer or Phone tab. @@ -67,7 +67,7 @@ private static function purgeItemCommon(CommonDBTM $item) /** @var DBmysql $DB */ global $DB; - $jamf_class = static::getJamfItemClassForGLPIItem($item::getType(), $item->getID()); + $jamf_class = static::getJamfItemClassForGLPIItem($item::class, $item->getID()); if (!is_string($jamf_class)) { return; } @@ -108,7 +108,7 @@ public static function plugin_jamf_purgePhone(Phone $item) self::purgeItemCommon($item); $DB->delete(Item_OperatingSystem::getTable(), [ - 'itemtype' => $item::getType(), + 'itemtype' => $item::class, 'items_id' => $item->getID(), ]); } @@ -176,7 +176,7 @@ public static function getJamfItemForGLPIItem(CommonDBTM $item, $limit_to_type = ], ], 'WHERE' => [ - 'itemtype' => $item::getType(), + 'itemtype' => $item::class, 'items_id' => $item->getID(), ], ]); @@ -256,7 +256,7 @@ public function getExtensionAttributes() ], ], 'WHERE' => [ - $item_ext_table . '.itemtype' => static::getType(), + $item_ext_table . '.itemtype' => static::class, 'items_id' => $this->getID(), ], ]); diff --git a/inc/computer.class.php b/inc/computer.class.php index 0224568..870d617 100644 --- a/inc/computer.class.php +++ b/inc/computer.class.php @@ -37,7 +37,7 @@ */ class PluginJamfComputer extends PluginJamfAbstractDevice { - public static $rightname = 'plugin_jamf_computer'; + public static string $rightname = 'plugin_jamf_computer'; public static $jamftype_name = 'Computer'; diff --git a/inc/computersync.class.php b/inc/computersync.class.php index 896fb53..8832a5a 100644 --- a/inc/computersync.class.php +++ b/inc/computersync.class.php @@ -133,7 +133,7 @@ protected function syncOS(): PluginJamfDeviceSync 'operatingsystemversions_id' => $os_version->getID(), 'date_creation' => $_SESSION['glpi_currenttime'], ], [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), ]); } catch (Exception) { @@ -186,11 +186,11 @@ protected function syncSoftware(): PluginJamfDeviceSync 'is_recursive' => $this->item->fields['is_recursive'], ]); $this->applyDesiredState('Item_SoftwareVersion', [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'softwareversions_id' => $software_version->getID(), ], [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'softwareversions_id' => $software_version->getID(), 'entities_id' => $this->item->fields['entities_id'], @@ -206,7 +206,7 @@ protected function syncSoftware(): PluginJamfDeviceSync foreach ($to_remove_software as $to_remove) { $DB->delete(Item_SoftwareVersion::getTable(), [ SoftwareVersion::getTable() . '.softwares_id' => $to_remove['softwares_id'], - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), ], [ 'LEFT JOIN' => [ @@ -294,7 +294,7 @@ protected function syncPurchasing(): PluginJamfDeviceSync } $this->db->updateOrInsert(Infocom::getTable(), $infocom_changes, [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), ]); } catch (Exception) { @@ -312,11 +312,11 @@ protected function syncExtensionAttributes(): PluginJamfDeviceSync { if (!$this->config['sync_general'] || !isset($this->data['extension_attributes'])) { $this->status['syncExtensionAttributes'] = self::STATUS_SKIPPED; - return $this; - } elseif ($this->config['sync_general'] && $this->jamfplugin_device === null) { - $this->status['syncExtensionAttributes'] = self::STATUS_DEFERRED; + } + if ($this->jamfplugin_device === null) { + $this->status['syncExtensionAttributes'] = self::STATUS_DEFERRED; return $this; } @@ -336,7 +336,7 @@ protected function syncExtensionAttributes(): PluginJamfDeviceSync $this->db->updateOrInsert(PluginJamfItem_ExtensionAttribute::getTable(), ['value' => $attr['value']], [ 'glpi_plugin_jamf_extensionattributes_id' => $attr_match['id'], 'items_id' => $this->jamfplugin_device->getID(), - 'itemtype' => $this->jamfplugin_device::getType(), + 'itemtype' => $this->jamfplugin_device::class, ]); } } @@ -398,11 +398,11 @@ protected function syncNetwork(): PluginJamfDeviceSync 'comment' => 'Created by Jamf Plugin for GLPI', ]); $item_wifi = $this->createOrGetItem('Item_DeviceNetworkCard', [ - 'itemtype' => $this->item->getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'devicenetworkcards_id' => $wifi->getID(), ], [ - 'itemtype' => $this->item->getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'devicenetworkcards_id' => $wifi->getID(), 'is_dynamic' => 1, @@ -411,12 +411,12 @@ protected function syncNetwork(): PluginJamfDeviceSync ]); $netport = $this->createOrGetItem('NetworkPort', [ - 'itemtype' => $this->item->getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'instantiation_type' => 'NetworkPortWifi', 'logical_number' => 0, ], [ - 'itemtype' => $this->item->getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'instantiation_type' => 'NetworkPortWifi', 'logical_number' => 0, @@ -442,7 +442,7 @@ protected function syncNetwork(): PluginJamfDeviceSync 'entities_id' => $this->item->fields['entities_id'], 'itemtype' => 'NetworkName', 'items_id' => $network_name->getID(), - 'mainitemtype' => $this->item->getType(), + 'mainitemtype' => $this->item::class, 'mainitems_id' => $this->item->getID(), 'is_dynamic' => 1, ]); @@ -451,7 +451,7 @@ protected function syncNetwork(): PluginJamfDeviceSync 'entities_id' => $this->item->fields['entities_id'], 'itemtype' => 'NetworkName', 'items_id' => $network_name->getID(), - 'mainitemtype' => $this->item->getType(), + 'mainitemtype' => $this->item::class, 'mainitems_id' => $this->item->getID(), 'is_dynamic' => 1, 'name' => $general['ip_address'], @@ -500,7 +500,7 @@ protected function syncGeneralJamfPluginItem(): PluginJamfDeviceSync $this->commondevice_changes['enroll_date'] = $enroll_date; } - $this->commondevice_changes['itemtype'] = $this->item::getType(); + $this->commondevice_changes['itemtype'] = $this->item::class; $this->commondevice_changes['items_id'] = $this->item->getID(); $this->commondevice_changes['jamf_items_id'] = $general['id']; $this->commondevice_changes['udid'] = $general['udid']; @@ -538,11 +538,11 @@ protected function syncComponents(): PluginJamfDeviceSync 'is_recursive' => '1', ]); $this->applyDesiredState('Item_DeviceFirmware', [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'devicefirmwares_id' => $boot_rom->getID(), ], [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'devicefirmwares_id' => $boot_rom->getID(), 'is_deleted' => 0, @@ -558,12 +558,12 @@ protected function syncComponents(): PluginJamfDeviceSync foreach ($disk['partitions'] as $partition) { // Volume $this->applyDesiredState(Item_Disk::class, [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'mountpoint' => '', 'name' => $partition['name'], ], [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'name' => $partition['name'], 'mountpoint' => '', @@ -712,7 +712,7 @@ public static function import(string $itemtype, int $jamf_items_id, $use_transac if ($items_id) { // Link $r = $DB->insert('glpi_plugin_jamf_devices', [ - 'itemtype' => $item::getType(), + 'itemtype' => $item::class, 'items_id' => $items_id, 'udid' => $jamf_item['general']['udid'], 'jamf_type' => static::$jamf_itemtype, diff --git a/inc/config.class.php b/inc/config.class.php index 9aac45b..b291aea 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -36,12 +36,12 @@ */ class PluginJamfConfig extends CommonDBTM { - protected static $notable = true; + protected static bool $notable = true; public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - if (!$withtemplate && $item::getType() === Config::class) { - return self::createTabEntry(__s("Jamf", "jamf"), 0, $item::getType(), self::getIcon()); + if (!$withtemplate && $item::class === Config::class) { + return self::createTabEntry(__s("Jamf", "jamf"), 0, $item::class, self::getIcon()); } return ''; @@ -49,7 +49,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) public function showForm($ID = -1, array $options = []) { - if (!Session::haveRight('config', UPDATE)) { + if (!Session::haveRight(Config::$rightname, UPDATE)) { return false; } @@ -73,7 +73,7 @@ public function showForm($ID = -1, array $options = []) public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - if ($item::getType() === Config::class) { + if ($item::class === Config::class) { return (new self())->showForm(); } @@ -95,9 +95,7 @@ public static function undiscloseConfigValue($fields) public static function getConfig(bool $force_all = false): array { static $config = null; - if ($config === null) { - $config = Config::getConfigurationValues('plugin:Jamf'); - } + $config ??= Config::getConfigurationValues('plugin:Jamf'); if (!$force_all) { return self::undiscloseConfigValue($config); diff --git a/inc/connection.class.php b/inc/connection.class.php index 51740d4..2b7fbf0 100644 --- a/inc/connection.class.php +++ b/inc/connection.class.php @@ -90,9 +90,7 @@ public function setConnectionConfig($jssserver, $jssuser, $jsspassword) public function getServerVersion() { static $version = null; - if (is_null($version)) { - $version = PluginJamfAPI::getJamfProVersion(); - } + $version ??= PluginJamfAPI::getJamfProVersion(); return $version; } diff --git a/inc/dbutil.class.php b/inc/dbutil.class.php index 0918deb..0e09de8 100644 --- a/inc/dbutil.class.php +++ b/inc/dbutil.class.php @@ -52,19 +52,7 @@ public static function dropTableOrDie(string $table, string $message = '') return true; } - $res = $DB->doQuery('DROP TABLE' . $DB::quoteName($table)); - if (!$res) { - //TRANS: %1$s is the description, %2$s is the query, %3$s is the error message - $message = sprintf( - _x('error', '%1$s - Error during the drop of the table %2$s - Error is %3$s', 'jamf'), - $message, - $table, - $DB->error(), - ); - throw new RuntimeException($message); - } - - return $res; + return $DB->doQuery('DROP TABLE' . $DB::quoteName($table)); } public static function truncate($table) diff --git a/inc/devicesync.class.php b/inc/devicesync.class.php index d1bbe6d..bbb9638 100644 --- a/inc/devicesync.class.php +++ b/inc/devicesync.class.php @@ -314,12 +314,12 @@ protected function finalizeSync() 'id' => $this->item->getID(), ] + $this->item_changes); foreach ($this->extitem_changes as $key => $value) { - PluginJamfExtField::setValue($this->item::getType(), $this->item->getID(), $key, $value); + PluginJamfExtField::setValue($this->item::class, $this->item->getID(), $key, $value); } // Update or Add Jamf Item $this->db->updateOrInsert('glpi_plugin_jamf_devices', $this->commondevice_changes, [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), ]); $device_id = -1; @@ -328,7 +328,7 @@ protected function finalizeSync() 'SELECT' => ['id'], 'FROM' => 'glpi_plugin_jamf_devices', 'WHERE' => [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), ], ]); @@ -340,7 +340,7 @@ protected function finalizeSync() 'glpi_plugin_jamf_devices_id' => $device_id, ]); - if ($this->jamfplugin_device === null || empty($this->jamfplugin_device->fields)) { + if ($this->jamfplugin_device === null || $this->jamfplugin_device->fields === []) { if (!is_a(static::$jamfplugin_itemtype, CommonDBTM::class, true)) { throw new RuntimeException('Invalid jamfplugin_itemtype: ' . static::$jamfplugin_itemtype); @@ -351,7 +351,7 @@ protected function finalizeSync() 'SELECT' => ['id'], 'FROM' => static::$jamfplugin_itemtype::getTable(), 'WHERE' => [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), ], 'LEFT JOIN' => [ diff --git a/inc/item_extensionattribute.class.php b/inc/item_extensionattribute.class.php index 7dec6ce..540c671 100644 --- a/inc/item_extensionattribute.class.php +++ b/inc/item_extensionattribute.class.php @@ -38,9 +38,9 @@ */ class PluginJamfItem_ExtensionAttribute extends CommonDBChild { - public static $itemtype = 'itemtype'; + public static string $itemtype = 'itemtype'; - public static $items_id = 'items_id'; + public static string $items_id = 'items_id'; public static function getTypeName($nb = 1) { @@ -53,7 +53,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) return ''; } - $jamf_class = PluginJamfAbstractDevice::getJamfItemClassForGLPIItem($item::getType(), $item->getID()); + $jamf_class = PluginJamfAbstractDevice::getJamfItemClassForGLPIItem($item::class, $item->getID()); if ($jamf_class === null) { return ''; } @@ -85,7 +85,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ public static function showForItem(CommonDBTM $item) { - $jamf_class = PluginJamfAbstractDevice::getJamfItemClassForGLPIItem($item::getType(), $item->getID()); + $jamf_class = PluginJamfAbstractDevice::getJamfItemClassForGLPIItem($item::class, $item->getID()); if ($jamf_class === null || !$jamf_class::canView()) { return false; } diff --git a/inc/item_mdmcommand.class.php b/inc/item_mdmcommand.class.php index 363fb5b..c522d5c 100644 --- a/inc/item_mdmcommand.class.php +++ b/inc/item_mdmcommand.class.php @@ -41,7 +41,7 @@ */ class PluginJamfItem_MDMCommand extends CommonDBTM { - public static $rightname = 'plugin_jamf_mdmcommand'; + public static string $rightname = 'plugin_jamf_mdmcommand'; public static function getTypeName($nb = 0) { @@ -54,7 +54,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) return ''; } - $jamf_class = PluginJamfAbstractDevice::getJamfItemClassForGLPIItem($item::getType(), $item->getID()); + $jamf_class = PluginJamfAbstractDevice::getJamfItemClassForGLPIItem($item::class, $item->getID()); if ($jamf_class !== PluginJamfMobileDevice::class || !PluginJamfMobileDevice::canView()) { return ''; } @@ -168,14 +168,15 @@ private static function getAvailableUpdates($model_identifier): array // Sort so newest updates are first usort($data['iOS'], static fn($a, $b) => version_compare($b['ProductVersion'], $a['ProductVersion'])); usort($data['macOS'], static fn($a, $b) => version_compare($b['ProductVersion'], $a['ProductVersion'])); - if ($data['iOS'] !== []) { return array_column($data['iOS'], 'ProductVersion'); - } elseif ($data['macOS'] !== []) { + } + + if ($data['macOS'] !== []) { return array_column($data['macOS'], 'ProductVersion'); - } else { - return []; } + + return []; } public static function applySpecificParams(&$commands, PluginJamfAbstractDevice $mobiledevice): void @@ -209,7 +210,7 @@ public static function showForItem(CommonDBTM $item) 'commands' => $commands, 'pending_commands' => $item_commands['pending'], 'failed_commands' => $item_commands['failed'], - 'itemtype' => $item->getType(), + 'itemtype' => $item::class, 'items_id' => $item->getID(), 'jamf_itemtype' => 'MobileDevice', 'jamf_items_id' => $mobiledevice->getID(), diff --git a/inc/mobiledevice.class.php b/inc/mobiledevice.class.php index de980f9..fe7998b 100644 --- a/inc/mobiledevice.class.php +++ b/inc/mobiledevice.class.php @@ -37,11 +37,11 @@ */ class PluginJamfMobileDevice extends PluginJamfAbstractDevice { - public static $itemtype = 'itemtype'; + public static string $itemtype = 'itemtype'; - public static $items_id = 'items_id'; + public static string $items_id = 'items_id'; - public static $rightname = 'plugin_jamf_mobiledevice'; + public static string $rightname = 'plugin_jamf_mobiledevice'; public static function getTypeName($nb = 1) { @@ -77,7 +77,7 @@ private static function purgeItemCommon(CommonDBTM $item) global $DB; $DB->delete(self::getTable(), [ - 'itemtype' => $item::getType(), + 'itemtype' => $item::class, 'items_id' => $item->getID(), ]); } @@ -101,7 +101,7 @@ public static function plugin_jamf_purgePhone(Phone $item) self::purgeItemCommon($item); $DB->delete(Item_OperatingSystem::getTable(), [ - 'itemtype' => $item::getType(), + 'itemtype' => $item::class, 'items_id' => $item->getID(), ]); } @@ -271,7 +271,7 @@ public static function showForItem(array $params) /** @var CommonDBTM $item */ $item = $params['item']; - if (!self::canView() || ($item::getType() !== 'Computer' && $item::getType() !== 'Phone')) { + if (!self::canView() || ($item::class !== 'Computer' && $item::class !== 'Phone')) { return false; } @@ -356,7 +356,7 @@ function syncDevice(itemtype, items_id) { ], 'sync' => [ 'caption' => _x('action', 'Sync now', 'jamf'), - 'on_click' => sprintf('syncDevice("%s", %d); return false;', $item::getType(), $item->getID()), + 'on_click' => sprintf('syncDevice("%s", %d); return false;', $item::class, $item->getID()), ], ], 'extra_js' => $js, @@ -401,9 +401,11 @@ function syncDevice(itemtype, items_id) { ], 'lost_location' => [ 'caption' => _x('field', 'GPS', 'jamf'), - 'value' => Html::link(sprintf('%s, %s', $lat, $long), sprintf('https://www.google.com/maps/place/%s,%s', $lat, $long), [ - 'display' => false, - ]), + 'value' => sprintf( + '%2$s', + htmlescape(sprintf('https://www.google.com/maps/place/%s,%s', $lat, $long)), + htmlescape(sprintf('%s, %s', $lat, $long)), + ), ], 'lost_location_altitude' => [ 'caption' => _x('field', 'Altitude', 'jamf'), diff --git a/inc/mobilesync.class.php b/inc/mobilesync.class.php index c32bf60..364b3c1 100644 --- a/inc/mobilesync.class.php +++ b/inc/mobilesync.class.php @@ -48,7 +48,7 @@ protected function syncGeneral(): PluginJamfDeviceSync try { $general = $this->data['general']; - $itemtype = $this->item::getType(); + $itemtype = $this->item::class; if (($general['name'] !== $this->item->fields['name'])) { $this->item_changes['name'] = $general['name']; @@ -156,7 +156,7 @@ protected function syncOS(): PluginJamfDeviceSync 'operatingsystemversions_id' => $os_version->getID(), 'date_creation' => $_SESSION['glpi_currenttime'], ], [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), ]); } catch (Exception) { @@ -242,13 +242,13 @@ protected function syncSoftware(): PluginJamfDeviceSync $item_softwareversion = new Item_SoftwareVersion(); $item_softwareversion_matches = $item_softwareversion->find([ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'softwareversions_id' => $softwareversion_id, ]); if (!count($item_softwareversion_matches)) { $item_softwareversion->add([ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'softwareversions_id' => $softwareversion_id, 'entities_id' => $this->item->fields['entities_id'], @@ -265,7 +265,7 @@ protected function syncSoftware(): PluginJamfDeviceSync foreach ($to_remove_software as $to_remove) { $DB->delete(Item_SoftwareVersion::getTable(), [ SoftwareVersion::getTable() . '.softwares_id' => $to_remove['softwares_id'], - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), ], [ 'LEFT JOIN' => [ @@ -354,7 +354,7 @@ protected function syncPurchasing(): PluginJamfDeviceSync } $this->db->updateOrInsert(Infocom::getTable(), $infocom_changes, [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), ]); } catch (Exception) { @@ -372,11 +372,11 @@ protected function syncExtensionAttributes(): PluginJamfDeviceSync { if (!$this->config['sync_general'] || !isset($this->data['extension_attributes'])) { $this->status['syncExtensionAttributes'] = self::STATUS_SKIPPED; - return $this; - } elseif ($this->config['sync_general'] && ($this->jamfplugin_device === null || empty($this->jamfplugin_device->fields))) { - $this->status['syncExtensionAttributes'] = self::STATUS_DEFERRED; + } + if ($this->jamfplugin_device === null || $this->jamfplugin_device->fields === []) { + $this->status['syncExtensionAttributes'] = self::STATUS_DEFERRED; return $this; } @@ -395,7 +395,7 @@ protected function syncExtensionAttributes(): PluginJamfDeviceSync $this->db->updateOrInsert(PluginJamfItem_ExtensionAttribute::getTable(), ['value' => $attr['value']], [ 'glpi_plugin_jamf_extensionattributes_id' => $attr_match['id'], 'items_id' => $this->jamfplugin_device->getID(), - 'itemtype' => $this->jamfplugin_device::getType(), + 'itemtype' => $this->jamfplugin_device::class, ]); } } @@ -473,11 +473,11 @@ protected function syncNetwork(): PluginJamfDeviceSync 'comment' => 'Created by Jamf Plugin for GLPI', ]); $item_wifi = $this->createOrGetItem('Item_DeviceNetworkCard', [ - 'itemtype' => $this->item->getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'devicenetworkcards_id' => $wifi->getID(), ], [ - 'itemtype' => $this->item->getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'devicenetworkcards_id' => $wifi->getID(), 'is_dynamic' => 1, @@ -486,12 +486,12 @@ protected function syncNetwork(): PluginJamfDeviceSync ]); $netport = $this->createOrGetItem('NetworkPort', [ - 'itemtype' => $this->item->getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'instantiation_type' => 'NetworkPortWifi', 'logical_number' => 0, ], [ - 'itemtype' => $this->item->getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'instantiation_type' => 'NetworkPortWifi', 'logical_number' => 0, @@ -517,7 +517,7 @@ protected function syncNetwork(): PluginJamfDeviceSync 'entities_id' => $this->item->fields['entities_id'], 'itemtype' => 'NetworkName', 'items_id' => $network_name->getID(), - 'mainitemtype' => $this->item->getType(), + 'mainitemtype' => $this->item::class, 'mainitems_id' => $this->item->getID(), 'is_dynamic' => 1, ]); @@ -526,7 +526,7 @@ protected function syncNetwork(): PluginJamfDeviceSync 'entities_id' => $this->item->fields['entities_id'], 'itemtype' => 'NetworkName', 'items_id' => $network_name->getID(), - 'mainitemtype' => $this->item->getType(), + 'mainitemtype' => $this->item::class, 'mainitems_id' => $this->item->getID(), 'is_dynamic' => 1, 'name' => $general['ip_address'], @@ -554,11 +554,11 @@ protected function syncNetwork(): PluginJamfDeviceSync 'comment' => 'Created by Jamf Plugin for GLPI', ]); $item_bt = $this->createOrGetItem('Item_DeviceNetworkCard', [ - 'itemtype' => $this->item->getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'devicenetworkcards_id' => $bt->getID(), ], [ - 'itemtype' => $this->item->getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'devicenetworkcards_id' => $bt->getID(), 'is_dynamic' => 1, @@ -567,12 +567,12 @@ protected function syncNetwork(): PluginJamfDeviceSync ]); $this->createOrGetItem('NetworkPort', [ - 'itemtype' => $this->item->getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'instantiation_type' => 'NetworkPortWifi', 'logical_number' => 1, ], [ - 'itemtype' => $this->item->getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'instantiation_type' => 'NetworkPortWifi', 'logical_number' => 1, @@ -618,7 +618,7 @@ protected function syncGeneralJamfPluginItem(): PluginJamfDeviceSync $this->commondevice_changes['enroll_date'] = $enroll_date; } - $this->commondevice_changes['itemtype'] = $this->item::getType(); + $this->commondevice_changes['itemtype'] = $this->item::class; $this->commondevice_changes['items_id'] = $this->item->getID(); $this->commondevice_changes['jamf_items_id'] = $general['id']; $this->commondevice_changes['udid'] = $general['udid']; @@ -651,11 +651,11 @@ protected function syncComponents(): PluginJamfDeviceSync // Volume $this->createOrGetItem(Item_Disk::class, [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'mountpoint' => '/', ], [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'name' => 'OS', 'mountpoint' => '/', @@ -682,11 +682,11 @@ protected function syncComponents(): PluginJamfDeviceSync 'caller_num' => $general['phone_number'], ]); $this->createOrGetItem(Item_DeviceSimcard::class, [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'devicesimcards_id' => $simcard->getID(), ], [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), 'devicesimcards_id' => $simcard->getID(), 'is_dynamic' => 1, @@ -862,7 +862,7 @@ public static function import(string $itemtype, int $jamf_items_id, $use_transac if ($items_id) { // Link $r = $DB->insert('glpi_plugin_jamf_devices', [ - 'itemtype' => $item::getType(), + 'itemtype' => $item::class, 'items_id' => $items_id, 'udid' => $jamf_item['general']['udid'], 'jamf_type' => static::$jamf_itemtype, diff --git a/inc/profile.class.php b/inc/profile.class.php index f468e12..b2ad79c 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -35,7 +35,7 @@ */ class PluginJamfProfile extends Profile { - public static $rightname = 'config'; + public static string $rightname = 'config'; public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { diff --git a/inc/ruleimport.class.php b/inc/ruleimport.class.php index 83d4794..9df7f08 100644 --- a/inc/ruleimport.class.php +++ b/inc/ruleimport.class.php @@ -36,7 +36,7 @@ */ class PluginJamfRuleImport extends Rule { - public static $rightname = 'plugin_jamf_ruleimport'; + public static string $rightname = 'plugin_jamf_ruleimport'; public $can_sort = true; @@ -90,8 +90,8 @@ public function displayAdditionalRuleCondition($condition, $crit, $name, $value, { if (isset($crit['field']) && $crit['field'] === 'itemtype') { Dropdown::showFromArray($name, [ - Computer::getType() => Computer::getTypeName(1), - Phone::getType() => Phone::getTypeName(1), + Computer::class => Computer::getTypeName(1), + Phone::class => Phone::getTypeName(1), ]); return true; } diff --git a/inc/ruleimportcollection.class.php b/inc/ruleimportcollection.class.php index 6ae8393..1b0ddbf 100644 --- a/inc/ruleimportcollection.class.php +++ b/inc/ruleimportcollection.class.php @@ -34,11 +34,11 @@ */ class PluginJamfRuleImportCollection extends RuleCollection { - public $stop_on_first_match = true; + public bool $stop_on_first_match = true; - public static $rightname = 'plugin_jamf_ruleimport'; + public static string $rightname = 'plugin_jamf_ruleimport'; - public $menu_option = 'jamf_import'; + public string $menu_option = 'jamf_import'; public function getTitle() { diff --git a/inc/software.class.php b/inc/software.class.php index bda1f7a..b918499 100644 --- a/inc/software.class.php +++ b/inc/software.class.php @@ -87,7 +87,7 @@ public static function getForGlpiItem(CommonDBTM $item): array ], ], 'WHERE' => [ - 'itemtype' => $item::getType(), + 'itemtype' => $item::class, 'items_id' => $item->getID(), ], ]); diff --git a/inc/sync.class.php b/inc/sync.class.php index 0de5237..d832031 100644 --- a/inc/sync.class.php +++ b/inc/sync.class.php @@ -163,11 +163,11 @@ protected function finalizeSync() 'id' => $this->item->getID(), ] + $this->item_changes); foreach ($this->extitem_changes as $key => $value) { - PluginJamfExtField::setValue($this->item::getType(), $this->item->getID(), $key, $value); + PluginJamfExtField::setValue($this->item::class, $this->item->getID(), $key, $value); } $this->db->updateOrInsert(static::$jamfplugin_itemtype::getTable(), $this->jamfplugin_item_changes, [ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID(), ]); @@ -178,7 +178,7 @@ protected function finalizeSync() $jamf_item = new static::$jamfplugin_itemtype(); $jamf_match = $jamf_item->find([ - 'itemtype' => $this->item::getType(), + 'itemtype' => $this->item::class, 'items_id' => $this->item->getID()], [], 1); if (count($jamf_match) > 0) { $jamf_item->getFromDB(reset($jamf_match)['id']); diff --git a/inc/toolbox.class.php b/inc/toolbox.class.php index feab646..e82f4e0 100644 --- a/inc/toolbox.class.php +++ b/inc/toolbox.class.php @@ -41,9 +41,7 @@ public static function getHumanReadableTimeDiff($start, $end = null) return null; } - if ($end === null) { - $end = $_SESSION['glpi_currenttime']; - } + $end ??= $_SESSION['glpi_currenttime']; $diff = date_diff(date_create($start), date_create($end)); $text_arr = []; @@ -92,9 +90,7 @@ public static function utcToLocal($utc, ?int $format = null): string $mask = 'Y-m-d H:i:s'; - if ($format === null) { - $format = $_SESSION['glpidate_format']; - } + $format ??= $_SESSION['glpidate_format']; switch ($format) { case 1: // DD-MM-YYYY diff --git a/inc/user_jssaccount.class.php b/inc/user_jssaccount.class.php index 9cb94ab..5248a35 100644 --- a/inc/user_jssaccount.class.php +++ b/inc/user_jssaccount.class.php @@ -40,11 +40,11 @@ */ class PluginJamfUser_JSSAccount extends CommonDBChild { - public static $itemtype = 'User'; + public static string $itemtype = 'User'; - public static $items_id = 'users_id'; + public static string $items_id = 'users_id'; - public static $rightname = 'plugin_jamf_jssaccount'; + public static string $rightname = 'plugin_jamf_jssaccount'; public const LINK = 256; @@ -85,9 +85,7 @@ public function getJSSPrivileges() // Cache JSS account privileges information to avoid extra, costly API calls. static $privileges = []; - if (!isset($privileges[$this->fields['jssaccounts_id']])) { - $privileges[$this->fields['jssaccounts_id']] = PluginJamfAPI::getJSSAccountRights($this->fields['jssaccounts_id']); - } + $privileges[$this->fields['jssaccounts_id']] ??= PluginJamfAPI::getJSSAccountRights($this->fields['jssaccounts_id']); return $privileges[$this->fields['jssaccounts_id']]; } @@ -95,23 +93,21 @@ public function getJSSPrivileges() private static function getItemRightMap() { static $map = null; - if ($map === null) { - $map = [ - 'accounts' => ['Accounts'], - 'advancedcomputersearches' => ['Advanced Computer Searches'], - 'advancedmobiledevicesearches' => ['Advanced Mobile Device Searches'], - 'advancedusersearches' => ['Advanced User Searches'], - 'buildings' => ['Buildings'], - 'categories' => ['Categories'], - 'classes' => ['Classes'], - 'departments' => ['Departments'], - 'mobiledeviceapplications' => ['Mobile Device Applications'], - 'mobiledeviceextensionattributes' => ['Mobile Device Extension Attributes'], - 'mobiledevicegroups' => ['Smart Mobile Device Groups', 'Static Mobile Device Groups'], - 'mobiledevices' => ['Mobile Devices'], - 'users' => ['Users'], - ]; - } + $map ??= [ + 'accounts' => ['Accounts'], + 'advancedcomputersearches' => ['Advanced Computer Searches'], + 'advancedmobiledevicesearches' => ['Advanced Mobile Device Searches'], + 'advancedusersearches' => ['Advanced User Searches'], + 'buildings' => ['Buildings'], + 'categories' => ['Categories'], + 'classes' => ['Classes'], + 'departments' => ['Departments'], + 'mobiledeviceapplications' => ['Mobile Device Applications'], + 'mobiledeviceextensionattributes' => ['Mobile Device Extension Attributes'], + 'mobiledevicegroups' => ['Smart Mobile Device Groups', 'Static Mobile Device Groups'], + 'mobiledevices' => ['Mobile Devices'], + 'users' => ['Users'], + ]; return $map; } @@ -205,11 +201,9 @@ public static function haveJSSRight($type, $jss_right) $user_jssaccount = new self(); static $matches = null; - if ($matches === null) { - $matches = $user_jssaccount->find([ - 'users_id' => Session::getLoginUserID(), - ]); - } + $matches ??= $user_jssaccount->find([ + 'users_id' => Session::getLoginUserID(), + ]); if (count($matches) === 0) { // No JSS account link diff --git a/setup.php b/setup.php index 3f2b90c..02c19f8 100644 --- a/setup.php +++ b/setup.php @@ -35,8 +35,8 @@ use function Safe\preg_replace; define('PLUGIN_JAMF_VERSION', '3.2.2'); -define('PLUGIN_JAMF_MIN_GLPI', '11.0.0'); -define('PLUGIN_JAMF_MAX_GLPI', '11.0.99'); +define('PLUGIN_JAMF_MIN_GLPI', '12.0.0'); +define('PLUGIN_JAMF_MAX_GLPI', '12.0.99'); function plugin_init_jamf() { diff --git a/templates/config.html.twig b/templates/config.html.twig index 5a94cbb..2600377 100644 --- a/templates/config.html.twig +++ b/templates/config.html.twig @@ -30,7 +30,6 @@ {% import 'components/form/fields_macros.html.twig' as fields %}
-
diff --git a/templates/import.html.twig b/templates/import.html.twig index 8b06298..07710b7 100644 --- a/templates/import.html.twig +++ b/templates/import.html.twig @@ -33,7 +33,6 @@ href: path('/plugins/jamf/front/import.php'), start: _get['start']|default(0), }) }} -
diff --git a/templates/merge.html.twig b/templates/merge.html.twig index ebc63db..49c0ee9 100644 --- a/templates/merge.html.twig +++ b/templates/merge.html.twig @@ -35,7 +35,6 @@ href: path('/plugins/jamf/front/merge.php'), start: _get['start']|default(0), }) }} -
diff --git a/templates/user_jssaccount.html.twig b/templates/user_jssaccount.html.twig index 046b17d..d4926d8 100644 --- a/templates/user_jssaccount.html.twig +++ b/templates/user_jssaccount.html.twig @@ -42,7 +42,6 @@ {% if can_edit %} - {% endif %} diff --git a/tests/units/PluginJamfMobileSync.php b/tests/units/PluginJamfMobileSync.php index 615e8df..a701d77 100644 --- a/tests/units/PluginJamfMobileSync.php +++ b/tests/units/PluginJamfMobileSync.php @@ -44,6 +44,7 @@ use PluginJamfMobileDevice; use PluginJamfSync; use ReflectionClass; +use PHPUnit\Framework\Attributes\DataProvider; class PluginJamfMobileSync extends AbstractDBTest { @@ -162,6 +163,7 @@ public function testImportAsPhone() // Make sure the new phone is linked properly $link_iterator = $DB->request([ + 'SELECT' => ['glpi_plugin_jamf_devices.jamf_items_id'], 'FROM' => 'glpi_plugin_jamf_devices', 'LEFT JOIN' => [ PluginJamfMobileDevice::getTable() => [ @@ -207,9 +209,7 @@ public static function deviceSyncEnginesProvider() return $result; } - /** - * @dataProvider deviceSyncEnginesProvider - */ + #[DataProvider('deviceSyncEnginesProvider')] public function testGetDeviceSyncEngineItem($device_class, $sync_class) { $rdc = new ReflectionClass($device_class);