Repository navigation
Relocate schema + functions to includes/ and add db_update_table upgrade #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a3f8988
Relocate schema + functions to includes/, add db_update_table upgrade
1e421d0
INFO: set compat to 1.2.32
36f17c9
CI: prepared version lookup in check_upgrade, allowlist includes/data…
c910b49
test: cover plugin_maint_check_upgrade; de-measure maint.php web entry
31fd2f3
fix: restore root functions.php shim for core snmpagent hard-coded in…
TheWitness f0ee6ac
test: measure includes/functions.php and allowlist the root shim
TheWitness 1bf7042
fix: legacy scalar primary for create, gate version bump on upgrade s…
TheWitness 1071b72
fix(ci): match clover files to the longest changed path, not the first
TheWitness 440f327
fix(upgrade): re-register is_device_in_maintenance hook against inclu…
f6245b9
INFO: back off compat to 1.2.29
411eb97
Add manifest.json + upgrade-time file pruning
f5381ea
fix: add root functions.php shim to manifest 'expected' to fix drift …
TheWitness f009aef
revert: drop root functions.php shim; core now prefers includes/funct…
TheWitness 4bd568d
Prune phpunit.xml on upgrade and ignore markdown-lint configs
3de589b
Harden prune against tampered-manifest path traversal
8612569
docs: align the Project Structure comment column
407f933
docs/tests: standardize test header and correct manifest-contract notes
cd0781e
refactor: rename prune helpers to the plugin-slug function prefix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group | | ||
| | | | ||
| | This program is free software; you can redistribute it and/or | | ||
| | modify it under the terms of the GNU General Public License | | ||
| | as published by the Free Software Foundation; either version 2 | | ||
| | of the License, or (at your option) any later version. | | ||
| | | | ||
| | This program is distributed in the hope that it will be useful, | | ||
| | but WITHOUT ANY WARRANTY; without even the implied warranty of | | ||
| | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | ||
| | GNU General Public License for more details. | | ||
| +-------------------------------------------------------------------------+ | ||
| | Cacti: The Complete RRDtool-based Graphing Solution | | ||
| +-------------------------------------------------------------------------+ | ||
| | This code is designed, written, and maintained by the Cacti Group. See | | ||
| | about.php and/or the AUTHORS file for specific developer information. | | ||
| +-------------------------------------------------------------------------+ | ||
| | http://www.cacti.net/ | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| /** | ||
| * The plugin_maint_schedules table definition (one row per maintenance | ||
| * schedule), shared by the create path (api_plugin_db_table_create()) and | ||
| * the upgrade path (db_update_table()) so both stay in sync from a single | ||
| * definition. | ||
| * | ||
| * @return array<string, mixed> The table definition array. | ||
| */ | ||
| function maint_schedules_table_data(): array { | ||
| $data = []; | ||
| $data['columns'][] = ['name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true]; | ||
| $data['columns'][] = ['name' => 'enabled', 'type' => 'varchar(3)', 'NULL' => false, 'default' => 'on']; | ||
| $data['columns'][] = ['name' => 'name', 'type' => 'varchar(128)', 'NULL' => true]; | ||
| $data['columns'][] = ['name' => 'mtype', 'type' => 'int(11)', 'NULL' => false]; | ||
| $data['columns'][] = ['name' => 'stime', 'type' => 'int(22)', 'NULL' => false]; | ||
| $data['columns'][] = ['name' => 'etime', 'type' => 'int(22)', 'NULL' => false]; | ||
| $data['columns'][] = ['name' => 'minterval', 'type' => 'int(11)', 'NULL' => false]; | ||
| $data['primary'] = ['id']; | ||
| $data['keys'][] = ['name' => 'mtype', 'columns' => ['mtype']]; | ||
| $data['keys'][] = ['name' => 'enabled', 'columns' => ['enabled']]; | ||
| $data['type'] = 'InnoDB'; | ||
| $data['comment'] = 'Maintenance Schedules'; | ||
|
|
||
| return $data; | ||
| } | ||
|
|
||
| /** | ||
| * The plugin_maint_hosts table definition (maps devices/tests to a | ||
| * maintenance schedule), shared by the create path | ||
| * (api_plugin_db_table_create()) and the upgrade path (db_update_table()). | ||
| * | ||
| * @return array<string, mixed> The table definition array. | ||
| */ | ||
| function maint_hosts_table_data(): array { | ||
| $data = []; | ||
| $data['columns'][] = ['name' => 'type', 'type' => 'int(6)', 'NULL' => false]; | ||
| $data['columns'][] = ['name' => 'host', 'type' => 'int(12)', 'NULL' => false]; | ||
| $data['columns'][] = ['name' => 'schedule', 'type' => 'int(12)', 'NULL' => false]; | ||
| $data['primary'] = ['type', 'schedule', 'host']; | ||
| $data['keys'][] = ['name' => 'type', 'columns' => ['type']]; | ||
| $data['keys'][] = ['name' => 'schedule', 'columns' => ['schedule']]; | ||
| $data['type'] = 'InnoDB'; | ||
| $data['comment'] = 'Maintenance Schedules Hosts'; | ||
|
|
||
| return $data; | ||
| } | ||
|
|
||
| /** | ||
| * Creates this plugin's database tables (plugin_maint_schedules and | ||
| * plugin_maint_hosts) through Cacti's tracked plugin table API. Called | ||
| * from plugin_maint_install() during installation, and re-run (safely, as | ||
| * a no-op for already-applied changes) from maint_upgrade_tables() during | ||
| * upgrades. | ||
| * | ||
| * @return void | ||
| */ | ||
| function maint_setup_database(): void { | ||
| api_plugin_db_table_create('maint', 'plugin_maint_schedules', maint_create_definition(maint_schedules_table_data())); | ||
| api_plugin_db_table_create('maint', 'plugin_maint_hosts', maint_create_definition(maint_hosts_table_data())); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a copy of a table definition with its array primary key | ||
| * normalized to the legacy backtick-joined scalar form. Older Cacti | ||
| * releases (1.2.0) concatenate data['primary'] straight into the CREATE in | ||
| * api_plugin_db_table_create(), so an array would render PRIMARY KEY | ||
| * (`Array`) and break a fresh install; the array form is retained in the | ||
| * *_table_data() helpers for db_update_table(), which requires it. | ||
| * | ||
| * @param array<string, mixed> $data The table definition (array primary). | ||
| * | ||
| * @return array<string, mixed> The definition with a scalar primary key. | ||
| */ | ||
| function maint_create_definition(array $data): array { | ||
| if (isset($data['primary']) && is_array($data['primary'])) { | ||
| $data['primary'] = implode('`,`', $data['primary']); | ||
| } | ||
|
|
||
| return $data; | ||
| } | ||
|
|
||
| /** | ||
| * Refreshes this plugin's tables to their current definition on upgrade: | ||
| * db_update_table() diffs the live schema against each definition and | ||
| * issues the exact ALTER when the table already exists, otherwise the | ||
| * table is created outright. Called from plugin_maint_check_upgrade() when | ||
| * the stored version changes. | ||
| * | ||
| * @return bool True when every table reconciled; false when any | ||
| * db_update_table()/api_plugin_db_table_create() reported an | ||
| * explicit failure, so the caller can skip the version bump | ||
| * and retry on the next request. | ||
| */ | ||
| function maint_upgrade_tables(): bool { | ||
| $success = true; | ||
|
|
||
| foreach ([ | ||
| 'plugin_maint_schedules' => maint_schedules_table_data(), | ||
| 'plugin_maint_hosts' => maint_hosts_table_data(), | ||
| ] as $table => $data) { | ||
| if (db_table_exists($table)) { | ||
| $result = db_update_table($table, $data); | ||
| } else { | ||
| $result = api_plugin_db_table_create('maint', $table, maint_create_definition($data)); | ||
| } | ||
|
|
||
| if ($result === false) { | ||
| $success = false; | ||
| } | ||
| } | ||
|
|
||
| return $success; | ||
| } | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "tombstones": [], | ||
| "expected": [ | ||
| ".pre-commit-config.yml", | ||
| "CHANGELOG.md", | ||
| "INFO", | ||
| "LICENSE", | ||
| "README.md", | ||
| "includes/", | ||
| "index.php", | ||
| "locales/", | ||
| "maint.php", | ||
| "manifest.json", | ||
| "setup.php" | ||
| ], | ||
| "whitelist": [] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.