From 42c3bd8936b4964247a6e6ac4f390b66092b0243 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Wed, 11 May 2022 23:09:20 +0200 Subject: [PATCH] Fix #71 - Cannot view old TOTP entries on latest Docker Image --- ..._change_nullable_in_twofaccounts_table.php | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/database/migrations/2021_09_14_195451_change_nullable_in_twofaccounts_table.php b/database/migrations/2021_09_14_195451_change_nullable_in_twofaccounts_table.php index 5958f51e..5fd2cfb2 100644 --- a/database/migrations/2021_09_14_195451_change_nullable_in_twofaccounts_table.php +++ b/database/migrations/2021_09_14_195451_change_nullable_in_twofaccounts_table.php @@ -16,16 +16,6 @@ class ChangeNullableInTwofaccountsTable extends Migration */ public function up() { - Schema::table('twofaccounts', function (Blueprint $table) { - $table->text('account')->nullable(false)->change(); - $table->string('service')->nullable()->change(); - $table->string('otp_type', 10)->nullable(false)->change(); - $table->text('secret')->nullable(false)->change(); - $table->string('algorithm', 20)->nullable(false)->change(); - $table->unsignedSmallInteger('digits')->nullable(false)->change(); - }); - - $twofaccounts = DB::table('twofaccounts')->select('id', 'legacy_uri')->get(); $settingService = resolve('App\Services\SettingService'); @@ -48,8 +38,39 @@ public function up() catch(Exception $ex) { Log::error($ex->getMessage()); + Log::error("TwoFAccount with id #" . $twofaccount->id . " could not be splited"); } } + + $twofaccounts = DB::table('twofaccounts') + ->whereNull('account') + ->orWhereNull('otp_type') + ->orWhereNull('secret') + ->orWhereNull('algorithm') + ->orWhereNull('digits') + ->get(); + + foreach ($twofaccounts as $twofaccount) { + + $affected = DB::table('twofaccounts') + ->where('id', $twofaccount->id) + ->update([ + 'account' => $twofaccount->account === null ? 'account (invalid)' : $twofaccount->account + ' (invalid)', + 'otp_type' => $twofaccount->otp_type === null ? 'totp' : $twofaccount->otp_type, + 'secret' => $twofaccount->secret === null ? 'secret' : $twofaccount->secret, + 'algorithm' => $twofaccount->algorithm === null ? 'sha1' : $twofaccount->algorithm, + 'digits' => $twofaccount->digits === null ? 6 : $twofaccount->digits, + ]); + } + + Schema::table('twofaccounts', function (Blueprint $table) { + $table->text('account')->nullable(false)->change(); + $table->string('service')->nullable()->change(); + $table->string('otp_type', 10)->nullable(false)->change(); + $table->text('secret')->nullable(false)->change(); + $table->string('algorithm', 20)->nullable(false)->change(); + $table->unsignedSmallInteger('digits')->nullable(false)->change(); + }); } /**