Skip to content

Commit

Permalink
Fixed update process
Browse files Browse the repository at this point in the history
  • Loading branch information
UndefinedOffset committed Apr 13, 2014
1 parent 5677764 commit eb9bed8
Showing 1 changed file with 42 additions and 46 deletions.
88 changes: 42 additions & 46 deletions code/model/CodeBankConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

Expand Down

0 comments on commit eb9bed8

Please sign in to comment.