1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2018 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16declare(strict_types=1); 17 18namespace Fisharebest\Webtrees\Schema; 19 20use Fisharebest\Webtrees\Database; 21use Fisharebest\Webtrees\DebugBar; 22use Fisharebest\Webtrees\Site; 23use PDOException; 24 25/** 26 * Upgrade the database schema from version 31 to version 32. 27 */ 28class Migration31 implements MigrationInterface 29{ 30 /** @var string[] Updated language codes */ 31 private $languages = [ 32 'en_AU' => 'en-AU', 33 'en_GB' => 'en-GB', 34 'en_US' => 'en-US', 35 'fr_CA' => 'fr-CA', 36 'pt_BR' => 'pt-BR', 37 ]; 38 39 /** 40 * Upgrade to to the next version 41 * 42 * @return void 43 */ 44 public function upgrade(): void 45 { 46 $index_dir = Site::getPreference('INDEX_DIRECTORY'); 47 48 // Due to the language code changes in 1.7.0, we need to update some other settings 49 foreach ($this->languages as $old => $new) { 50 try { 51 Database::prepare( 52 "UPDATE `##site_setting` SET setting_name = REPLACE(setting_name, :old, :new) " . 53 "WHERE setting_name LIKE 'WELCOME_TEXT_AUTH_MODE_%'" 54 )->execute([ 55 'old' => $old, 56 'new' => $new, 57 ]); 58 } catch (PDOException $ex) { 59 // Duplicate key? Already done? 60 } 61 62 Database::prepare( 63 "UPDATE `##block_setting` SET setting_value = REPLACE(setting_value, :old, :new) " . 64 "WHERE setting_name = 'languages'" 65 )->execute([ 66 'old' => $old, 67 'new' => $new, 68 ]); 69 70 // Historical fact files 71 if (file_exists($index_dir . 'histo.' . $old . '.php') && !file_exists($index_dir . 'histo.' . $new . '.php')) { 72 rename($index_dir . 'histo.' . $old . '.php', $index_dir . 'histo.' . $new . '.php'); 73 } 74 75 // Language files 76 if (file_exists($index_dir . 'language/' . $old . '.php') && !file_exists($index_dir . 'language/' . $new . '.php')) { 77 rename($index_dir . 'language/' . $old . '.php', $index_dir . 'language/' . $new . '.php'); 78 } 79 80 if (file_exists($index_dir . 'language/' . $old . '.csv') && !file_exists($index_dir . 'language/' . $new . '.csv')) { 81 rename($index_dir . 'language/' . $old . '.csv', $index_dir . 'language/' . $new . '.csv'); 82 } 83 84 if (file_exists($index_dir . 'language/' . $old . '.mo') && !file_exists($index_dir . 'language/' . $new . '.mo')) { 85 rename($index_dir . 'language/' . $old . '.mo', $index_dir . 'language/' . $new . '.mo'); 86 } 87 } 88 } 89} 90