Skip to content

Commit eb9bed8

Browse files
Fixed update process
1 parent 5677764 commit eb9bed8

File tree

1 file changed

+42
-46
lines changed

1 file changed

+42
-46
lines changed

code/model/CodeBankConfig.php

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -109,53 +109,49 @@ public function requireDefaultRecords() {
109109

110110
//Sanity Check database version against latest
111111
if(version_compare($dbVerTmp[0], $versionTmp[0], '<')) {
112-
DB::alteration_message('Code Bank Server database version '.CodeBankConfig::CurrentConfig()->Version.', current version available for download is '.$latestVersion, 'error');
113-
return;
112+
$data=array(
113+
'version'=>CodeBankConfig::CurrentConfig()->Version,
114+
'db_type'=>'SERVER'
115+
);
116+
117+
$data=http_build_query($data);
118+
119+
120+
$context=stream_context_create(array(
121+
'http'=>array(
122+
'method'=>'POST',
123+
'header'=>"Content-type: application/x-www-form-urlencoded\r\n"
124+
."Content-Length: ".strlen($data)."\r\n",
125+
'content'=>$data
126+
)
127+
));
128+
129+
130+
//Download and run queries needed
131+
$sql=simplexml_load_string(file_get_contents('http://update.edchipman.ca/codeBank/DatabaseUpgrade.php', false, $context));
132+
$sets=count($sql->query);
133+
foreach($sql->query as $query) {
134+
$queries=explode('$',$query);
135+
$t=count($queries);
136+
137+
foreach($queries as $query) {
138+
if(empty($query)) {
139+
continue;
140+
}
141+
142+
DB::query($query);
143+
}
144+
}
145+
146+
147+
//Update Database Version
148+
$codeBankConfig=CodeBankConfig::CurrentConfig();
149+
$codeBankConfig->Version=$latestVersion;
150+
$codeBankConfig->write();
151+
152+
153+
DB::alteration_message('Code Bank Server database upgraded', 'changed');
114154
}
115-
116-
117-
$data=array(
118-
'version'=>CodeBankConfig::CurrentConfig()->Version,
119-
'db_type'=>'SERVER'
120-
);
121-
122-
$data=http_build_query($data);
123-
124-
125-
$context=stream_context_create(array(
126-
'http'=>array(
127-
'method'=>'POST',
128-
'header'=>"Content-type: application/x-www-form-urlencoded\r\n"
129-
."Content-Length: ".strlen($data)."\r\n",
130-
'content'=>$data
131-
)
132-
));
133-
134-
135-
//Download and run queries needed
136-
$sql=simplexml_load_string(file_get_contents('http://update.edchipman.ca/codeBank/DatabaseUpgrade.php', false, $context));
137-
$sets=count($sql->query);
138-
foreach($sql->query as $query) {
139-
$queries=explode('$',$query);
140-
$t=count($queries);
141-
142-
foreach($queries as $query) {
143-
if(empty($query)) {
144-
continue;
145-
}
146-
147-
DB::query($query);
148-
}
149-
}
150-
151-
152-
//Update Database Version
153-
$codeBankConfig=CodeBankConfig::CurrentConfig();
154-
$codeBankConfig->Version=$latestVersion;
155-
$codeBankConfig->write();
156-
157-
158-
DB::alteration_message('Code Bank Server database upgraded', 'changed');
159155
}
160156
}
161157

0 commit comments

Comments
 (0)