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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

--- 5.0 ---

* issue#456: Avoid PHP 8.6 deprecation warnings during schema checks by using object IDs for the connection cache key

* issue#440: Remember only a successful table creation (not updates of existing tables) when avoiding repeated schema operations, so schema drift on an existing table, such as a narrowed owner column, is still detected and repaired within the same request
* issue#451: Treat the stale hostField value 'host_id' (shipped in config_local.php.dist since 2022) as the syslog_incoming 'host' column, and correct config_local.php.dist, so the device-rule mute/maintenance filter and host alerts no longer fail with "Unknown column 'syslog_incoming.host_id'" during alert processing
* issue#452, issue#453: Resolve remote collector hostnames from the Cacti poller table over the Cacti connection instead of joining it on the Syslog connection, and tolerate a failed query, so the Syslog Status and Dashboard tabs no longer throw a TypeError that disabled the plugin when the Syslog tables live in a separate database
Expand Down
2 changes: 1 addition & 1 deletion includes/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function syslog_db_update_table($table, $data, $removecolumns = false, $log = tr
// creation is remembered; updates of existing tables always run so schema
// drift is still repaired (connect and upgrade can overlap).
$connection = is_object($db_conn) ? $db_conn : $syslog_cnn;
$key = (is_object($connection) ? spl_object_hash($connection) : 'default') . ':' . $table;
$key = (is_object($connection) ? spl_object_id($connection) : 'default') . ':' . $table;
$definition = [$connection, $data, $removecolumns];
$exists = syslog_db_table_exists($table, false);

Expand Down
24 changes: 23 additions & 1 deletion tests/Unit/SchemaPrimaryKeyCompatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,26 @@ function schema_primary_capture(string $cacti_version, bool $table_exists): arra
expect($calls)->toBe(2);
expect(syslog_db_update_table('syslog_existing_probe', $definition, false, true, $connection))->toBeFalse();
expect($calls)->toBe(3);
});
});

it('keeps remembered schema creation separate for each connection', function () {
syslog_load_plugin_source('includes/schema.php');
$GLOBALS['config']['cacti_version'] = '1.2.32';
$first = new stdClass();
$second = new stdClass();
$exists = false;
$connections = [];
test_override('syslog_db_table_exists', function () use (&$exists) { return $exists; });
test_override('db_update_table', function ($table, $data, $remove, $log, $connection) use (&$connections, &$exists) {
$connections[] = $connection;
$exists = true;

return true;
});
$definition = ['columns' => [['name' => 'id', 'type' => 'int']], 'primary' => ['id']];

expect(syslog_db_update_table('syslog_connection_probe', $definition, false, true, $first))->toBeTrue();
expect(syslog_db_update_table('syslog_connection_probe', $definition, false, true, $first))->toBeTrue();
expect(syslog_db_update_table('syslog_connection_probe', $definition, false, true, $second))->toBeTrue();
expect($connections)->toBe([$first, $second]);
});
Loading