Skip to content

Adopt plugin table API and relocate schema to includes/database.php - #254

Merged
cigamit merged 15 commits into
developfrom
refactor/schema-includes-database
Oct 1, 2026
Merged

cigamit merged 15 commits into
developfrom
refactor/schema-includes-database

Conversation

@TheWitness

@TheWitness TheWitness commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Adopt the plugin table API, relocate schema to includes/database.php, consolidate themes/ → css/, and add the fleet file manifest

Adds the fleet-wide manifest.json + upgrade-time file-pruning mechanism and finishes the stylesheet-directory consolidation under css/.

  • Relocated schema provisioning into includes/database.php.
  • themes/<theme>/monitor.css → css/<theme>/monitor.css — the per-Cacti-theme override stylesheets now live alongside the base css/monitor.css; plugin_monitor_page_head() repointed. The old themes/ directory is removed.
  • File manifest + upgrade pruning — new root manifest.json with tombstones (themes/), expected (top-level files/directories shipping today, directories with a trailing /), and whitelist (empty). monitor_prune_files() (in setup.php, called from the version-change block of monitor_check_upgrade()) removes the tombstoned themes/ and the dev-only tests/ tree on upgrade, refuses any path that resolves outside the plugin directory (a tampered manifest.json), warns on any file/directory it cannot remove, leaves whitelist/.git* alone, and logs — without removing — any top-level entry the manifest does not account for.
  • tests/bin/validate-manifest.php (wired into plugin-ci-workflow.yml) fails on drift between expected and the real top-level tree.
  • Tests — added PruneFilesTest, a MonitorPageHeadTest covering the per-theme/base stylesheet selection, and a monitor_poller_bottom fallback test; sandboxed base_path file-wide in MonitorLifecycleTest (pre-loading the real includes/database.php) so its upgrade-path tests run the prune against a throwaway tree; added a get_selected_theme stub.

Validation

Full Pest suite green (74 passed) and patch-coverage passes at 100% (85/85 changed measured lines); manifest drift-check passes and the translation template is up to date.

Revision: hardening & fleet cleanup

Since the initial description, this PR also:

  • Prunes phpunit.xml on upgrade (alongside the dev-only tests/ tree) and leaves .md* lint configs in place — the drift check now ignores tests/, phpunit.xml, .git*, .md*, and whitelisted paths.
  • Hardens the prune against tampered manifests: refuses any tombstone whose normalized path contains a ./.. traversal segment or resolves outside the plugin directory (including via a symlinked directory), and protects a directory when a whitelisted entry lives beneath it — each with added unit coverage.
  • Renames the prune helpers to the documented naming convention: monitor_prune_files() / monitor_rmtree() (the plugin_monitor_ prefix is reserved for lifecycle/hook-registration functions).
  • Gives tests/Unit/PruneFilesTest.php the full standard GPL v2 header and aligns the Project Structure block in .github/copilot-instructions.md.

browniebraun
browniebraun previously approved these changes Sep 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Fresh-install compatibility, dashboard preservation, and schema coverage issues remain unresolved.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Centralizes plugin schema management and adopts Cacti’s table APIs.

Changes:

  • Adds shared table definitions and lifecycle helpers.
  • Updates setup, upgrade, uninstall, and include behavior.
  • Extends database test stubs and coverage configuration.
File Description
includes/​database.php Defines and manages plugin tables.
setup.php Integrates schema lifecycle helpers.
monitor.php Uses mandatory authentication loading.
monitor_controller.php Uses mandatory syslog dependency loading.
tests/​bootstrap-unit.php Adds schema API stubs.
tests/​Unit/​MonitorSetupTableAndPollerTest.php Loads relocated schema helpers.
tests/​bin/​patch-coverage.php Adds coverage exclusions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread includes/database.php
Comment thread includes/database.php
TheWitness and others added 5 commits September 30, 2026 17:37
api_plugin_db_table_create() records plugin_monitor_dashboards in
plugin_db_changes, so api_plugin_db_changes_remove() (run by
api_plugin_uninstall() after plugin_monitor_uninstall()) would drop it
even though monitor_drop_tables() intentionally leaves it in place. Remove
the 'create' ownership record after provisioning (install and upgrade
paths) so user dashboards survive an uninstall. Adds a regression test.
phpunit.xml ships in the repo for CI but is a dev-only test artifact, so it
is removed from manifest.json 'expected', pruned from installs on upgrade
(like tests/), and excluded from the manifest drift check.

The retired markdown-lint configs (.mdlrc, .md_style.rb) are deleted, and
.md* is now ignored like .git*: protected from pruning and excluded from
drift if it reappears.
db_functions.php, monitor_render.php and monitor_controller.php move into
includes/ (the latter two lose the monitor_ prefix, becoming render.php and
controller.php); monitor.php and the tests load them from there. Each per-theme
stylesheet css/<theme>/monitor.css becomes css/<theme>.css so users can drop
their own css/<theme>.css into the css base, and plugin_monitor_page_head()
looks there, falling back to css/monitor.css. The unreferenced
sonar-project.properties is removed. Old paths are tombstoned so existing
installs drop the stale copies on upgrade.
Follows the fleet convention for the plugin's shared library filename; monitor.php,
the measured-source list and the unit test load it from the new name.
Moving the plugin's library files into includes/ changed the source-reference
lines in the translation template; regenerate it so the 'Verify translation
template' CI check passes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Existing v2.9 installations skip the version-gated migration, and unresolved SQL-safety and permission-view failures remain.

Review effort: Balanced
Findings: 1 Medium severity · 2 Low severity

Open (3)
Resolved since last review (2)

Comment thread setup.php Outdated
Comment thread .github/copilot-instructions.md Outdated
Comment thread tests/Unit/MonitorLifecycleTest.php Outdated
Copilot and others added 6 commits September 30, 2026 22:13
The upgrade-time prune now rejects any tombstone containing '.'/'..' segments
(which could escape the plugin directory or resolve to its root) and treats
ancestors of whitelist entries as protected, so a tombstone on a parent
directory can no longer delete a whitelisted file beneath it.
Point the structure tree at the relocated files (libraries now under
includes/, data files under docs/, stylesheets under css/) and align the
trailing '# ...' comments to a single column so they no longer drift right.
- Use the full license header (from the plugin's own setup.php) in
  tests/Unit/PruneFilesTest.php instead of the abbreviated copyright banner.
- Document that the manifest drift check and the upgrade-time prune also
  handle phpunit.xml and .md* files, matching the implemented behavior.
The repository naming contract reserves the plugin_<name>_ prefix for plugin
lifecycle / hook-registration functions; all other functions use the plain
<name>_ prefix. Rename the internal upgrade helpers accordingly:

  plugin_<name>_prune_files() -> <name>_prune_files()
  plugin_<name>_rmtree()      -> <name>_rmtree()

The call site, unit tests, and the copilot-instructions.md references are
updated to match. No behavioral change.
Align the compat metadata (and the contributor-guide references) with the
team decision to standardize the minimum supported Cacti version at 1.2.29;
the previously proposed 1.2.32 floor was not adopted.
Add a 3.0 CHANGELOG section for this cycle's schema/manifest work and set
INFO version = 3.0 so existing 2.9 installs detect the version change and
run the schema refresh and manifest-based file prune.
@cigamit
cigamit merged commit 66358e0 into develop Oct 1, 2026
5 checks passed
@cigamit
cigamit deleted the refactor/schema-includes-database branch October 1, 2026 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants