1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2017 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 */ 16namespace Fisharebest\Webtrees\Schema; 17 18use Fisharebest\Webtrees\Database; 19use Fisharebest\Webtrees\DebugBar; 20use Fisharebest\Webtrees\Site; 21use PDOException; 22 23/** 24 * Upgrade the database schema from version 31 to version 32. 25 */ 26class Migration31 implements MigrationInterface { 27 /** @var string[] Updated language codes */ 28 private $languages = [ 29 'en_AU' => 'en-AU', 30 'en_GB' => 'en-GB', 31 'en_US' => 'en-US', 32 'fr_CA' => 'fr-CA', 33 'pt_BR' => 'pt-BR', 34 ]; 35 36 /** 37 * Upgrade to to the next version 38 */ 39 public function upgrade() { 40 $index_dir = Site::getPreference('INDEX_DIRECTORY'); 41 42 // Due to the language code changes in 1.7.0, we need to update some other settings 43 foreach ($this->languages as $old => $new) { 44 try { 45 Database::prepare( 46 "UPDATE `##site_setting` SET setting_name = REPLACE(setting_name, :old, :new) " . 47 "WHERE setting_name LIKE 'WELCOME_TEXT_AUTH_MODE_%'" 48 )->execute([ 49 'old' => $old, 50 'new' => $new, 51 ]); 52 } catch (PDOException $ex) { 53 DebugBar::addThrowable($ex); 54 55 // Duplicate key? Already done? 56 } 57 58 Database::prepare( 59 "UPDATE `##block_setting` SET setting_value = REPLACE(setting_value, :old, :new) " . 60 "WHERE setting_name = 'languages'" 61 )->execute([ 62 'old' => $old, 63 'new' => $new, 64 ]); 65 66 // Historical fact files 67 if (file_exists($index_dir . 'histo.' . $old . '.php') && !file_exists($index_dir . 'histo.' . $new . '.php')) { 68 rename($index_dir . 'histo.' . $old . '.php', $index_dir . 'histo.' . $new . '.php'); 69 } 70 71 // Language files 72 if (file_exists($index_dir . 'language/' . $old . '.php') && !file_exists($index_dir . 'language/' . $new . '.php')) { 73 rename($index_dir . 'language/' . $old . '.php', $index_dir . 'language/' . $new . '.php'); 74 } 75 76 if (file_exists($index_dir . 'language/' . $old . '.csv') && !file_exists($index_dir . 'language/' . $new . '.csv')) { 77 rename($index_dir . 'language/' . $old . '.csv', $index_dir . 'language/' . $new . '.csv'); 78 } 79 80 if (file_exists($index_dir . 'language/' . $old . '.mo') && !file_exists($index_dir . 'language/' . $new . '.mo')) { 81 rename($index_dir . 'language/' . $old . '.mo', $index_dir . 'language/' . $new . '.mo'); 82 } 83 } 84 } 85} 86