- Adjusted indentation in ActivityLogModule methods for consistency. - Simplified ActivityLogRepository class by removing unnecessary lines. - Updated FillJsonData seeder to streamline the run method. - Modified various Migrator classes to change JSON data paths for testing and added sequence reset statements for better database integrity.
57 lines
1.9 KiB
PHP
57 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders\Migrators;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
class UsersMigrator
|
|
{
|
|
public function migrate(): void
|
|
{
|
|
DB::table('users')->truncate();
|
|
|
|
$path = database_path('data/nurmuhammetsdb/users.json');
|
|
|
|
$data = File::json($path);
|
|
|
|
foreach ($data as $user) {
|
|
DB::table('users')
|
|
->insert([
|
|
'id' => $user['id'],
|
|
'name' => $user['name'],
|
|
'email' => $user['email'],
|
|
'email_verified_at' => $user['email_verified_at'],
|
|
'password' => $user['password'],
|
|
'remember_token' => $user['remember_token'],
|
|
'created_at' => $user['created_at'],
|
|
'updated_at' => $user['updated_at'],
|
|
'username' => $user['username'],
|
|
'first_name' => $this->extractFirstName($user['name']),
|
|
'last_name' => $this->extractLastName($user['name']),
|
|
'phone' => $user['phone'],
|
|
'phone_verified_at' => $user['phone_verified_at'],
|
|
'locale' => $user['locale'],
|
|
'password_must_be_changed' => $user['password_must_be_changed'],
|
|
'options' => $user['options'],
|
|
'must_fill_profile' => false,
|
|
'custom_fields' => null,
|
|
'active' => $user['active'],
|
|
]);
|
|
}
|
|
|
|
DB::statement("SELECT setval('users_id_seq', (SELECT MAX(id) from users));");
|
|
DB::statement("SELECT nextval('users_id_seq');");
|
|
}
|
|
|
|
protected function extractFirstName(string $name): string
|
|
{
|
|
return explode(' ', $name)[0] ?? '';
|
|
}
|
|
|
|
protected function extractLastName(string $name): string
|
|
{
|
|
return explode(' ', $name)[1] ?? '';
|
|
}
|
|
}
|