167992b6aSRichard Cissee<?php 23976b470SGreg Roach 367992b6aSRichard Cissee/** 467992b6aSRichard Cissee * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 667992b6aSRichard Cissee * This program is free software: you can redistribute it and/or modify 767992b6aSRichard Cissee * it under the terms of the GNU General Public License as published by 867992b6aSRichard Cissee * the Free Software Foundation, either version 3 of the License, or 967992b6aSRichard Cissee * (at your option) any later version. 1067992b6aSRichard Cissee * This program is distributed in the hope that it will be useful, 1167992b6aSRichard Cissee * but WITHOUT ANY WARRANTY; without even the implied warranty of 1267992b6aSRichard Cissee * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1367992b6aSRichard Cissee * GNU General Public License for more details. 1467992b6aSRichard Cissee * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 1667992b6aSRichard Cissee */ 17fcfa147eSGreg Roach 1867992b6aSRichard Cisseedeclare(strict_types=1); 1967992b6aSRichard Cissee 2067992b6aSRichard Cisseenamespace Fisharebest\Webtrees\Schema; 2167992b6aSRichard Cissee 226f4ec3caSGreg Roachuse Fisharebest\Webtrees\DB; 2387cca37cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleBlockInterface; 2487cca37cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleChartInterface; 2587cca37cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleListInterface; 2687cca37cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleMenuInterface; 2787cca37cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleReportInterface; 2887cca37cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleSidebarInterface; 2987cca37cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleTabInterface; 3087cca37cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleThemeInterface; 3167992b6aSRichard Cisseeuse Illuminate\Database\Schema\Blueprint; 3267992b6aSRichard Cissee 3367992b6aSRichard Cissee/** 3467992b6aSRichard Cissee * Upgrade the database schema from version 42 to version 43. 3567992b6aSRichard Cissee */ 3667992b6aSRichard Cisseeclass Migration42 implements MigrationInterface 3767992b6aSRichard Cissee{ 3887cca37cSGreg Roach private const COMPONENT_TO_INTERFACE = [ 3987cca37cSGreg Roach 'block' => ModuleBlockInterface::class, 4087cca37cSGreg Roach 'chart' => ModuleChartInterface::class, 4187cca37cSGreg Roach 'list' => ModuleListInterface::class, 4287cca37cSGreg Roach 'menu' => ModuleMenuInterface::class, 4387cca37cSGreg Roach 'report' => ModuleReportInterface::class, 4487cca37cSGreg Roach 'sidebar' => ModuleSidebarInterface::class, 4587cca37cSGreg Roach 'tab' => ModuleTabInterface::class, 4687cca37cSGreg Roach 'theme' => ModuleThemeInterface::class, 4787cca37cSGreg Roach ]; 4887cca37cSGreg Roach 4967992b6aSRichard Cissee public function upgrade(): void 5067992b6aSRichard Cissee { 5187cca37cSGreg Roach // doctrine/dbal cannot modify tables containing ENUM fields 5267992b6aSRichard Cissee $data = DB::table('module_privacy')->get(); 5387cca37cSGreg Roach 5467992b6aSRichard Cissee DB::schema()->drop('module_privacy'); 5567992b6aSRichard Cissee 560b5fd0a6SGreg Roach DB::schema()->create('module_privacy', static function (Blueprint $table): void { 5787cca37cSGreg Roach $table->increments('id'); 5867992b6aSRichard Cissee $table->string('module_name', 32); 5967992b6aSRichard Cissee $table->integer('gedcom_id'); 6087cca37cSGreg Roach $table->string('interface'); 6167992b6aSRichard Cissee $table->tinyInteger('access_level'); 6267992b6aSRichard Cissee 6309331e47SGreg Roach // Default constraint names are too long for MySQL. 64*211018abSGreg Roach $key1 = DB::prefix($table->getTable() . '_ix1'); 65*211018abSGreg Roach $key2 = DB::prefix($table->getTable() . '_ix2'); 6609331e47SGreg Roach 6709331e47SGreg Roach $table->unique(['gedcom_id', 'module_name', 'interface'], $key1); 6809331e47SGreg Roach $table->unique(['module_name', 'gedcom_id', 'interface'], $key2); 6967992b6aSRichard Cissee 7087cca37cSGreg Roach $table->foreign('module_name')->references('module_name')->on('module')->onDelete('cascade'); 7187cca37cSGreg Roach $table->foreign('gedcom_id')->references('gedcom_id')->on('gedcom')->onDelete('cascade'); 7267992b6aSRichard Cissee }); 7367992b6aSRichard Cissee 7487cca37cSGreg Roach foreach ($data as $datum) { 7567992b6aSRichard Cissee DB::table('module_privacy')->insert([ 7687cca37cSGreg Roach 'module_name' => $datum->module_name, 7787cca37cSGreg Roach 'gedcom_id' => $datum->gedcom_id, 7887cca37cSGreg Roach 'interface' => self::COMPONENT_TO_INTERFACE[$datum->component], 7987cca37cSGreg Roach 'access_level' => $datum->access_level, 8067992b6aSRichard Cissee ]); 8167992b6aSRichard Cissee } 8267992b6aSRichard Cissee } 8367992b6aSRichard Cissee} 84