diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 1ab419c..2c54e23 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -25,20 +25,20 @@ When generating code for this repository: ## Project Structure ``` -hmib/ # Repository root (install to plugins/hmib/ in Cacti) -├── images/ # UI icons -├── locales/ # Internationalization files -├── templates/ # Device/graph template XML -├── associate_os_type.php # Maps discovered devices to Host MIB types -├── hmib.php # Main viewer (summary, hardware, storage, software, running, devices) -├── hmib_types.php # Host MIB type administration -├── poller_graphs.php # Graph URL helper output -├── poller_hmib.php # Background poller entry point (CLI) -├── snmp.php # SNMP collection routines -├── snmp_functions.php # SNMP helper/formatting functions -├── INFO # Plugin metadata (name, version, compat) +hmib/ # Repository root (install to plugins/hmib/ in Cacti) +├── images/ # UI icons +├── locales/ # Internationalization files +├── templates/ # Device/graph template XML +├── associate_os_type.php # Maps discovered devices to Host MIB types +├── hmib.php # Main viewer (summary, hardware, storage, software, running, devices) +├── hmib_types.php # Host MIB type administration +├── poller_graphs.php # Graph URL helper output +├── poller_hmib.php # Background poller entry point (CLI) +├── snmp.php # SNMP collection routines +├── snmp_functions.php # SNMP helper/formatting functions +├── INFO # Plugin metadata (name, version, compat) ├── README.md -└── setup.php # Plugin install/uninstall/upgrade hooks +└── setup.php # Plugin install/uninstall/upgrade hooks ``` ## Naming Conventions @@ -210,3 +210,7 @@ existing code or adding new code, not just in dedicated cleanup passes: line, `@param` lines, a blank comment line, then `@return`. Infer parameter/return types from actual usage; don't change the function's real type-hints in the same pass (let static analysis flag mismatches separately). Skip vendored third-party library files. + +## File manifest & upgrade pruning + +The plugin ships a root `manifest.json` with three arrays: `tombstones` (files/directories older versions shipped that have since moved or been removed), `expected` (the top-level files and directories that ship today, directories written with a trailing `/`), and `whitelist` (paths holding user data that must never be touched). Keep `expected` current: CI runs `tests/bin/validate-manifest.php`, which fails on any drift between `expected` and the real top-level tree (it ignores `tests/`, `phpunit.xml`, `.git*`, `.md*`, and whitelisted paths). Custom customer CSS/theme files belong in `expected`, and stylesheets live in `css/` (not `themes/`). On upgrade, `hmib_prune_files()` deletes the tombstoned paths, the dev-only `tests/` tree, and the `phpunit.xml` test config, leaves `whitelist`, `.git*`, and `.md*` alone, and logs (without removing) any top-level entry the manifest does not account for. As a safety measure it refuses any tombstone that resolves outside the plugin directory (a tampered manifest.json) and logs a warning for any file or directory it cannot remove. When you move or delete a shipped file, add its old path to `tombstones` and update `expected` in the same change. diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index 1d988a3..93581b1 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -89,6 +89,9 @@ jobs: - name: Check PHP version run: php -v + - name: Validate plugin manifest (expected-file drift) + run: php cacti/plugins/hmib/tests/bin/validate-manifest.php + - name: Run apt-get update run: sudo apt-get update diff --git a/CHANGELOG.md b/CHANGELOG.md index 53a144f..d6da243 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ChangeLog --- develop --- +* dev: Relocate schema provisioning into includes/database.php (loaded from setup.php) and add the fleet manifest.json with upgrade-time file pruning * dev: Enforce patch coverage of changed lines in CI and remove the inert COMPOSER_ROOT_VERSION env from the Pest step, and measure coverage with xdebug so the plugin's own sources are instrumented * issue: Fix PHP 8.1+ 'float-string to int loses precision' deprecation from runCollector() by typing the last-run timestamp parameter as float * dev: Bring all plugin code to PHPStan level 8 with accurate parameter and return types diff --git a/includes/database.php b/includes/database.php new file mode 100644 index 0000000..0dbe9a5 --- /dev/null +++ b/includes/database.php @@ -0,0 +1,288 @@ + setup.php + includes/database.php hmib.php hmib_types.php poller_hmib.php diff --git a/setup.php b/setup.php index 4fe298a..604e2df 100644 --- a/setup.php +++ b/setup.php @@ -22,6 +22,8 @@ +-------------------------------------------------------------------------+ */ +require_once(__DIR__ . '/includes/database.php'); + /** * Return the CSP nonce attribute for inline