2022-07-07 16:39:57 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands\Utils;
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
|
|
trait ResetTrait
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Reset icons
|
|
|
|
*/
|
2022-09-07 17:54:27 +02:00
|
|
|
protected function resetIcons() : void
|
2022-07-07 16:39:57 +02:00
|
|
|
{
|
|
|
|
$this->deleteIcons();
|
|
|
|
$this->generateIcons();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete all icons
|
|
|
|
*/
|
2022-09-07 17:54:27 +02:00
|
|
|
protected function deleteIcons() : void
|
2022-07-07 16:39:57 +02:00
|
|
|
{
|
|
|
|
$filesForDelete = \Illuminate\Support\Facades\File::glob('public/icons/*.png');
|
|
|
|
Storage::delete($filesForDelete);
|
|
|
|
|
|
|
|
$this->line('Existing icons deleted');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate icons for seeded accounts
|
|
|
|
*/
|
2022-09-07 17:54:27 +02:00
|
|
|
protected function generateIcons() : void
|
2022-07-07 16:39:57 +02:00
|
|
|
{
|
|
|
|
IconGenerator::generateIcon('amazon', IconGenerator::AMAZON);
|
|
|
|
IconGenerator::generateIcon('apple', IconGenerator::APPLE);
|
|
|
|
IconGenerator::generateIcon('dropbox', IconGenerator::DROPBOX);
|
|
|
|
IconGenerator::generateIcon('facebook', IconGenerator::FACEBOOK);
|
|
|
|
IconGenerator::generateIcon('github', IconGenerator::GITHUB);
|
|
|
|
IconGenerator::generateIcon('google', IconGenerator::GOOGLE);
|
|
|
|
IconGenerator::generateIcon('instagram', IconGenerator::INSTAGRAM);
|
|
|
|
IconGenerator::generateIcon('linkedin', IconGenerator::LINKEDIN);
|
|
|
|
IconGenerator::generateIcon('twitter', IconGenerator::TWITTER);
|
|
|
|
|
|
|
|
$this->line('Icons regenerated');
|
|
|
|
}
|
2022-11-22 15:15:52 +01:00
|
|
|
|
2022-07-07 16:39:57 +02:00
|
|
|
/**
|
|
|
|
* Reset DB
|
|
|
|
*/
|
2022-09-07 17:54:27 +02:00
|
|
|
protected function resetDB(string $seeder) : void
|
2022-07-07 16:39:57 +02:00
|
|
|
{
|
|
|
|
$this->flushDB();
|
|
|
|
$this->seedDB($seeder);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete all DB tables
|
|
|
|
*/
|
2022-09-07 17:54:27 +02:00
|
|
|
protected function flushDB() : void
|
2022-07-07 16:39:57 +02:00
|
|
|
{
|
|
|
|
// Reset the db
|
2024-01-26 18:16:55 +01:00
|
|
|
DB::table(config('auth.passwords.users.table'))->delete();
|
2022-07-07 16:39:57 +02:00
|
|
|
DB::table('oauth_access_tokens')->delete();
|
|
|
|
DB::table('oauth_personal_access_clients')->delete();
|
|
|
|
DB::table('oauth_refresh_tokens')->delete();
|
2022-11-14 17:13:24 +01:00
|
|
|
DB::table('webauthn_credentials')->delete();
|
2024-01-26 18:16:55 +01:00
|
|
|
DB::table(config('auth.passwords.webauthn.table'))->delete();
|
2022-07-07 16:39:57 +02:00
|
|
|
DB::table('twofaccounts')->delete();
|
|
|
|
DB::table('groups')->delete();
|
2023-02-25 22:29:55 +01:00
|
|
|
DB::table('users')->delete();
|
|
|
|
DB::table('options')->delete();
|
2024-04-23 16:28:42 +02:00
|
|
|
DB::table('auth_logs')->delete();
|
2022-07-07 16:39:57 +02:00
|
|
|
|
|
|
|
$this->line('Database cleaned');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Seed the DB
|
|
|
|
*/
|
2022-09-07 17:54:27 +02:00
|
|
|
protected function seedDB(string $seeder) : void
|
2022-07-07 16:39:57 +02:00
|
|
|
{
|
|
|
|
$this->callSilent('db:seed', [
|
2022-11-22 15:15:52 +01:00
|
|
|
'--class' => $seeder,
|
2024-06-26 14:14:45 +02:00
|
|
|
'--no-interaction' => 1
|
2022-07-07 16:39:57 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->line('Database seeded');
|
|
|
|
}
|
|
|
|
}
|