refactor: safe PHP 7.4 modernization#53
Conversation
There was a problem hiding this comment.
Pull request overview
This PR modernizes the Cacti “maint” plugin PHP files by enabling strict typing across key entry points, aiming to improve type safety and consistency within the plugin.
Changes:
- Added
declare(strict_types=1);to multiple plugin PHP entry points. - (Unintended) Introduced PHP syntax errors in
setup.phpaffecting device maintenance actions. - Added
.omc/sessions/*.jsonsession metadata files to the repo.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| setup.php | Adds strict typing but currently contains syntax-breaking changes in device action hooks/handlers. |
| maint.php | Adds strict typing declaration. |
| functions.php | Adds strict typing declaration. |
| index.php | Adds strict typing declaration to the redirect stub. |
| locales/index.php | Adds strict typing declaration to the redirect stub. |
| locales/LC_MESSAGES/index.php | Adds strict typing declaration to the redirect stub. |
| locales/po/index.php | Adds strict typing declaration to the redirect stub. |
| .omc/sessions/fc9af2ff-7ef1-4e14-af43-2eb9d4741f10.json | New session artifact file committed (likely accidental). |
| .omc/sessions/76281449-e05c-4ccd-a666-0e5c56e6d38b.json | New session artifact file committed (likely accidental). |
| * @return array<string, string> Modified actions array with maintenance options | ||
| */ | ||
| function maint_device_action_array(array $actions): array { | ||
| function maint_device_action_[array $actions]: array { |
There was a problem hiding this comment.
Function name/syntax is invalid (maint_device_action_[array ...) and no longer matches the registered hook (maint_device_action_array). This will cause a PHP parse error and break the device action dropdown hook; restore the correct function declaration/name.
| function maint_device_action_[array $actions]: array { | |
| function maint_device_action_array(array $actions): array { |
| $host_list = ''; | ||
|
|
||
| if (!empty($save['host_array']) && is_array($save['host_array'])) { | ||
| if (!empty($save['host_array']) && is_[$save['host_array']]) { |
There was a problem hiding this comment.
is_[$save['host_array']] is invalid PHP and will trigger a parse error. This should be the standard array type check (e.g., is_array(...)) used elsewhere in Cacti.
| if (!empty($save['host_array']) && is_[$save['host_array']]) { | |
| if (!empty($save['host_array']) && is_array($save['host_array'])) { |
| $host_list = ''; | ||
|
|
||
| if (!empty($save['host_array']) && is_array($save['host_array'])) { | ||
| if (!empty($save['host_array']) && is_[$save['host_array']]) { |
There was a problem hiding this comment.
is_[$save['host_array']] is invalid PHP and will trigger a parse error. Replace with the correct array type check (e.g., is_array(...)).
| if (!empty($save['host_array']) && is_[$save['host_array']]) { | |
| if (!empty($save['host_array']) && is_array($save['host_array'])) { |
| $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items')); | ||
|
|
||
| if (is_array($selected_items)) { | ||
| if (is_[$selected_items]) { |
There was a problem hiding this comment.
is_[$selected_items] is invalid PHP and will trigger a parse error, preventing maintenance actions from executing. Replace with the correct array type check (e.g., is_array(...)).
| if (is_[$selected_items]) { | |
| if (is_array($selected_items)) { |
| if (is_[$selected_items]) { | ||
| foreach ($selected_items as $host_id) { | ||
| db_execute_prepared('REPLACE INTO plugin_maint_hosts (type, host, schedule) VALUES (1, ?, ?)', [(int) $host_id, $schedule_id]); |
There was a problem hiding this comment.
is_[$selected_items] is invalid PHP and will trigger a parse error. Replace with the correct array type check (e.g., is_array(...)) so adding devices to an existing schedule works.
| { | ||
| "session_id": "fc9af2ff-7ef1-4e14-af43-2eb9d4741f10", | ||
| "ended_at": "2026-04-09T11:14:41.971Z", | ||
| "reason": "other", | ||
| "agents_spawned": 0, | ||
| "agents_completed": 0, | ||
| "modes_used": [] | ||
| } No newline at end of file |
There was a problem hiding this comment.
These .omc/sessions/*.json files look like local tooling/session artifacts and are not used by the plugin. They should be removed from the repository (and ideally ignored via .gitignore) to avoid committing machine-specific state.
| { | |
| "session_id": "fc9af2ff-7ef1-4e14-af43-2eb9d4741f10", | |
| "ended_at": "2026-04-09T11:14:41.971Z", | |
| "reason": "other", | |
| "agents_spawned": 0, | |
| "agents_completed": 0, | |
| "modes_used": [] | |
| } |
| { | ||
| "session_id": "76281449-e05c-4ccd-a666-0e5c56e6d38b", | ||
| "ended_at": "2026-04-09T11:25:28.665Z", | ||
| "reason": "other", | ||
| "agents_spawned": 0, | ||
| "agents_completed": 0, | ||
| "modes_used": [] | ||
| } No newline at end of file |
There was a problem hiding this comment.
This .omc/sessions/*.json file appears to be local session metadata rather than source code. Please remove it from the PR (and consider adding an ignore rule) to keep the repo clean and deterministic.
| { | |
| "session_id": "76281449-e05c-4ccd-a666-0e5c56e6d38b", | |
| "ended_at": "2026-04-09T11:25:28.665Z", | |
| "reason": "other", | |
| "agents_spawned": 0, | |
| "agents_completed": 0, | |
| "modes_used": [] | |
| } |
Revert bulk array()->[] rewrite damage affecting: - is_array, in_array, xml2array - call_user_func_array, filter_var_array - Function declarations with _array suffix Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
|
Converted to draft to serialize the stack in this repo. Blocked by #49; will un-draft after that merges to avoid cross-PR merge conflicts. |
This PR adds strict typing, short array syntax, and null coalescing operators across the plugin. Standalone infrastructure files were removed per architectural mandate.