Skip to content

Commit

Permalink
Fix upgrade.php from failing if oai_ tables do not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
torinfo committed May 9, 2024
1 parent 72a1cce commit 8836fa7
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ function _upgrade_db_query($sql, $params = array()) {
return $result;
}

function _table_exists($table) {
$sql = "select 1 from $table limit 1";
$r = db_query($sql);
return $r!==false;
}

function _do_cleanup()
{
// Cleanup files that are really in the way of functionality, i.e. the responsivetext.css files in some of the themes prior to v3.6
Expand Down Expand Up @@ -1319,11 +1325,17 @@ function upgrade_35(){

function upgrade_36(){
$table = table_by_key('oai_education');
$ok = _upgrade_db_query("alter table $table add column parent_id int(11)");
$message = "Adding parent_id column to oai_education - ok ? " . ($ok ? 'true' : 'false') . "<br>";
$table = table_by_key('oai_categories');
$ok = _upgrade_db_query("alter table $table add column parent_id int(11)");
$message .= "Adding parent_id column to oai_categories - ok ? " . ($ok ? 'true' : 'false') . "<br>";
$exists = _table_exists($table);
if ($exists) {
$ok = _upgrade_db_query("alter table $table add column parent_id int(11)");
$message = "Adding parent_id column to oai_education - ok ? " . ($ok ? 'true' : 'false') . "<br>";
}
$exists = _table_exists($table);
if ($exists) {
$table = table_by_key('oai_categories');
$ok = _upgrade_db_query("alter table $table add column parent_id int(11)");
$message .= "Adding parent_id column to oai_categories - ok ? " . ($ok ? 'true' : 'false') . "<br>";
}
$table = table_by_key('educationlevel');
$ok = _upgrade_db_query("alter table $table add column parent_id int(11)");
$message .= "Adding parent_id column to educationlevel - ok ? " . ($ok ? 'true' : 'false') . "<br>";
Expand Down

0 comments on commit 8836fa7

Please sign in to comment.