Skip to content

Commit

Permalink
Fix build error on unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
craigk5n committed Sep 12, 2023
1 parent dd45dea commit cb546ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
22 changes: 19 additions & 3 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tests/functionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

}

0 comments on commit cb546ea

Please sign in to comment.