mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-12-26 17:09:11 +01:00
Move some schema changes to next migration to fix travis
This commit is contained in:
parent
9ed037412f
commit
d40bcad1fe
@ -16,8 +16,6 @@ class SplitTwofaccountsUriInMultipleColumns extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
$driver = Schema::connection($this->getConnection())->getConnection()->getDriverName();
|
|
||||||
|
|
||||||
// as SQLITE disallow to add a not nullable column without default
|
// as SQLITE disallow to add a not nullable column without default
|
||||||
// value when altering a table we add all columns as nullable and
|
// value when altering a table we add all columns as nullable and
|
||||||
// change them right after to not nullable column
|
// change them right after to not nullable column
|
||||||
@ -30,54 +28,9 @@ public function up()
|
|||||||
$table->unsignedBigInteger('counter')->nullable();
|
$table->unsignedBigInteger('counter')->nullable();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Schema::table('twofaccounts', function (Blueprint $table){
|
|
||||||
// $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();
|
|
||||||
// });
|
|
||||||
|
|
||||||
// Apply previous migration 'AlterEncryptedColumnsToText' even to sqlite base
|
|
||||||
if ('sqlite' === $driver) {
|
|
||||||
|
|
||||||
Schema::table('twofaccounts', function (Blueprint $table) {
|
|
||||||
$table->text('account')->change();
|
|
||||||
});
|
|
||||||
|
|
||||||
Schema::table('twofaccounts', function (Blueprint $table) {
|
|
||||||
$table->text('uri')->change();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Schema::table('twofaccounts', function (Blueprint $table) {
|
Schema::table('twofaccounts', function (Blueprint $table) {
|
||||||
$table->renameColumn('uri', 'legacy_uri');
|
$table->renameColumn('uri', 'legacy_uri');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$twofaccounts = DB::table('twofaccounts')->select('id', 'legacy_uri')->get();
|
|
||||||
$settingService = resolve('App\Services\SettingService');
|
|
||||||
|
|
||||||
foreach ($twofaccounts as $twofaccount) {
|
|
||||||
try {
|
|
||||||
$legacy_uri = $settingService->get('useEncryption') ? Crypt::decryptString($twofaccount->legacy_uri) : $twofaccount->legacy_uri;
|
|
||||||
$token = \OTPHP\Factory::loadFromProvisioningUri($legacy_uri);
|
|
||||||
|
|
||||||
$affected = DB::table('twofaccounts')
|
|
||||||
->where('id', $twofaccount->id)
|
|
||||||
->update([
|
|
||||||
'otp_type' => get_class($token) === 'OTPHP\TOTP' ? 'totp' : 'hotp',
|
|
||||||
'secret' => $settingService->get('useEncryption') ? Crypt::encryptString($token->getSecret()) : $token->getSecret(),
|
|
||||||
'algorithm' => $token->getDigest(),
|
|
||||||
'digits' => $token->getDigits(),
|
|
||||||
'period' => $token->hasParameter('period') ? $token->getParameter('period') : null,
|
|
||||||
'counter' => $token->hasParameter('counter') ? $token->getParameter('counter') : null
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
catch(Exception $ex)
|
|
||||||
{
|
|
||||||
Log::error($ex->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Support\Facades\Crypt;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class ChangeAccountNotNullableTwofaccountsTable extends Migration
|
class ChangeAccountNotNullableTwofaccountsTable extends Migration
|
||||||
{
|
{
|
||||||
@ -13,10 +16,54 @@ class ChangeAccountNotNullableTwofaccountsTable extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
|
$driver = Schema::connection($this->getConnection())->getConnection()->getDriverName();
|
||||||
|
|
||||||
Schema::table('twofaccounts', function (Blueprint $table) {
|
Schema::table('twofaccounts', function (Blueprint $table) {
|
||||||
$table->text('account')->nullable(false)->change();
|
$table->text('account')->nullable(false)->change();
|
||||||
$table->string('service')->nullable()->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();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Apply migration 'AlterEncryptedColumnsToText' even to sqlite base
|
||||||
|
if ('sqlite' === $driver) {
|
||||||
|
|
||||||
|
Schema::table('twofaccounts', function (Blueprint $table) {
|
||||||
|
$table->text('account')->change();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('twofaccounts', function (Blueprint $table) {
|
||||||
|
$table->text('legacy_uri')->change();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$twofaccounts = DB::table('twofaccounts')->select('id', 'legacy_uri')->get();
|
||||||
|
$settingService = resolve('App\Services\SettingService');
|
||||||
|
|
||||||
|
foreach ($twofaccounts as $twofaccount) {
|
||||||
|
try {
|
||||||
|
$legacy_uri = $settingService->get('useEncryption') ? Crypt::decryptString($twofaccount->legacy_uri) : $twofaccount->legacy_uri;
|
||||||
|
$token = \OTPHP\Factory::loadFromProvisioningUri($legacy_uri);
|
||||||
|
|
||||||
|
$affected = DB::table('twofaccounts')
|
||||||
|
->where('id', $twofaccount->id)
|
||||||
|
->update([
|
||||||
|
'otp_type' => get_class($token) === 'OTPHP\TOTP' ? 'totp' : 'hotp',
|
||||||
|
'secret' => $settingService->get('useEncryption') ? Crypt::encryptString($token->getSecret()) : $token->getSecret(),
|
||||||
|
'algorithm' => $token->getDigest(),
|
||||||
|
'digits' => $token->getDigits(),
|
||||||
|
'period' => $token->hasParameter('period') ? $token->getParameter('period') : null,
|
||||||
|
'counter' => $token->hasParameter('counter') ? $token->getParameter('counter') : null
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
catch(Exception $ex)
|
||||||
|
{
|
||||||
|
Log::error($ex->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user