2019-03-16 19:02:13 +01:00
|
|
|
<?php
|
2019-10-02 06:38:38 +02:00
|
|
|
/**
|
|
|
|
|
* 2019_03_11_223700_fix_ldap_configuration.php
|
2020-03-17 16:06:30 +00:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org.
|
2019-10-02 06:38:38 +02:00
|
|
|
*
|
|
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-08-17 12:09:03 +02:00
|
|
|
declare(strict_types=1);
|
2019-03-16 19:02:13 +01:00
|
|
|
|
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
2023-04-07 19:33:19 +02:00
|
|
|
use Illuminate\Database\QueryException;
|
2019-03-16 19:02:13 +01:00
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
|
|
|
|
|
|
/**
|
2020-03-17 16:06:30 +00:00
|
|
|
* Class FixLdapConfiguration.
|
2021-03-12 06:17:50 +01:00
|
|
|
*
|
2020-10-27 06:53:47 +01:00
|
|
|
* @codeCoverageIgnore
|
2019-03-16 19:02:13 +01:00
|
|
|
*/
|
|
|
|
|
class FixLdapConfiguration extends Migration
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Reverse the migrations.
|
|
|
|
|
*/
|
|
|
|
|
public function down(): void
|
|
|
|
|
{
|
2023-05-29 13:56:55 +02:00
|
|
|
if (Schema::hasColumn('users', 'objectguid')) {
|
2023-04-10 08:29:27 +02:00
|
|
|
try {
|
|
|
|
|
Schema::table(
|
|
|
|
|
'users',
|
2023-12-21 05:06:17 +01:00
|
|
|
static function (Blueprint $table): void {
|
2023-04-10 08:29:27 +02:00
|
|
|
$table->dropColumn(['objectguid']);
|
|
|
|
|
}
|
|
|
|
|
);
|
2024-04-02 15:40:33 +02:00
|
|
|
} catch (QueryException $e) {
|
2023-08-11 19:37:52 +02:00
|
|
|
app('log')->error(sprintf('Could not execute query: %s', $e->getMessage()));
|
|
|
|
|
app('log')->error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
|
2023-04-10 08:29:27 +02:00
|
|
|
}
|
2023-04-07 19:33:19 +02:00
|
|
|
}
|
2019-03-16 19:02:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Run the migrations.
|
2023-12-20 19:41:37 +01:00
|
|
|
*
|
2023-11-30 17:28:44 +01:00
|
|
|
* @SuppressWarnings(PHPMD.ShortMethodName)
|
2019-03-16 19:02:13 +01:00
|
|
|
*/
|
|
|
|
|
public function up(): void
|
|
|
|
|
{
|
2023-12-20 19:41:37 +01:00
|
|
|
/*
|
2019-03-16 19:02:13 +01:00
|
|
|
* ADLdap2 appears to require the ability to store an objectguid for LDAP users
|
|
|
|
|
* now. To support this, we add the column.
|
|
|
|
|
*/
|
2023-05-29 13:56:55 +02:00
|
|
|
if (!Schema::hasColumn('users', 'objectguid')) {
|
2023-04-10 08:29:27 +02:00
|
|
|
try {
|
|
|
|
|
Schema::table(
|
|
|
|
|
'users',
|
2023-12-21 05:06:17 +01:00
|
|
|
static function (Blueprint $table): void {
|
2023-04-10 08:29:27 +02:00
|
|
|
$table->uuid('objectguid')->nullable()->after('id');
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
} catch (QueryException $e) {
|
2023-08-11 19:37:52 +02:00
|
|
|
app('log')->error(sprintf('Could not execute query: %s', $e->getMessage()));
|
|
|
|
|
app('log')->error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
|
2023-04-10 08:29:27 +02:00
|
|
|
}
|
2023-04-07 19:33:19 +02:00
|
|
|
}
|
2019-03-16 19:02:13 +01:00
|
|
|
}
|
|
|
|
|
}
|