diff --git a/CHANGELOG.md b/CHANGELOG.md index 73090287..a36637bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/includes/schema.php b/includes/schema.php index 4a704b13..460d8eb2 100644 --- a/includes/schema.php +++ b/includes/schema.php @@ -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); diff --git a/tests/Unit/SchemaPrimaryKeyCompatTest.php b/tests/Unit/SchemaPrimaryKeyCompatTest.php index fca4ee76..214128a0 100644 --- a/tests/Unit/SchemaPrimaryKeyCompatTest.php +++ b/tests/Unit/SchemaPrimaryKeyCompatTest.php @@ -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); -}); \ No newline at end of file +}); + +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]); +});