diff --git a/.github/actions/init_containers-start.sh b/.github/actions/init_containers-start.sh deleted file mode 100755 index 41d9b0f..0000000 --- a/.github/actions/init_containers-start.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set -e -u -x -o pipefail - -docker-compose pull --quiet -docker-compose up --no-start -docker-compose start \ No newline at end of file diff --git a/.github/actions/install.sh b/.github/actions/install.sh deleted file mode 100755 index f297ed2..0000000 --- a/.github/actions/install.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -# install glpi database -docker exec --user www-data glpi /bin/bash -c "cd /var/www/glpi && php bin/console db:install -H db -u glpi -p glpi -d glpi -n -r" - -# install our plugin -docker exec --user www-data glpi /bin/bash -c "cd /var/www/glpi && php bin/console plugin:install -u glpi centreon" -docker exec --user www-data glpi /bin/bash -c "cd /var/www/glpi && php bin/console plugin:activate centreon" \ No newline at end of file diff --git a/.github/actions/lint.sh b/.github/actions/lint.sh deleted file mode 100755 index cbe18b7..0000000 --- a/.github/actions/lint.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e -u -x -o pipefail - -docker exec --user www-data glpi /bin/bash -c "(cd /var/www/glpi/plugins/centreon && ./vendor/bin/parallel-lint --colors --exclude ./vendor/ .)" -docker exec --user www-data glpi /bin/bash -c "(cd /var/www/glpi/plugins/centreon && ./vendor/bin/phpcs)" \ No newline at end of file diff --git a/.github/actions/teardown_containers-cleanup.sh b/.github/actions/teardown_containers-cleanup.sh deleted file mode 100755 index 1a62d5e..0000000 --- a/.github/actions/teardown_containers-cleanup.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -docker-compose down --volumes \ No newline at end of file diff --git a/.github/actions/tests.sh b/.github/actions/tests.sh deleted file mode 100755 index cd39ae6..0000000 --- a/.github/actions/tests.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -docker exec --user www-data glpi /bin/bash -c "/var/www/glpi/plugins/centreon/vendor/bin/phpunit --debug --do-not-cache-result --bootstrap /var/www/glpi/plugins/centreon/tests/bootstrap.php /var/www/glpi/plugins/centreon/tests " \ No newline at end of file diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 3fc90f7..b597d4c 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -8,93 +8,25 @@ on: tags: - "*" pull_request: + schedule: + - cron: "0 0 * * *" workflow_dispatch: jobs: - lint: - name: "Lint" - runs-on: "ubuntu-latest" + ci: + name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}" strategy: fail-fast: false matrix: include: - - {php-version: "7.4"} - steps: - - name: "Checkout" - uses: "actions/checkout@v3" - - - name: "Setup PHP" - uses: "shivammathur/setup-php@v2" - with: - php-version: "${{ matrix.php-version }}" - coverage: "none" - tools: "composer, cs2pr" - - name: "Get Composer cache directory" - id: "composer-cache" - run: | - echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: "Restore dependencies cache" - uses: "actions/cache@v3" - with: - path: "${{ steps.composer-cache.outputs.dir }}" - key: "${{ github.job }}-${{ matrix.php-version }}-dependencies-${{ hashFiles('**/composer.lock') }}" - - - name: "Install Composer dependencies" - run: | - composer install --ansi --no-interaction --no-progress --prefer-dist - - - name: "PHP Parallel Lint" - run: | - vendor/bin/parallel-lint --colors --checkstyle --exclude ./vendor/ . | cs2pr - - - name: "PHP_CodeSniffer" - run: | - vendor/bin/phpcs -q --report=checkstyle | cs2pr - - - name: "Check for missing/outdated headers" - run: | - vendor/bin/licence-headers-check --ansi --no-interaction - - unit-tests: - name: "unit-tests" - runs-on: "ubuntu-latest" - strategy: - fail-fast: false - matrix: - include: - - {php-version: "7.4"} - steps: - - name: "Clean workspace" - run: | - echo "APP_CONTAINER_HOME=${{ runner.temp }}/app_home" >> $GITHUB_ENV - rm -rf "${{ env.APPLICATION_ROOT }}/*" - - - name: "Checkout" - uses: "actions/checkout@v3" - - - name: "Initialize containers" - run: | - .github/actions/init_containers-start.sh - - - name: Cache Composer dependencies - uses: actions/cache@v3 - with: - path: /tmp/composer-cache - key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} - - - name: "Install dependencies" - uses: "ramsey/composer-install@v2" - - - name: "Install GLPI & plugin" - run: | - .github/actions/install.sh - - - name: "Run PHPUnit" - run: | - .github/actions/tests.sh - - - name: "Cleanup containers" - if: always() - run: | - ${{ github.workspace }}/.github/actions/teardown_containers-cleanup.sh + - {glpi-version: "10.0.x", php-version: "7.4", db-image: "mysql:5.7"} + - {glpi-version: "10.0.x", php-version: "8.0", db-image: "mysql:8.0"} + - {glpi-version: "10.0.x", php-version: "8.1", db-image: "mariadb:10.2"} + - {glpi-version: "10.0.x", php-version: "8.2", db-image: "mariadb:11.0"} + - {glpi-version: "10.0.x", php-version: "8.3-rc", db-image: "mysql:8.0"} + uses: "glpi-project/plugin-ci-workflows/.github/workflows/continuous-integration.yml@v1" + with: + plugin-key: "centreon" + glpi-version: "${{ matrix.glpi-version }}" + php-version: "${{ matrix.php-version }}" + db-image: "${{ matrix.db-image }}" diff --git a/ajax/setDowntime.php b/ajax/setDowntime.php index 9d676c2..7b50dc6 100644 --- a/ajax/setDowntime.php +++ b/ajax/setDowntime.php @@ -34,7 +34,7 @@ header("Content-Type: text/html; charset=UTF-8"); -if (isset($_POST)) { +if (isset($_POST['params'])) { $params = $_POST['params']; $hostid = (int) $_POST['hostid']; $host = new Host(); diff --git a/composer.json b/composer.json index be7c460..773cc3d 100644 --- a/composer.json +++ b/composer.json @@ -4,8 +4,9 @@ "guzzlehttp/guzzle": "^7.0" }, "require-dev": { - "glpi-project/tools": "^0.4", + "glpi-project/tools": "^0.7.1", "php-parallel-lint/php-parallel-lint": "^1.3", + "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^9.6", "squizlabs/php_codesniffer": "^3.7" }, diff --git a/hook.php b/hook.php index 079c2ef..64458c0 100644 --- a/hook.php +++ b/hook.php @@ -37,6 +37,7 @@ */ function plugin_centreon_install() { + /** @var DBmysql $DB */ global $DB; $default_charset = DBConnection::getDefaultCharset(); @@ -72,6 +73,7 @@ function plugin_centreon_install() */ function plugin_centreon_uninstall() { + /** @var DBmysql $DB */ global $DB; $tables = [GlpiPlugin\Centreon\Host::getTable(),]; diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..aa3b353 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,19 @@ +parameters: + parallel: + maximumNumberOfProcesses: 2 + level: 2 + bootstrapFiles: + - ../../inc/based_config.php + paths: + - src + - front + - ajax + - hook.php + - setup.php + scanDirectories: + - ../../inc + - ../../src + stubFiles: + - ../../stubs/glpi_constants.php +rules: + - GlpiProject\Tools\PHPStan\Rules\GlobalVarTypeRule diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..969cd4b --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,9 @@ + + + + + + tests + + + diff --git a/setup.php b/setup.php index 0581e3b..d276877 100644 --- a/setup.php +++ b/setup.php @@ -45,6 +45,7 @@ */ function plugin_init_centreon() { + /** @var array $PLUGIN_HOOKS */ global $PLUGIN_HOOKS; $PLUGIN_HOOKS['csrf_compliant']['centreon'] = true; diff --git a/src/ApiClient.php b/src/ApiClient.php index 583c116..967a2da 100644 --- a/src/ApiClient.php +++ b/src/ApiClient.php @@ -77,6 +77,7 @@ public function connectionRequest(array $params = []) public function diagnostic() { + $result = []; try { $test = $this->connectionRequest(['throw' => true]); diff --git a/src/Config.php b/src/Config.php index eea90a6..8135abe 100644 --- a/src/Config.php +++ b/src/Config.php @@ -74,6 +74,7 @@ public static function displayTabContentForItem( public static function showForConfig(\Config $config, $withtemplate = 0) { + /** @var array $CFG_GLPI */ global $CFG_GLPI; if (!self::canView()) { diff --git a/src/Host.php b/src/Host.php index 455856c..78c994a 100644 --- a/src/Host.php +++ b/src/Host.php @@ -86,6 +86,7 @@ public function hostList() if ($res["security"]["token"] != null) { $list = $api->getHostsList(); if ($list != null) { + $items_centreon = []; foreach ($list["result"] as $item_centreon) { $items_centreon[] = [ 'centreon_id' => $item_centreon["id"],