From 9301de15ec55402ea8fc39d6033df92d41589afb Mon Sep 17 00:00:00 2001 From: RomainLvr Date: Sun, 29 Jun 2025 17:33:57 +0200 Subject: [PATCH 1/5] GLPI 11 compatibility --- .github/workflows/continuous-integration.yml | 2 +- ajax/container.php | 9 +- ajax/reorder.php | 4 +- ajax/viewtranslations.php | 2 - composer.json | 6 +- composer.lock | 483 +++++++----------- front/container.form.php | 4 +- front/export_to_yaml.php | 2 +- inc/abstractcontainerinstance.class.php | 14 +- inc/container.class.php | 21 +- inc/containerdisplaycondition.class.php | 8 +- inc/field.class.php | 30 +- inc/labeltranslation.class.php | 14 +- inc/profile.class.php | 7 +- inc/statusoverride.class.php | 7 +- inc/toolbox.class.php | 2 +- phpstan.neon | 3 +- setup.php | 9 +- templates/container.class.tpl | 4 +- .../container_display_conditions.html.twig | 4 +- templates/dropdown.class.tpl | 2 +- templates/fields.html.twig | 10 +- templates/forms/status_override.html.twig | 6 +- templates/status_overrides.html.twig | 6 +- 24 files changed, 301 insertions(+), 358 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 31e9e8e4..850f4482 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: "10.0.x" + glpi-version: "11.0.x" ci: name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}" needs: "generate-ci-matrix" diff --git a/ajax/container.php b/ajax/container.php index 5bdea933..ac8118ae 100644 --- a/ajax/container.php +++ b/ajax/container.php @@ -31,14 +31,13 @@ include('../../../inc/includes.php'); Session::checkLoginUser(); -use Glpi\Http\Response; +use Glpi\Exception\Http\HttpException; if (isset($_GET['action']) && $_GET['action'] === 'get_fields_html') { $right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $_GET['id']); if ($right < READ) { - Response::sendError(403, 'Forbidden'); - return; + throw new HttpException(403, 'Forbidden'); } $containers_id = $_GET['id']; @@ -50,7 +49,7 @@ $item = new $itemtype(); if ($items_id > 0 && !$item->getFromDB($items_id)) { - Response::sendError(404, 'Not Found'); + throw new HttpException(404, 'Not Found'); } $item->input = $input; @@ -66,5 +65,5 @@ echo ''; } } else { - Response::sendError(404, 'Not Found'); + throw new HttpException(404, 'Not Found'); } diff --git a/ajax/reorder.php b/ajax/reorder.php index 9ee4516d..14dee8e4 100644 --- a/ajax/reorder.php +++ b/ajax/reorder.php @@ -72,7 +72,7 @@ $DB->update( $table, [ - 'ranking' => new \QueryExpression($DB->quoteName('ranking') . ' - 1'), + 'ranking' => new \Glpi\DBAL\QueryExpression($DB->quoteName('ranking') . ' - 1'), ], [ 'plugin_fields_containers_id' => $container_id, @@ -84,7 +84,7 @@ $DB->update( $table, [ - 'ranking' => new \QueryExpression($DB->quoteName('ranking') . ' + 1'), + 'ranking' => new \Glpi\DBAL\QueryExpression($DB->quoteName('ranking') . ' + 1'), ], [ 'plugin_fields_containers_id' => $container_id, diff --git a/ajax/viewtranslations.php b/ajax/viewtranslations.php index df0dbc0e..e1ed855d 100644 --- a/ajax/viewtranslations.php +++ b/ajax/viewtranslations.php @@ -53,5 +53,3 @@ } else { echo __('Access denied'); } - -Html::ajaxFooter(); diff --git a/composer.json b/composer.json index ec5ce920..76e43622 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "require": { - "php": ">=7.4", - "symfony/yaml": "^5.4" + "php": ">=8.2", + "symfony/yaml": "^7.3" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.75", @@ -15,7 +15,7 @@ "config": { "optimize-autoloader": true, "platform": { - "php": "7.4.0" + "php": "8.2.99" }, "sort-packages": true, "allow-plugins": { diff --git a/composer.lock b/composer.lock index 61f1bad3..3564b0f9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,24 +4,24 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9d4758e6827d715fec0e58dbaa09e068", + "content-hash": "267d4da9f607fd1c32ef5a17f83890cb", "packages": [ { "name": "symfony/deprecation-contracts", - "version": "v2.5.4", + "version": "v3.6.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "605389f2a7e5625f273b53960dc46aeaf9c62918" + "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/605389f2a7e5625f273b53960dc46aeaf9c62918", - "reference": "605389f2a7e5625f273b53960dc46aeaf9c62918", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62", + "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=8.1" }, "type": "library", "extra": { @@ -30,7 +30,7 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "2.5-dev" + "dev-main": "3.6-dev" } }, "autoload": { @@ -55,7 +55,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.4" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.6.0" }, "funding": [ { @@ -71,7 +71,7 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2024-09-25T14:21:43+00:00" }, { "name": "symfony/polyfill-ctype", @@ -154,31 +154,28 @@ }, { "name": "symfony/yaml", - "version": "v5.4.45", + "version": "v7.3.1", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "a454d47278cc16a5db371fe73ae66a78a633371e" + "reference": "0c3555045a46ab3cd4cc5a69d161225195230edb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/a454d47278cc16a5db371fe73ae66a78a633371e", - "reference": "a454d47278cc16a5db371fe73ae66a78a633371e", + "url": "https://api.github.com/repos/symfony/yaml/zipball/0c3555045a46ab3cd4cc5a69d161225195230edb", + "reference": "0c3555045a46ab3cd4cc5a69d161225195230edb", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", + "php": ">=8.2", + "symfony/deprecation-contracts": "^2.5|^3.0", "symfony/polyfill-ctype": "^1.8" }, "conflict": { - "symfony/console": "<5.3" + "symfony/console": "<6.4" }, "require-dev": { - "symfony/console": "^5.3|^6.0" - }, - "suggest": { - "symfony/console": "For validating YAML files using the lint command" + "symfony/console": "^6.4|^7.0" }, "bin": [ "Resources/bin/yaml-lint" @@ -209,7 +206,7 @@ "description": "Loads and dumps YAML files", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/yaml/tree/v5.4.45" + "source": "https://github.com/symfony/yaml/tree/v7.3.1" }, "funding": [ { @@ -225,7 +222,7 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2025-06-03T06:57:57+00:00" } ], "packages-dev": [ @@ -733,16 +730,16 @@ }, { "name": "friendsoftwig/twigcs", - "version": "v6.1.0", + "version": "6.5.0", "source": { "type": "git", "url": "https://github.com/friendsoftwig/twigcs.git", - "reference": "3c36d606c4f19db0dd2a01b735ec7a8151b7f182" + "reference": "aaa3ba112bf4fcee7b51a00d9b45b13bc2cc23bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/friendsoftwig/twigcs/zipball/3c36d606c4f19db0dd2a01b735ec7a8151b7f182", - "reference": "3c36d606c4f19db0dd2a01b735ec7a8151b7f182", + "url": "https://api.github.com/repos/friendsoftwig/twigcs/zipball/aaa3ba112bf4fcee7b51a00d9b45b13bc2cc23bc", + "reference": "aaa3ba112bf4fcee7b51a00d9b45b13bc2cc23bc", "shasum": "" }, "require": { @@ -751,14 +748,14 @@ "ext-json": "*", "ext-mbstring": "*", "ext-simplexml": "*", - "php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0", - "symfony/console": "^4.4 || ^5.3 || ^6.0", - "symfony/filesystem": "^4.4 || ^5.3 || ^6.0", - "symfony/finder": "^4.4 || ^5.3 || ^6.0" + "php": "~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0", + "symfony/console": "^4.4 || ^5.3 || ^6.0 || ^7.0", + "symfony/filesystem": "^4.4 || ^5.3 || ^6.0 || ^7.0", + "symfony/finder": "^4.4 || ^5.3 || ^6.0 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "^9.5.20", - "symfony/phpunit-bridge": "^6.2.3" + "phpunit/phpunit": "^9.6.19", + "symfony/phpunit-bridge": "^7.1.4" }, "bin": [ "bin/twigcs" @@ -782,9 +779,9 @@ "description": "Checkstyle automation for Twig", "support": { "issues": "https://github.com/friendsoftwig/twigcs/issues", - "source": "https://github.com/friendsoftwig/twigcs/tree/v6.1.0" + "source": "https://github.com/friendsoftwig/twigcs/tree/6.5.0" }, - "time": "2023-01-04T16:01:24+00:00" + "time": "2024-11-27T21:59:24+00:00" }, { "name": "glpi-project/tools", @@ -1058,22 +1055,27 @@ }, { "name": "psr/container", - "version": "1.1.2", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/php-fig/container.git", - "reference": "513e0666f7216c7459170d56df27dfcefe1689ea" + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea", - "reference": "513e0666f7216c7459170d56df27dfcefe1689ea", + "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/" @@ -1100,9 +1102,9 @@ ], "support": { "issues": "https://github.com/php-fig/container/issues", - "source": "https://github.com/php-fig/container/tree/1.1.2" + "source": "https://github.com/php-fig/container/tree/2.0.2" }, - "time": "2021-11-05T16:50:12+00:00" + "time": "2021-11-05T16:47:00+00:00" }, { "name": "psr/event-dispatcher", @@ -1156,30 +1158,30 @@ }, { "name": "psr/log", - "version": "1.1.4", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "d49695b909c3b7628b6289db5479a1c204601f11" + "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", - "reference": "d49695b909c3b7628b6289db5479a1c204601f11", + "url": "https://api.github.com/repos/php-fig/log/zipball/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3", + "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": ">=8.0.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "3.x-dev" } }, "autoload": { "psr-4": { - "Psr\\Log\\": "Psr/Log/" + "Psr\\Log\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -1200,9 +1202,9 @@ "psr-3" ], "support": { - "source": "https://github.com/php-fig/log/tree/1.1.4" + "source": "https://github.com/php-fig/log/tree/3.0.2" }, - "time": "2021-05-03T11:20:27+00:00" + "time": "2024-09-11T13:17:53+00:00" }, { "name": "react/cache", @@ -1732,29 +1734,29 @@ }, { "name": "sebastian/diff", - "version": "4.0.6", + "version": "6.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc" + "reference": "b4ccd857127db5d41a5b676f24b51371d76d8544" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/ba01945089c3a293b01ba9badc29ad55b106b0bc", - "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/b4ccd857127db5d41a5b676f24b51371d76d8544", + "reference": "b4ccd857127db5d41a5b676f24b51371d76d8544", "shasum": "" }, "require": { - "php": ">=7.3" + "php": ">=8.2" }, "require-dev": { - "phpunit/phpunit": "^9.3", + "phpunit/phpunit": "^11.0", "symfony/process": "^4.2 || ^5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-main": "6.0-dev" } }, "autoload": { @@ -1786,7 +1788,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/4.0.6" + "security": "https://github.com/sebastianbergmann/diff/security/policy", + "source": "https://github.com/sebastianbergmann/diff/tree/6.0.2" }, "funding": [ { @@ -1794,56 +1797,51 @@ "type": "github" } ], - "time": "2024-03-02T06:30:58+00:00" + "time": "2024-07-03T04:53:05+00:00" }, { "name": "symfony/console", - "version": "v5.4.47", + "version": "v6.4.23", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed" + "reference": "9056771b8eca08d026cd3280deeec3cfd99c4d93" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed", - "reference": "c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed", + "url": "https://api.github.com/repos/symfony/console/zipball/9056771b8eca08d026cd3280deeec3cfd99c4d93", + "reference": "9056771b8eca08d026cd3280deeec3cfd99c4d93", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.5|^3", "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php73": "^1.9", - "symfony/polyfill-php80": "^1.16", - "symfony/service-contracts": "^1.1|^2|^3", - "symfony/string": "^5.1|^6.0" + "symfony/service-contracts": "^2.5|^3", + "symfony/string": "^5.4|^6.0|^7.0" }, "conflict": { - "psr/log": ">=3", - "symfony/dependency-injection": "<4.4", - "symfony/dotenv": "<5.1", - "symfony/event-dispatcher": "<4.4", - "symfony/lock": "<4.4", - "symfony/process": "<4.4" + "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" + "psr/log-implementation": "1.0|2.0|3.0" }, "require-dev": { - "psr/log": "^1|^2", - "symfony/config": "^4.4|^5.0|^6.0", - "symfony/dependency-injection": "^4.4|^5.0|^6.0", - "symfony/event-dispatcher": "^4.4|^5.0|^6.0", - "symfony/lock": "^4.4|^5.0|^6.0", - "symfony/process": "^4.4|^5.0|^6.0", - "symfony/var-dumper": "^4.4|^5.0|^6.0" - }, - "suggest": { - "psr/log": "For using the console logger", - "symfony/event-dispatcher": "", - "symfony/lock": "", - "symfony/process": "" + "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": { @@ -1877,7 +1875,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.47" + "source": "https://github.com/symfony/console/tree/v6.4.23" }, "funding": [ { @@ -1893,48 +1891,43 @@ "type": "tidelift" } ], - "time": "2024-11-06T11:30:55+00:00" + "time": "2025-06-27T19:37:22+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v5.4.45", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "72982eb416f61003e9bb6e91f8b3213600dcf9e9" + "reference": "497f73ac996a598c92409b44ac43b6690c4f666d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/72982eb416f61003e9bb6e91f8b3213600dcf9e9", - "reference": "72982eb416f61003e9bb6e91f8b3213600dcf9e9", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/497f73ac996a598c92409b44ac43b6690c4f666d", + "reference": "497f73ac996a598c92409b44ac43b6690c4f666d", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", - "symfony/event-dispatcher-contracts": "^2|^3", - "symfony/polyfill-php80": "^1.16" + "php": ">=8.2", + "symfony/event-dispatcher-contracts": "^2.5|^3" }, "conflict": { - "symfony/dependency-injection": "<4.4" + "symfony/dependency-injection": "<6.4", + "symfony/service-contracts": "<2.5" }, "provide": { "psr/event-dispatcher-implementation": "1.0", - "symfony/event-dispatcher-implementation": "2.0" + "symfony/event-dispatcher-implementation": "2.0|3.0" }, "require-dev": { "psr/log": "^1|^2|^3", - "symfony/config": "^4.4|^5.0|^6.0", - "symfony/dependency-injection": "^4.4|^5.0|^6.0", - "symfony/error-handler": "^4.4|^5.0|^6.0", - "symfony/expression-language": "^4.4|^5.0|^6.0", - "symfony/http-foundation": "^4.4|^5.0|^6.0", - "symfony/service-contracts": "^1.1|^2|^3", - "symfony/stopwatch": "^4.4|^5.0|^6.0" - }, - "suggest": { - "symfony/dependency-injection": "", - "symfony/http-kernel": "" + "symfony/config": "^6.4|^7.0", + "symfony/dependency-injection": "^6.4|^7.0", + "symfony/error-handler": "^6.4|^7.0", + "symfony/expression-language": "^6.4|^7.0", + "symfony/http-foundation": "^6.4|^7.0", + "symfony/service-contracts": "^2.5|^3", + "symfony/stopwatch": "^6.4|^7.0" }, "type": "library", "autoload": { @@ -1962,7 +1955,7 @@ "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/event-dispatcher/tree/v5.4.45" + "source": "https://github.com/symfony/event-dispatcher/tree/v7.3.0" }, "funding": [ { @@ -1978,29 +1971,26 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2025-04-22T09:11:45+00:00" }, { "name": "symfony/event-dispatcher-contracts", - "version": "v2.5.4", + "version": "v3.6.0", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher-contracts.git", - "reference": "e0fe3d79b516eb75126ac6fa4cbf19b79b08c99f" + "reference": "59eb412e93815df44f05f342958efa9f46b1e586" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/e0fe3d79b516eb75126ac6fa4cbf19b79b08c99f", - "reference": "e0fe3d79b516eb75126ac6fa4cbf19b79b08c99f", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/59eb412e93815df44f05f342958efa9f46b1e586", + "reference": "59eb412e93815df44f05f342958efa9f46b1e586", "shasum": "" }, "require": { - "php": ">=7.2.5", + "php": ">=8.1", "psr/event-dispatcher": "^1" }, - "suggest": { - "symfony/event-dispatcher-implementation": "" - }, "type": "library", "extra": { "thanks": { @@ -2008,7 +1998,7 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "2.5-dev" + "dev-main": "3.6-dev" } }, "autoload": { @@ -2041,7 +2031,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v2.5.4" + "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.6.0" }, "funding": [ { @@ -2057,30 +2047,29 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2024-09-25T14:21:43+00:00" }, { "name": "symfony/filesystem", - "version": "v5.4.45", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "57c8294ed37d4a055b77057827c67f9558c95c54" + "reference": "b8dce482de9d7c9fe2891155035a7248ab5c7fdb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/57c8294ed37d4a055b77057827c67f9558c95c54", - "reference": "57c8294ed37d4a055b77057827c67f9558c95c54", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/b8dce482de9d7c9fe2891155035a7248ab5c7fdb", + "reference": "b8dce482de9d7c9fe2891155035a7248ab5c7fdb", "shasum": "" }, "require": { - "php": ">=7.2.5", + "php": ">=8.2", "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-mbstring": "~1.8", - "symfony/polyfill-php80": "^1.16" + "symfony/polyfill-mbstring": "~1.8" }, "require-dev": { - "symfony/process": "^5.4|^6.4" + "symfony/process": "^6.4|^7.0" }, "type": "library", "autoload": { @@ -2108,7 +2097,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v5.4.45" + "source": "https://github.com/symfony/filesystem/tree/v7.3.0" }, "funding": [ { @@ -2124,26 +2113,27 @@ "type": "tidelift" } ], - "time": "2024-10-22T13:05:35+00:00" + "time": "2024-10-25T15:15:23+00:00" }, { "name": "symfony/finder", - "version": "v5.4.45", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "63741784cd7b9967975eec610b256eed3ede022b" + "reference": "ec2344cf77a48253bbca6939aa3d2477773ea63d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/63741784cd7b9967975eec610b256eed3ede022b", - "reference": "63741784cd7b9967975eec610b256eed3ede022b", + "url": "https://api.github.com/repos/symfony/finder/zipball/ec2344cf77a48253bbca6939aa3d2477773ea63d", + "reference": "ec2344cf77a48253bbca6939aa3d2477773ea63d", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", - "symfony/polyfill-php80": "^1.16" + "php": ">=8.2" + }, + "require-dev": { + "symfony/filesystem": "^6.4|^7.0" }, "type": "library", "autoload": { @@ -2171,7 +2161,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v5.4.45" + "source": "https://github.com/symfony/finder/tree/v7.3.0" }, "funding": [ { @@ -2187,27 +2177,25 @@ "type": "tidelift" } ], - "time": "2024-09-28T13:32:08+00:00" + "time": "2024-12-30T19:00:26+00:00" }, { "name": "symfony/options-resolver", - "version": "v5.4.45", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", - "reference": "74e5b6f0db3e8589e6cfd5efb317a1fc2bb52fb6" + "reference": "afb9a8038025e5dbc657378bfab9198d75f10fca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/74e5b6f0db3e8589e6cfd5efb317a1fc2bb52fb6", - "reference": "74e5b6f0db3e8589e6cfd5efb317a1fc2bb52fb6", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/afb9a8038025e5dbc657378bfab9198d75f10fca", + "reference": "afb9a8038025e5dbc657378bfab9198d75f10fca", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", - "symfony/polyfill-php73": "~1.0", - "symfony/polyfill-php80": "^1.16" + "php": ">=8.2", + "symfony/deprecation-contracts": "^2.5|^3" }, "type": "library", "autoload": { @@ -2240,7 +2228,7 @@ "options" ], "support": { - "source": "https://github.com/symfony/options-resolver/tree/v5.4.45" + "source": "https://github.com/symfony/options-resolver/tree/v7.3.0" }, "funding": [ { @@ -2256,7 +2244,7 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2025-04-04T13:12:05+00:00" }, { "name": "symfony/polyfill-intl-grapheme", @@ -2498,82 +2486,6 @@ ], "time": "2024-12-23T08:48:59+00:00" }, - { - "name": "symfony/polyfill-php73", - "version": "v1.32.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "0f68c03565dcaaf25a890667542e8bd75fe7e5bb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/0f68c03565dcaaf25a890667542e8bd75fe7e5bb", - "reference": "0f68c03565dcaaf25a890667542e8bd75fe7e5bb", - "shasum": "" - }, - "require": { - "php": ">=7.2" - }, - "type": "library", - "extra": { - "thanks": { - "url": "https://github.com/symfony/polyfill", - "name": "symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Php73\\": "" - }, - "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 backporting some PHP 7.3+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-php73/tree/v1.32.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-09T11:45:10+00:00" - }, { "name": "symfony/polyfill-php80", "version": "v1.32.0", @@ -2732,21 +2644,20 @@ }, { "name": "symfony/process", - "version": "v5.4.47", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "5d1662fb32ebc94f17ddb8d635454a776066733d" + "reference": "40c295f2deb408d5e9d2d32b8ba1dd61e36f05af" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/5d1662fb32ebc94f17ddb8d635454a776066733d", - "reference": "5d1662fb32ebc94f17ddb8d635454a776066733d", + "url": "https://api.github.com/repos/symfony/process/zipball/40c295f2deb408d5e9d2d32b8ba1dd61e36f05af", + "reference": "40c295f2deb408d5e9d2d32b8ba1dd61e36f05af", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/polyfill-php80": "^1.16" + "php": ">=8.2" }, "type": "library", "autoload": { @@ -2774,7 +2685,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v5.4.47" + "source": "https://github.com/symfony/process/tree/v7.3.0" }, "funding": [ { @@ -2790,33 +2701,30 @@ "type": "tidelift" } ], - "time": "2024-11-06T11:36:42+00:00" + "time": "2025-04-17T09:11:12+00:00" }, { "name": "symfony/service-contracts", - "version": "v2.5.4", + "version": "v3.6.0", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "f37b419f7aea2e9abf10abd261832cace12e3300" + "reference": "f021b05a130d35510bd6b25fe9053c2a8a15d5d4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/f37b419f7aea2e9abf10abd261832cace12e3300", - "reference": "f37b419f7aea2e9abf10abd261832cace12e3300", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/f021b05a130d35510bd6b25fe9053c2a8a15d5d4", + "reference": "f021b05a130d35510bd6b25fe9053c2a8a15d5d4", "shasum": "" }, "require": { - "php": ">=7.2.5", - "psr/container": "^1.1", - "symfony/deprecation-contracts": "^2.1|^3" + "php": ">=8.1", + "psr/container": "^1.1|^2.0", + "symfony/deprecation-contracts": "^2.5|^3" }, "conflict": { "ext-psr": "<1.1|>=2" }, - "suggest": { - "symfony/service-implementation": "" - }, "type": "library", "extra": { "thanks": { @@ -2824,13 +2732,16 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "2.5-dev" + "dev-main": "3.6-dev" } }, "autoload": { "psr-4": { "Symfony\\Contracts\\Service\\": "" - } + }, + "exclude-from-classmap": [ + "/Test/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -2857,7 +2768,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v2.5.4" + "source": "https://github.com/symfony/service-contracts/tree/v3.6.0" }, "funding": [ { @@ -2873,25 +2784,25 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2025-04-25T09:37:31+00:00" }, { "name": "symfony/stopwatch", - "version": "v5.4.45", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "fb2c199cf302eb207f8c23e7ee174c1c31a5c004" + "reference": "5a49289e2b308214c8b9c2fda4ea454d8b8ad7cd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/fb2c199cf302eb207f8c23e7ee174c1c31a5c004", - "reference": "fb2c199cf302eb207f8c23e7ee174c1c31a5c004", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/5a49289e2b308214c8b9c2fda4ea454d8b8ad7cd", + "reference": "5a49289e2b308214c8b9c2fda4ea454d8b8ad7cd", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/service-contracts": "^1|^2|^3" + "php": ">=8.2", + "symfony/service-contracts": "^2.5|^3" }, "type": "library", "autoload": { @@ -2919,7 +2830,7 @@ "description": "Provides a way to profile code", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/stopwatch/tree/v5.4.45" + "source": "https://github.com/symfony/stopwatch/tree/v7.3.0" }, "funding": [ { @@ -2935,38 +2846,39 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2025-02-24T10:49:57+00:00" }, { "name": "symfony/string", - "version": "v5.4.47", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "136ca7d72f72b599f2631aca474a4f8e26719799" + "reference": "f3570b8c61ca887a9e2938e85cb6458515d2b125" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/136ca7d72f72b599f2631aca474a4f8e26719799", - "reference": "136ca7d72f72b599f2631aca474a4f8e26719799", + "url": "https://api.github.com/repos/symfony/string/zipball/f3570b8c61ca887a9e2938e85cb6458515d2b125", + "reference": "f3570b8c61ca887a9e2938e85cb6458515d2b125", "shasum": "" }, "require": { - "php": ">=7.2.5", + "php": ">=8.2", "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-intl-grapheme": "~1.0", "symfony/polyfill-intl-normalizer": "~1.0", - "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php80": "~1.15" + "symfony/polyfill-mbstring": "~1.0" }, "conflict": { - "symfony/translation-contracts": ">=3.0" + "symfony/translation-contracts": "<2.5" }, "require-dev": { - "symfony/error-handler": "^4.4|^5.0|^6.0", - "symfony/http-client": "^4.4|^5.0|^6.0", - "symfony/translation-contracts": "^1.1|^2", - "symfony/var-exporter": "^4.4|^5.0|^6.0" + "symfony/emoji": "^7.1", + "symfony/error-handler": "^6.4|^7.0", + "symfony/http-client": "^6.4|^7.0", + "symfony/intl": "^6.4|^7.0", + "symfony/translation-contracts": "^2.5|^3.0", + "symfony/var-exporter": "^6.4|^7.0" }, "type": "library", "autoload": { @@ -3005,7 +2917,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.4.47" + "source": "https://github.com/symfony/string/tree/v7.3.0" }, "funding": [ { @@ -3021,31 +2933,30 @@ "type": "tidelift" } ], - "time": "2024-11-10T20:33:58+00:00" + "time": "2025-04-20T20:19:01+00:00" }, { "name": "twig/twig", - "version": "v3.11.3", + "version": "v3.21.1", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "3b06600ff3abefaf8ff55d5c336cd1c4253f8c7e" + "reference": "285123877d4dd97dd7c11842ac5fb7e86e60d81d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/3b06600ff3abefaf8ff55d5c336cd1c4253f8c7e", - "reference": "3b06600ff3abefaf8ff55d5c336cd1c4253f8c7e", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/285123877d4dd97dd7c11842ac5fb7e86e60d81d", + "reference": "285123877d4dd97dd7c11842ac5fb7e86e60d81d", "shasum": "" }, "require": { - "php": ">=7.2.5", + "php": ">=8.1.0", "symfony/deprecation-contracts": "^2.5|^3", "symfony/polyfill-ctype": "^1.8", - "symfony/polyfill-mbstring": "^1.3", - "symfony/polyfill-php80": "^1.22", - "symfony/polyfill-php81": "^1.29" + "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" }, @@ -3089,7 +3000,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.11.3" + "source": "https://github.com/twigphp/Twig/tree/v3.21.1" }, "funding": [ { @@ -3101,7 +3012,7 @@ "type": "tidelift" } ], - "time": "2024-11-07T12:34:41+00:00" + "time": "2025-05-03T07:21:55+00:00" } ], "aliases": [], @@ -3110,11 +3021,11 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.4" + "php": ">=8.2" }, "platform-dev": [], "platform-overrides": { - "php": "7.4.0" + "php": "8.2.99" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/front/container.form.php b/front/container.form.php index 8a80410a..e1bb4f82 100644 --- a/front/container.form.php +++ b/front/container.form.php @@ -28,6 +28,8 @@ * ------------------------------------------------------------------------- */ +use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; + include('../../../inc/includes.php'); Session::checkLoginUser(); @@ -64,7 +66,7 @@ if ((int) $_GET['id'] > 0) { $right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $_GET['id']); if ($right < READ) { - Html::displayRightError("User is missing the " . READ . " ('read') right for container"); + throw new AccessDeniedHttpException(); } } diff --git a/front/export_to_yaml.php b/front/export_to_yaml.php index 16e8afb7..cfd132d4 100644 --- a/front/export_to_yaml.php +++ b/front/export_to_yaml.php @@ -41,7 +41,7 @@ if (plugin_fields_exportBlockAsYaml($ID)) { $filename = 'fields_conf.yaml'; $path = GLPI_TMP_DIR . '/fields_conf.yaml'; - Toolbox::sendFile($path, $filename, 'text/yaml'); + Toolbox::getFileAsResponse($path, $filename, 'text/yaml')->send(); } else { Session::addMessageAfterRedirect('No data to export', false, INFO); Html::back(); diff --git a/inc/abstractcontainerinstance.class.php b/inc/abstractcontainerinstance.class.php index 87ebcbd5..be26cc0b 100644 --- a/inc/abstractcontainerinstance.class.php +++ b/inc/abstractcontainerinstance.class.php @@ -62,16 +62,12 @@ public function addNeededInfoToInput($input) $completeinput, ) ) { - if ( - ($itemToGetEntity instanceof CommonDBTM) - ) { - if ($itemToGetEntity->isEntityAssign()) { - $input['entities_id'] = $itemToGetEntity->getEntityID(); - } + if ($itemToGetEntity->isEntityAssign()) { + $input['entities_id'] = $itemToGetEntity->getEntityID(); + } - if ($itemToGetEntity->maybeRecursive()) { - $input['is_recursive'] = intval($itemToGetEntity->isRecursive()); - } + if ($itemToGetEntity->maybeRecursive()) { + $input['is_recursive'] = intval($itemToGetEntity->isRecursive()); } } } diff --git a/inc/container.class.php b/inc/container.class.php index d8cc983f..901c4cc3 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -36,12 +36,12 @@ class PluginFieldsContainer extends CommonDBTM public static $rightname = 'config'; - public static function canCreate() + public static function canCreate(): bool { return self::canUpdate(); } - public static function canPurge() + public static function canPurge(): bool { return self::canUpdate(); } @@ -104,10 +104,10 @@ public static function installBaseData(Migration $migration, $version) $migration->changeField($table, 'itemtype', 'itemtypes', 'longtext'); $migration->migrationOneTable($table); - $DB->updateOrDie( + $DB->update( $table, [ - 'itemtypes' => new QueryExpression( + 'itemtypes' => new \Glpi\DBAL\QueryExpression( sprintf( 'CONCAT(%s, %s, %s)', $DB->quoteValue('[\"'), @@ -620,7 +620,7 @@ public function prepareInputForAdd($input) } } - $input['itemtypes'] = Sanitizer::dbEscape(json_encode($input['itemtypes'])); + $input['itemtypes'] = json_encode($input['itemtypes']); return $input; } @@ -783,10 +783,13 @@ public static function getTypeName($nb = 0) public function showForm($ID, $options = []) { + /** @var array $CFG_GLPI */ + global $CFG_GLPI; + $this->initForm($ID, $options); if (!$this->isNewID($ID)) { - $btn_url = Plugin::getWebDir('fields') . '/front/export_to_yaml.php?id=' . $ID; + $btn_url = $CFG_GLPI['root_doc'] . '/plugins/fields/front/export_to_yaml.php?id=' . $ID; $btn_label = __('Export to YAML', 'fields'); $export_btn = <<find(['type' => 'tab', 'name' => Sanitizer::sanitize($tabnum), 'is_active' => 1]); + $found_c = $container->find(['type' => 'tab', 'name' => $tabnum, 'is_active' => 1]); foreach ($found_c as $data) { $dataitemtypes = json_decode($data['itemtypes']); if (in_array(get_class($item), $dataitemtypes) != false) { @@ -1886,7 +1889,7 @@ public static function getAddSearchOptions($itemtype, $containers_id = false) 'glpi_plugin_fields_containers.label AS container_label', ( Session::isCron() - ? new QueryExpression(sprintf('%s AS %s', READ + CREATE, $DB->quoteName('right'))) + ? new \Glpi\DBAL\QueryExpression(sprintf('%s AS %s', READ + CREATE, $DB->quoteName('right'))) : 'glpi_plugin_fields_profiles.right' ), ], @@ -2132,7 +2135,7 @@ public function prepareInputForClone($input) if (array_key_exists('itemtypes', $input) && !empty($input['itemtypes'])) { // $input has been transformed with `Toolbox::addslashes_deep()`, and `self::prepareInputForAdd()` // is expecting an array, so it have to be unslashed then json decoded. - $input['itemtypes'] = json_decode(Sanitizer::dbUnescape($input['itemtypes'])); + $input['itemtypes'] = json_decode($input['itemtypes']); } else { unset($input['itemtypes']); } diff --git a/inc/containerdisplaycondition.class.php b/inc/containerdisplaycondition.class.php index bd108987..a1bb6c1d 100644 --- a/inc/containerdisplaycondition.class.php +++ b/inc/containerdisplaycondition.class.php @@ -163,6 +163,8 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) return self::createTabEntry( self::getTypeName(Session::getPluralNumber()), countElementsInTable(self::getTable(), ['plugin_fields_containers_id' => $item->getID()]), + null, + 'ti ti-eye-off', ); } @@ -232,6 +234,9 @@ public static function getFieldName($so_id, $itemtype) public static function showItemtypeFieldForm($itemtype) { + /** @var array $CFG_GLPI */ + global $CFG_GLPI; + $rand = mt_rand(); $out = ''; $out .= Dropdown::showFromArray('search_option', self::removeBlackListedOption(Search::getOptions($itemtype), $itemtype), ['display_emptychoice' => true, 'display' => false, 'rand' => $rand]); @@ -239,7 +244,7 @@ public static function showItemtypeFieldForm($itemtype) $out .= Ajax::updateItemOnSelectEvent( 'dropdown_search_option' . $rand, 'results_condition', - Plugin::getWebDir('fields') . '/ajax/container_display_condition.php', + $CFG_GLPI['root_doc'] . '/plugins/fields/ajax/container_display_condition.php', [ 'search_option_id' => '__VALUE__', 'itemtype' => $itemtype, @@ -457,7 +462,6 @@ public function checkCondition($item) case self::SHOW_CONDITION_REGEX: //'regex'; if (self::checkRegex($value)) { - $value = Sanitizer::unsanitize($value); if (preg_match_all($value . 'i', $fields[$searchOption['linkfield']]) > 0) { return false; } diff --git a/inc/field.class.php b/inc/field.class.php index 4f3a4d92..47ac0798 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -98,18 +98,18 @@ public static function installBaseData(Migration $migration, $version) $migration->displayMessage("Updating $table"); if (!$DB->fieldExists($table, 'is_active')) { - $migration->addField($table, 'is_active', 'bool', ['value' => 1]); + $migration->addField($table, 'is_active', 'bool', ['value' => '1']); $migration->addKey($table, 'is_active', 'is_active'); } if (!$DB->fieldExists($table, 'is_readonly')) { - $migration->addField($table, 'is_readonly', 'bool', ['default' => false]); + $migration->addField($table, 'is_readonly', 'bool', ['default' => 'false']); $migration->addKey($table, 'is_readonly', 'is_readonly'); } if (!$DB->fieldExists($table, 'mandatory')) { - $migration->addField($table, 'mandatory', 'bool', ['value' => 0]); + $migration->addField($table, 'mandatory', 'bool', ['value' => '0']); } if (!$DB->fieldExists($table, 'multiple')) { - $migration->addField($table, 'multiple', 'bool', ['value' => 0]); + $migration->addField($table, 'multiple', 'bool', ['value' => '0']); } //increase the size of column 'type' (25 to 255) @@ -313,7 +313,7 @@ public function prepareInputForAdd($input) } if (isset($input['allowed_values'])) { - $input['allowed_values'] = Sanitizer::dbEscape(json_encode($input['allowed_values'])); + $input['allowed_values'] = json_encode($input['allowed_values']); } return $input; @@ -431,7 +431,7 @@ public function post_purgeItem() $DB->update( $table, [ - 'ranking' => new QueryExpression($DB->quoteName('ranking') . ' - 1'), + 'ranking' => new \Glpi\DBAL\QueryExpression($DB->quoteName('ranking') . ' - 1'), ], [ 'plugin_fields_containers_id' => $old_container, @@ -510,7 +510,7 @@ public function getNextRanking() global $DB; $iterator = $DB->request([ - 'SELECT' => new \QueryExpression( + 'SELECT' => new \Glpi\DBAL\QueryExpression( 'max(' . $DB->quoteName('ranking') . ') AS ' . $DB->quoteName('rank'), ), 'FROM' => self::getTable(), @@ -547,6 +547,8 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) self::getTable(), ['plugin_fields_containers_id' => $item->getID()], ), + null, + 'ti ti-forms', ); } @@ -636,7 +638,7 @@ public function showSummary($container) echo ''; $label = !empty($this->fields['label']) ? $this->fields['label'] : NOT_AVAILABLE; - echo "getID()}'>{$label}"; + echo "getID()}'>{$label}"; echo ''; echo '' . $fields_type[$this->fields['type']] . ''; echo '' ; @@ -815,6 +817,9 @@ public function showForm($ID, $options = []) public static function showForTabContainer($c_id, $item) { + /** @var array $CFG_GLPI */ + global $CFG_GLPI; + //profile restriction $right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $c_id); if ($right < READ) { @@ -825,7 +830,7 @@ public static function showForTabContainer($c_id, $item) //get fields for this container $field_obj = new self(); $fields = $field_obj->find(['plugin_fields_containers_id' => $c_id, 'is_active' => 1], 'ranking'); - echo "
"; + echo ""; echo Html::hidden('plugin_fields_containers_id', ['value' => $c_id]); echo Html::hidden('items_id', ['value' => $item->getID()]); echo Html::hidden('itemtype', ['value' => $item->getType()]); @@ -885,6 +890,9 @@ public static function showDomContainer($id, $item, $type = 'dom', $subtype = '' */ public static function showForTab($params) { + /** @var array $CFG_GLPI */ + global $CFG_GLPI; + $item = $params['item']; $functions = array_column(debug_backtrace(), 'function'); @@ -982,7 +990,7 @@ public static function showForTab($params) echo ''; //JS to trigger any change and check if container need to be display or not - $ajax_url = Plugin::getWebDir('fields') . '/ajax/container.php'; + $ajax_url = $CFG_GLPI['root_doc'] . '/plugins/fields/ajax/container.php'; $items_id = !$item->isNewItem() ? $item->getID() : 0; echo Html::scriptBlock( <<can($item->getID(), UPDATE); $rand = mt_rand(); if ($canedit) { @@ -167,7 +175,7 @@ public static function showTranslations(CommonDBTM $item) echo Html::scriptBlock(' addTranslation' . $item->getID() . $rand . ' = function() { $("#viewtranslation' . $item->getID() . $rand . '").load( - "' . Plugin::getWebDir('fields') . '/ajax/viewtranslations.php", + "' . $CFG_GLPI['root_doc'] . '/plugins/fields/ajax/viewtranslations.php", ' . json_encode($ajax_params) . ' ); }; @@ -222,7 +230,7 @@ public static function showTranslations(CommonDBTM $item) echo Html::scriptBlock(' viewEditTranslation' . $data['id'] . $rand . ' = function() { $("#viewtranslation' . $item->getID() . $rand . '").load( - "' . Plugin::getWebDir('fields') . '/ajax/viewtranslations.php", + "' . $CFG_GLPI['root_doc'] . '/plugins/fields/ajax/viewtranslations.php", ' . json_encode($ajax_params) . ' ); }; diff --git a/inc/profile.class.php b/inc/profile.class.php index d6c72c3a..29b1faf1 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -86,7 +86,12 @@ public static function uninstall() public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - return self::createTabEntry(_n('Profile', 'Profiles', 2)); + return self::createTabEntry( + _n('Profile', 'Profiles', 2), + 0, + null, + 'ti ti-user-check', + ); } public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) diff --git a/inc/statusoverride.class.php b/inc/statusoverride.class.php index 73e52581..cd745bcd 100644 --- a/inc/statusoverride.class.php +++ b/inc/statusoverride.class.php @@ -93,7 +93,12 @@ public static function getTypeName($nb = 0) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if ($item instanceof CommonDBTM) { - return self::createTabEntry(self::getTypeName(), self::countOverridesForContainer($item->getID())); + return self::createTabEntry( + self::getTypeName(), + self::countOverridesForContainer($item->getID()), + null, + 'ti ti-adjustments-alt', + ); } return ''; } diff --git a/inc/toolbox.class.php b/inc/toolbox.class.php index 91c412d0..5e26de19 100644 --- a/inc/toolbox.class.php +++ b/inc/toolbox.class.php @@ -308,7 +308,7 @@ public static function getGlpiItemtypes(): array NetworkPort::class, Notification::class, NotificationTemplate::class, - ComputerVirtualMachine::class, + ItemVirtualMachine::class, ]; $all_itemtypes = [ diff --git a/phpstan.neon b/phpstan.neon index 455f2e74..9ec5db83 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,7 +3,8 @@ parameters: maximumNumberOfProcesses: 2 level: 5 bootstrapFiles: - - ../../inc/based_config.php + - ../../stubs/glpi_constants.php + - ../../vendor/autoload.php paths: - inc - front diff --git a/setup.php b/setup.php index 2f9ea1f4..c2796588 100644 --- a/setup.php +++ b/setup.php @@ -28,18 +28,21 @@ * ------------------------------------------------------------------------- */ +/** @var array $CFG_GLPI */ +global $CFG_GLPI; + define('PLUGIN_FIELDS_VERSION', '1.21.22'); // Minimal GLPI version, inclusive -define('PLUGIN_FIELDS_MIN_GLPI', '10.0.11'); +define('PLUGIN_FIELDS_MIN_GLPI', '11.0.0'); // Maximum GLPI version, exclusive -define('PLUGIN_FIELDS_MAX_GLPI', '10.0.99'); +define('PLUGIN_FIELDS_MAX_GLPI', '11.0.99'); if (!defined('PLUGINFIELDS_DIR')) { define('PLUGINFIELDS_DIR', Plugin::getPhpDir('fields')); } if (!defined('PLUGINFIELDS_WEB_DIR')) { - define('PLUGINFIELDS_WEB_DIR', Plugin::getWebDir('fields')); + define('PLUGINFIELDS_WEB_DIR', $CFG_GLPI['root_doc'] . '/plugins/fields'); } if (!defined('PLUGINFIELDS_DOC_DIR')) { diff --git a/templates/container.class.tpl b/templates/container.class.tpl index 58bd527f..509d5a74 100644 --- a/templates/container.class.tpl +++ b/templates/container.class.tpl @@ -26,11 +26,11 @@ class %%CLASSNAME%% extends PluginFieldsAbstractContainerInstance UNIQUE INDEX `itemtype_item_container` (`itemtype`, `items_id`, `plugin_fields_containers_id`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; - $DB->query($query) or die ($DB->error()); + $DB->doQuery($query); } else { // 1.15.4 // fix nullable state for 'glpi_item' field - $result = $DB->query("SHOW COLUMNS FROM `$table`"); + $result = $DB->doQuery("SHOW COLUMNS FROM `$table`"); if ($result && $DB->numrows($result) > 0) { $changed = false; while ($data = $DB->fetchAssoc($result)) { diff --git a/templates/container_display_conditions.html.twig b/templates/container_display_conditions.html.twig index 6e95ca43..bcd543ce 100644 --- a/templates/container_display_conditions.html.twig +++ b/templates/container_display_conditions.html.twig @@ -114,7 +114,7 @@ glpi_ajax_dialog( { title: __('Edit condition to hide block', 'fields'), - url: CFG_GLPI.root_doc + '/' + GLPI_PLUGINS_PATH.fields + '/ajax/container_display_condition.php', + url: CFG_GLPI.root_doc + '/plugins/fields/ajax/container_display_condition.php', method: 'get', params: { action: 'get_edit_form', @@ -133,7 +133,7 @@ glpi_ajax_dialog( { title: __('Add condition to hide block', 'fields'), - url: CFG_GLPI.root_doc + '/' + GLPI_PLUGINS_PATH.fields + '/ajax/container_display_condition.php', + url: CFG_GLPI.root_doc + '/plugins/fields/ajax/container_display_condition.php', method: 'get', params: { action: 'get_add_form', diff --git a/templates/dropdown.class.tpl b/templates/dropdown.class.tpl index 77929514..0d41c214 100644 --- a/templates/dropdown.class.tpl +++ b/templates/dropdown.class.tpl @@ -42,7 +42,7 @@ class %%CLASSNAME%% extends CommonTreeDropdown { KEY `plugin_fields_%%FIELDNAME%%dropdowns_id` (`plugin_fields_%%FIELDNAME%%dropdowns_id`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; - $DB->query($query) or die ($DB->error()); + $DB->doQuery($query); } } diff --git a/templates/fields.html.twig b/templates/fields.html.twig index b1a770f7..ca27f1bd 100644 --- a/templates/fields.html.twig +++ b/templates/fields.html.twig @@ -43,7 +43,7 @@ {% set type = field['type'] %} {% set name = field['name'] %} {% set label = field['label'] %} - {% set value = item.input[name] ?: field['value'] %} + {% set value = item.input[name]|default(field['value']) %} {% set readonly = field['is_readonly'] %} {% set rand = random() %} @@ -138,7 +138,7 @@
{% endif %} - {{ macros.dropdownArrayField(itemtype_prefix ~ name, value.itemtype, field['allowed_values'], label, field_options|merge({ + {{ macros.dropdownArrayField(itemtype_prefix ~ name, value.itemtype|default(''), field['allowed_values'], label, field_options|merge({ 'rand': rand, 'display_emptychoice': true, })) }} @@ -166,9 +166,9 @@
- {% if value.itemtype != '' %} - {{ macros.dropdownField(value.itemtype, items_id_prefix ~ name, value.items_id, ' ', field_options|merge({ - 'entity': value.itemtype == 'User' ? -1 : item.getEntityID(), + {% if value.itemtype|default('') != '' %} + {{ macros.dropdownField(value.itemtype, items_id_prefix ~ name, value.items_id|default(''), ' ', field_options|merge({ + 'entity': value.itemtype|default('') == 'User' ? -1 : item.getEntityID(), 'rand': rand, 'right': 'all', 'displaywith': ['otherserial', 'serial'], diff --git a/templates/forms/status_override.html.twig b/templates/forms/status_override.html.twig index 85b344d6..9c52a5a8 100644 --- a/templates/forms/status_override.html.twig +++ b/templates/forms/status_override.html.twig @@ -39,7 +39,7 @@ {% set itemtype = override.fields['itemtype']|default(container_itemtypes|keys|first) %} {{ fields.dropdownArrayField('itemtype', itemtype, container_itemtypes, __('Item type')) }} - {{ fields.dropdownArrayField('plugin_fields_fields_id', override.fields['plugin_fields_fields_id'], container_fields, __('Field', 'fields')) }} + {{ fields.dropdownArrayField('plugin_fields_fields_id', override.fields['plugin_fields_fields_id']|default(null), container_fields, __('Field', 'fields')) }} {% set status_field_html %}
@@ -58,7 +58,7 @@ {{ _x('button', 'Add') }} {% else %} - +