mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-21 21:08:42 +00:00
chore: add upgrader for #40
This commit is contained in:
parent
d244f36a25
commit
ad0837689a
@ -995,7 +995,8 @@ INSERT INTO `upgrades` (`name`, `status`, `updated_at`) VALUES
|
||||
('21_problem_difficulty', 'up', now()),
|
||||
('28_remote_judge', 'up', now()),
|
||||
('31_problem_resources', 'up', now()),
|
||||
('36_decimal_score_range', 'up', now());
|
||||
('36_decimal_score_range', 'up', now()),
|
||||
('40_contest_resources', 'up', now());
|
||||
/*!40000 ALTER TABLE `upgrades` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
|
1
web/app/upgrade/40_contest_resources/up.sql
Normal file
1
web/app/upgrade/40_contest_resources/up.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE `contests` MODIFY `extra_config` json NOT NULL;
|
37
web/app/upgrade/40_contest_resources/upgrade.php
Normal file
37
web/app/upgrade/40_contest_resources/upgrade.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
return function ($type) {
|
||||
if ($type == 'up_after_sql') {
|
||||
DB::init();
|
||||
|
||||
$contests = DB::selectAll("select * from contests");
|
||||
|
||||
foreach ($contests as $contest) {
|
||||
$extra_config = json_decode($contest['extra_config'], true);
|
||||
|
||||
if (isset($extra_config['links'])) {
|
||||
$new_links = [];
|
||||
|
||||
foreach ($extra_config['links'] as $link) {
|
||||
if (isset($link['name'])) continue;
|
||||
|
||||
$new_links[] = [
|
||||
'name' => $link[0],
|
||||
'url' => '/blogs/' . $link[1],
|
||||
];
|
||||
}
|
||||
|
||||
$extra_config['links'] = $new_links;
|
||||
}
|
||||
|
||||
DB::update([
|
||||
"update contests",
|
||||
"set", [
|
||||
"extra_config" => json_encode($extra_config, JSON_FORCE_OBJECT),
|
||||
],
|
||||
"where", [
|
||||
"id" => $contest['id'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user