xref: /webtrees/app/Schema/Migration43.php (revision c7aa856b917ed7f821ff91e715981bae3c43d016)
1*c7aa856bSGreg Roach<?php
2*c7aa856bSGreg Roach
3*c7aa856bSGreg Roach/**
4*c7aa856bSGreg Roach * webtrees: online genealogy
5*c7aa856bSGreg Roach * Copyright (C) 2019 webtrees development team
6*c7aa856bSGreg Roach * This program is free software: you can redistribute it and/or modify
7*c7aa856bSGreg Roach * it under the terms of the GNU General Public License as published by
8*c7aa856bSGreg Roach * the Free Software Foundation, either version 3 of the License, or
9*c7aa856bSGreg Roach * (at your option) any later version.
10*c7aa856bSGreg Roach * This program is distributed in the hope that it will be useful,
11*c7aa856bSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*c7aa856bSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13*c7aa856bSGreg Roach * GNU General Public License for more details.
14*c7aa856bSGreg Roach * You should have received a copy of the GNU General Public License
15*c7aa856bSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16*c7aa856bSGreg Roach */
17*c7aa856bSGreg Roach
18*c7aa856bSGreg Roachdeclare(strict_types=1);
19*c7aa856bSGreg Roach
20*c7aa856bSGreg Roachnamespace Fisharebest\Webtrees\Schema;
21*c7aa856bSGreg Roach
22*c7aa856bSGreg Roachuse Fisharebest\Webtrees\Site;
23*c7aa856bSGreg Roachuse Illuminate\Database\Capsule\Manager as DB;
24*c7aa856bSGreg Roach
25*c7aa856bSGreg Roach/**
26*c7aa856bSGreg Roach * Upgrade the database schema from version 43 to version 44.
27*c7aa856bSGreg Roach */
28*c7aa856bSGreg Roachclass Migration43 implements MigrationInterface
29*c7aa856bSGreg Roach{
30*c7aa856bSGreg Roach    /**
31*c7aa856bSGreg Roach     * Upgrade to to the next version
32*c7aa856bSGreg Roach     *
33*c7aa856bSGreg Roach     * @return void
34*c7aa856bSGreg Roach     */
35*c7aa856bSGreg Roach    public function upgrade(): void
36*c7aa856bSGreg Roach    {
37*c7aa856bSGreg Roach        // Language was previously a tree-setting.
38*c7aa856bSGreg Roach        $language = DB::table('gedcom_setting')
39*c7aa856bSGreg Roach            ->where('setting_name', '=', 'LANGUAGE')
40*c7aa856bSGreg Roach            ->where('gedcom_id', '>', 0)
41*c7aa856bSGreg Roach            ->value('setting_value');
42*c7aa856bSGreg Roach
43*c7aa856bSGreg Roach        // Now it is a site-setting.
44*c7aa856bSGreg Roach        DB::table('site_setting')->updateOrInsert([
45*c7aa856bSGreg Roach            'setting_name' => 'LANGUAGE',
46*c7aa856bSGreg Roach        ], [
47*c7aa856bSGreg Roach            'setting_value' => $language ?? 'en-US',
48*c7aa856bSGreg Roach        ]);
49*c7aa856bSGreg Roach
50*c7aa856bSGreg Roach        // Cleanup
51*c7aa856bSGreg Roach        DB::table('gedcom_setting')
52*c7aa856bSGreg Roach            ->where('setting_name', '=', 'LANGUAGE')
53*c7aa856bSGreg Roach            ->delete();
54*c7aa856bSGreg Roach    }
55*c7aa856bSGreg Roach}
56