From cb546ea40d8de466f5fbefb24b0acd6e1a6bd1ec Mon Sep 17 00:00:00 2001 From: Craig Knudsen Date: Tue, 12 Sep 2023 12:22:22 -0400 Subject: [PATCH] Fix build error on unit test --- includes/functions.php | 22 +++++++++++++++++++--- tests/functionsTest.php | 6 ++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index ab376450f..1bcc93879 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -6543,7 +6543,7 @@ function upgrade_requires_db_changes($db_type, $old_version, $new_version) { $start_token = "/*upgrade_$old_version*/"; $start_pos = strpos($content, "$start_token"); if ($start_pos) { - $start_pos += strlen($start_token);; + $start_pos += strlen($start_token); } else { // Not found. Find the next version up. $next_version = findNextVersion($content, $old_version); @@ -6559,11 +6559,27 @@ function upgrade_requires_db_changes($db_type, $old_version, $new_version) { } $end_token = "/*upgrade_$new_version*/"; $end_pos = strpos($content, "$end_token"); + if ($end_pos) + $end_pos += strlen($end_token); + else { + // Not found. Find the next version up. This is not likely to + // happen except from the unit tests. + $next_version = findNextVersion($content, $new_version); + if (empty($next_version)) { // shouldn't happen unless file is messed up + return true; + } + $end_token = "/*upgrade_$next_version*/"; + $end_pos = strpos($content, "$end_token"); + if (!$end_pos) { + return true; + } + $end_pos += strlen($end_token); + } $sql_content = trim(substr($content, $start_pos, $end_pos - $start_pos)); $no_comments = preg_replace('/\/\*upgrade_v\d+\.\d+\.\d+\*\/\n?/', '', $sql_content); - // Check if there's more than just the comment (meaning there are SQL commands) - if (strlen($no_comments) > 10) { + // Check if for ';' which will indicate a SQL command + if (strpos($no_comments, ';')) { return true; // Found SQL changes }; return false; // No SQL changes found diff --git a/tests/functionsTest.php b/tests/functionsTest.php index 7c31250cd..4ad333ce8 100644 --- a/tests/functionsTest.php +++ b/tests/functionsTest.php @@ -192,11 +192,13 @@ function test_rgb2html() { function test_upgrade_requires_db_changes() { $this->assertTrue(upgrade_requires_db_changes('mysql', 'v1.3.0', 'v1.9.1')); + $this->assertTrue(upgrade_requires_db_changes('mysql', 'v1.3.0', 'v1.9.8')); + $this->assertTrue(upgrade_requires_db_changes('mysql', 'v1.3.0', 'v1.9.9')); $this->assertFalse(upgrade_requires_db_changes('mysql', 'v1.9.1', 'v1.9.2')); $this->assertFalse(upgrade_requires_db_changes('mysql', 'v1.9.2', 'v1.9.5')); - $this->assertTrue(upgrade_requires_db_changes('mysql', 'v1.9.5', 'v1.9.8')); + $this->assertFalse(upgrade_requires_db_changes('mysql', 'v1.9.3', 'v1.9.5')); + $this->assertTrue(upgrade_requires_db_changes('mysql', 'v1.9.5', 'v1.9.6')); $this->assertFalse(upgrade_requires_db_changes('mysql', 'v1.9.7', 'v1.9.8')); - $this->assertTrue(upgrade_requires_db_changes('mysql', 'v1.3.0', 'v1.9.8')); } }