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