From 2cf8bd02c343233fd348ca427b866eac3d79bda7 Mon Sep 17 00:00:00 2001 From: Liviu-Mihail Concioiu Date: Thu, 5 Mar 2026 00:01:32 +0100 Subject: [PATCH] Check if ddlog is not empty Signed-off-by: Liviu-Mihail Concioiu --- libraries/classes/Tracking.php | 35 ++++++++++++++++++---------------- phpstan-baseline.neon | 2 +- psalm-baseline.xml | 3 ++- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/libraries/classes/Tracking.php b/libraries/classes/Tracking.php index 8c5c6fa209..196197fa5c 100644 --- a/libraries/classes/Tracking.php +++ b/libraries/classes/Tracking.php @@ -642,25 +642,28 @@ class Tracking . ']'; $data = Tracker::getTrackedData($_POST['db'], $_POST['table'], $_POST['version']); - // Get first DROP TABLE/VIEW and CREATE TABLE/VIEW statements - $drop_create_statements = $data['ddlog'][0]['statement']; + // ddlog can be empty if all statements are deleted + if ($data['ddlog'] !== []) { + // Get first DROP TABLE/VIEW and CREATE TABLE/VIEW statements + $drop_create_statements = $data['ddlog'][0]['statement']; - if ( - mb_strstr($data['ddlog'][0]['statement'], 'DROP TABLE') - || mb_strstr($data['ddlog'][0]['statement'], 'DROP VIEW') - ) { - $drop_create_statements .= $data['ddlog'][1]['statement']; + if ( + mb_strstr($data['ddlog'][0]['statement'], 'DROP TABLE') + || mb_strstr($data['ddlog'][0]['statement'], 'DROP VIEW') + ) { + $drop_create_statements .= $data['ddlog'][1]['statement']; + } + + // Print SQL code + $html .= Generator::getMessage( + sprintf( + __('Version %s snapshot (SQL code)'), + htmlspecialchars($_POST['version']) + ), + $drop_create_statements + ); } - // Print SQL code - $html .= Generator::getMessage( - sprintf( - __('Version %s snapshot (SQL code)'), - htmlspecialchars($_POST['version']) - ), - $drop_create_statements - ); - // Unserialize snapshot $temp = Core::safeUnserialize($data['schema_snapshot']); if ($temp === null) { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index dbc0fa016e..bc0be93404 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -36537,7 +36537,7 @@ parameters: - message: "#^Cannot access offset 'ddlog' on mixed\\.$#" - count: 4 + count: 1 path: libraries/classes/Tracking.php - diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 310a18293c..19a9b95724 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -13846,12 +13846,13 @@ $str5 $value['Name'] - + $data[$which_log][$delete_id] $data['ddlog'] $data['ddlog'] $data['ddlog'] $data['ddlog'] + $data['ddlog'] $data['schema_snapshot'] $entry['date'] $entry['date']