Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions includes/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ function intropage_upgrade_database(): void {
$current = $info['version'];
$oldv = db_fetch_cell('SELECT version FROM plugin_config WHERE directory = "intropage"');

// The plugin's library directory moved from include/ to includes/. Repoint
// any plugin_hooks row still bound to the old path on every check - not only
// during a version-change upgrade - because an install whose version was
// already bumped without its hooks being repointed would otherwise keep
// loading the stale include/<file> path (or, once include/ is deleted, fail
// Cacti's plugin file-inclusion security check for it) on every page. The
// LIKE filter makes this a no-op on healthy installs.
db_execute("UPDATE plugin_hooks SET file = REPLACE(file, 'include/', 'includes/') WHERE name = 'intropage' AND file LIKE 'include/%'");
Comment thread
TheWitness marked this conversation as resolved.

if (!cacti_version_compare($oldv, $current, '=')) {
if (cacti_version_compare($oldv, '3.0.0', '<=')) {
include_once($config['base_path'] . '/plugins/intropage/includes/functions.php');
Expand Down Expand Up @@ -369,11 +378,6 @@ function intropage_upgrade_database(): void {
ADD COLUMN `height` enum("normal","double","triple") NOT NULL DEFAULT "normal"');
}

// The plugin's library directory moved from include/ to includes/; repoint
// any hook still registered against the old path so existing installs load
// them from the new location after upgrade.
db_execute("UPDATE plugin_hooks SET file = REPLACE(file, 'include/', 'includes/') WHERE name = 'intropage' AND file LIKE 'include/%'");

// Remove files/directories a previous version left behind (per manifest.json).
plugin_intropage_prune_files();

Expand Down
15 changes: 13 additions & 2 deletions tests/Unit/IntropageLifecycleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
*/

/*
Expand Down Expand Up @@ -45,8 +47,17 @@
expect(plugin_intropage_upgrade())->toBeFalse();
});

it('does nothing when the stored version already matches the plugin version', function () {
it('repoints stale include/ hooks even when the stored version already matches', function () {
plugin_intropage_check_config();

expect($GLOBALS['__test_db_calls'])->toBeEmpty();
// On an up-to-date install the only work is the idempotent include/ ->
// includes/ plugin_hooks repoint; no schema migration or version write runs.
expect($GLOBALS['__test_db_calls'])->toHaveCount(1);

$call = $GLOBALS['__test_db_calls'][0];

expect($call['fn'])->toBe('db_execute')
->and($call['sql'])->toContain('UPDATE plugin_hooks')
->and($call['sql'])->toContain("REPLACE(file, 'include/', 'includes/')")
->and($call['sql'])->toContain("file LIKE 'include/%'");
});
Loading