diff --git a/code/model/CodeBankConfig.php b/code/model/CodeBankConfig.php index 232c068..2af3dd1 100644 --- a/code/model/CodeBankConfig.php +++ b/code/model/CodeBankConfig.php @@ -109,53 +109,49 @@ public function requireDefaultRecords() { //Sanity Check database version against latest if(version_compare($dbVerTmp[0], $versionTmp[0], '<')) { - DB::alteration_message('Code Bank Server database version '.CodeBankConfig::CurrentConfig()->Version.', current version available for download is '.$latestVersion, 'error'); - return; + $data=array( + 'version'=>CodeBankConfig::CurrentConfig()->Version, + 'db_type'=>'SERVER' + ); + + $data=http_build_query($data); + + + $context=stream_context_create(array( + 'http'=>array( + 'method'=>'POST', + 'header'=>"Content-type: application/x-www-form-urlencoded\r\n" + ."Content-Length: ".strlen($data)."\r\n", + 'content'=>$data + ) + )); + + + //Download and run queries needed + $sql=simplexml_load_string(file_get_contents('http://update.edchipman.ca/codeBank/DatabaseUpgrade.php', false, $context)); + $sets=count($sql->query); + foreach($sql->query as $query) { + $queries=explode('$',$query); + $t=count($queries); + + foreach($queries as $query) { + if(empty($query)) { + continue; + } + + DB::query($query); + } + } + + + //Update Database Version + $codeBankConfig=CodeBankConfig::CurrentConfig(); + $codeBankConfig->Version=$latestVersion; + $codeBankConfig->write(); + + + DB::alteration_message('Code Bank Server database upgraded', 'changed'); } - - - $data=array( - 'version'=>CodeBankConfig::CurrentConfig()->Version, - 'db_type'=>'SERVER' - ); - - $data=http_build_query($data); - - - $context=stream_context_create(array( - 'http'=>array( - 'method'=>'POST', - 'header'=>"Content-type: application/x-www-form-urlencoded\r\n" - ."Content-Length: ".strlen($data)."\r\n", - 'content'=>$data - ) - )); - - - //Download and run queries needed - $sql=simplexml_load_string(file_get_contents('http://update.edchipman.ca/codeBank/DatabaseUpgrade.php', false, $context)); - $sets=count($sql->query); - foreach($sql->query as $query) { - $queries=explode('$',$query); - $t=count($queries); - - foreach($queries as $query) { - if(empty($query)) { - continue; - } - - DB::query($query); - } - } - - - //Update Database Version - $codeBankConfig=CodeBankConfig::CurrentConfig(); - $codeBankConfig->Version=$latestVersion; - $codeBankConfig->write(); - - - DB::alteration_message('Code Bank Server database upgraded', 'changed'); } }