Skip to content

Commit 440f327

Browse files
author
Copilot
committed
fix(upgrade): re-register is_device_in_maintenance hook against includes/functions.php
plugin_maint_install() registers the hook with the relocated includes/functions.php path, but install never re-runs on upgrade and core's api_plugin_upgrade_register() only touches plugin_config, never plugin_hooks. Existing installs therefore keep the stale functions.php hook file. Re-register the hook in plugin_maint_check_upgrade()'s version-change branch so upgraded sites pick up the new path (currently only surviving via the back-compat root shim). Assert the repoint in MaintCheckUpgradeTest.
1 parent 1071b72 commit 440f327

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
--- develop ---
44

5-
* refactor: Move schema management into includes/database.php (the thold model) and relocate functions.php into includes/; setup.php delegates via require_once, and plugin_maint_check_upgrade() now refreshes the schema via db_update_table() and updates the full plugin_config row on a version change. Switches every file inclusion from include/include_once to require/require_once
5+
* refactor: Move schema management into includes/database.php (the thold model) and relocate functions.php into includes/; setup.php delegates via require_once, and plugin_maint_check_upgrade() now refreshes the schema via db_update_table(), re-registers the is_device_in_maintenance hook against includes/functions.php, and updates the full plugin_config row on a version change. Switches every file inclusion from include/include_once to require/require_once
66
* dev: Enforce patch coverage of changed lines in CI and remove the inert COMPOSER_ROOT_VERSION env from the Pest step
77
* feature: Add a standard Cacti search filter to the Maintenance Schedules list that also matches the hostname/description/location/site name of associated Thold devices and the hostname/description of associated Servcheck tests
88
* security: Add a version-safe CSP nonce (`plugin_maint_csp_nonce()`) to every inline `<script>` tag so pages stay compatible with Cacti's Content-Security-Policy nonce enforcement, while falling back cleanly on older Cacti releases that lack the `CactiSecureHeaders` class

‎setup.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ function plugin_maint_check_upgrade(): void {
177177
// version once every table reconciled, so a failed refresh is retried on
178178
// the next request instead of being masked by a now-matching version.
179179
if (maint_upgrade_tables()) {
180+
// Re-register the is_device_in_maintenance hook so existing installs
181+
// pick up the relocated includes/functions.php file. plugin_maint_install()
182+
// registers the new path, but it never re-runs on upgrade, and core's
183+
// upgrade path only touches plugin_config, never plugin_hooks.
184+
api_plugin_register_hook('maint', 'is_device_in_maintenance', 'plugin_maint_check_cacti_host', 'includes/functions.php');
185+
180186
db_execute_prepared('UPDATE plugin_config
181187
SET version = ?, name = ?, author = ?, webpage = ?
182188
WHERE directory = ?',

‎tests/Unit/MaintCheckUpgradeTest.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
// db_table_exists defaults to false -> create branch; stale stored version.
4242
$GLOBALS['__test_table_exists'] = [];
4343
maint_test_queue('db_fetch_cell_prepared', '0.0-stale');
44-
$GLOBALS['__test_db_calls'] = [];
44+
$GLOBALS['__test_db_calls'] = [];
45+
$GLOBALS['__test_registered_hooks'] = [];
4546

4647
try {
4748
plugin_maint_check_upgrade();
@@ -71,8 +72,13 @@
7172
return $call['fn'] === 'db_execute_prepared' && strpos($call['sql'], 'plugin_config') !== false;
7273
});
7374

75+
$repointed = array_filter($GLOBALS['__test_registered_hooks'], function ($hook) {
76+
return $hook['hook'] === 'is_device_in_maintenance' && $hook['file'] === 'includes/functions.php';
77+
});
78+
7479
expect($created)->toContain('plugin_maint_schedules');
7580
expect($created)->toContain('plugin_maint_hosts');
81+
expect($repointed)->not->toBeEmpty();
7682
expect($config_updates)->not->toBeEmpty();
7783
});
7884

0 commit comments

Comments
 (0)