|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of SeAT |
| 5 | + * |
| 6 | + * Copyright (C) 2015 to present Leon Jacobs |
| 7 | + * |
| 8 | + * This program is free software; you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License as published by |
| 10 | + * the Free Software Foundation; either version 2 of the License, or |
| 11 | + * (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License along |
| 19 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | + */ |
| 22 | + |
| 23 | +use Illuminate\Database\Migrations\Migration; |
| 24 | +use Illuminate\Support\Facades\DB; |
| 25 | + |
| 26 | +return new class extends Migration { |
| 27 | + /** |
| 28 | + * Run the migrations. |
| 29 | + * |
| 30 | + * @return void |
| 31 | + */ |
| 32 | + public function up() |
| 33 | + { |
| 34 | + // Extends https://github.com/eveseat/web/pull/698 |
| 35 | + |
| 36 | + $remove_scopes = [ |
| 37 | + 'esi-characterstats.read.v1', |
| 38 | + ]; |
| 39 | + |
| 40 | + $sso_scopes_setting = DB::table('global_settings')->where('name', 'sso_scopes')->first(); |
| 41 | + |
| 42 | + // if no sso scope settings have been configured, we don't have anything to migrate |
| 43 | + if($sso_scopes_setting === null) return; |
| 44 | + |
| 45 | + // Fix the global_settings |
| 46 | + $profiles = json_decode($sso_scopes_setting->value); |
| 47 | + foreach($profiles as &$profile) { |
| 48 | + foreach($remove_scopes as $rs) { |
| 49 | + foreach(array_keys($profile->scopes, $rs, true) as $key) { |
| 50 | + unset($profile->scopes[$key]); |
| 51 | + } |
| 52 | + $profile->scopes = array_values($profile->scopes); |
| 53 | + } |
| 54 | + } |
| 55 | + DB::table('global_settings') |
| 56 | + ->where('name', 'sso_scopes') |
| 57 | + ->update(['value' => json_encode($profiles)]); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Reverse the migrations. |
| 62 | + * |
| 63 | + * @return void |
| 64 | + */ |
| 65 | + public function down() |
| 66 | + { |
| 67 | + |
| 68 | + } |
| 69 | +}; |
0 commit comments