Skip to content

Commit 5229a12

Browse files
committed
fix country_id still being in core_metadata setting (should be country) on fresh install after rework
1 parent 8072b20 commit 5229a12

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

core/updates/Update20260717.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace OpenBroadcaster\Updates;
4+
5+
use OpenBroadcaster\Base\Update;
6+
7+
class Update20260717 extends Update
8+
{
9+
public function items()
10+
{
11+
$updates = [];
12+
$updates[] = "Fix country_id still being in core_metadata setting if it's not been manually updated.";
13+
return $updates;
14+
}
15+
16+
public function run()
17+
{
18+
$this->db->query("SELECT * FROM settings WHERE name = 'core_metadata'");
19+
if ($this->db->error()) {
20+
echo $this->db->error() . PHP_EOL;
21+
return false;
22+
}
23+
24+
$settingJson = $this->db->assoc_list()[0]['value'] ?? null;
25+
26+
if (! $settingJson) {
27+
echo 'Failed to load core metadata settings.' . PHP_EOL;
28+
return false;
29+
}
30+
31+
$setting = json_decode($settingJson, true);
32+
if (! $setting) {
33+
echo 'Invalid JSON in core metadata settings.' . PHP_EOL;
34+
return false;
35+
}
36+
37+
if (! isset($setting['country_id']) && ! isset($setting['country'])) {
38+
// Neither metadata is set, this should not be possible, so something must've gone wrong in decoding.
39+
echo 'Failed to decode either old country_id or new country metadata setting.' . PHP_EOL;
40+
return false;
41+
}
42+
43+
if (isset($setting['country_id']) && ! isset($setting['country'])) {
44+
// Old country_id still used, but no country set, so change that.
45+
$setting['country'] = $setting['country_id'];
46+
}
47+
48+
if (isset($setting['country_id'])) {
49+
// Unset the country_id if it was still set for some reason (should only be from never saving settings
50+
// after previous, but just in case there's other situations).
51+
unset($setting['country_id']);
52+
}
53+
54+
$settingJson = json_encode($setting);
55+
$this->db->where('name', 'core_metadata');
56+
$this->db->update('settings', [
57+
'value' => $settingJson,
58+
]);
59+
if ($this->db->error()) {
60+
echo $this->db->error() . PHP_EOL;
61+
return false;
62+
}
63+
64+
return true;
65+
}
66+
}

0 commit comments

Comments
 (0)