Initial commit - lms-v2 + CLAUDE.md
This commit is contained in:
@@ -0,0 +1,311 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use App\Models\User;
|
||||
|
||||
class MigrateLmsData extends Command
|
||||
{
|
||||
protected $signature = 'lms:migrate-data';
|
||||
protected $description = 'Migrasi komprehensif: Master Data -> Users -> Sinkronisasi Jabatan -> Bank Soal -> History Test';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Memulai pemindahan data dari CI3 Lama ke Laravel 13 V2...');
|
||||
|
||||
// 1. Eksekusi Master Data Terlebih Dahulu
|
||||
$this->migrateDepartments();
|
||||
$this->migratePositions();
|
||||
$this->migrateDepartmentPositions();
|
||||
|
||||
// 2. Eksekusi Data User
|
||||
$this->migrateStaffToUsers();
|
||||
$this->migrateStudentsToUsers();
|
||||
|
||||
// 3. Sinkronisasi Departemen & Posisi ke User
|
||||
$this->syncUserDepartmentAndPosition();
|
||||
|
||||
// 4. Eksekusi Ujian & Hasil
|
||||
$this->migrateQuestions();
|
||||
$this->migrateExamHistory();
|
||||
|
||||
$this->info('Sukses! Semua data Master, Karyawan, Sinkronisasi Jabatan, Bank Soal, dan Histori Test berhasil dipindahkan.');
|
||||
}
|
||||
|
||||
/**
|
||||
* TAHAP 1A: Memindahkan data `sections` (Lama) ke `departments` (Baru)
|
||||
*/
|
||||
/**
|
||||
* TAHAP 1A: Memindahkan data `sections` (Lama) ke `departments` (Baru)
|
||||
*/
|
||||
private function migrateDepartments()
|
||||
{
|
||||
$this->warn('1A. Menarik data Departemen (Sections)...');
|
||||
|
||||
$oldSections = DB::table('lmsv2-old.sections')->get();
|
||||
$bar = $this->output->createProgressBar(count($oldSections));
|
||||
$bar->start();
|
||||
|
||||
foreach ($oldSections as $section) {
|
||||
// Generate kode otomatis untuk Departments karena kolom 'code' WAJIB ada
|
||||
$code = 'DPT-' . str_pad($section->id, 3, '0', STR_PAD_LEFT);
|
||||
|
||||
DB::table('lmsv2.departments')->updateOrInsert(
|
||||
['id' => $section->id],
|
||||
[
|
||||
'code' => $code, // Tabel ini punya kolom 'code'
|
||||
'name' => trim($section->section),
|
||||
'created_at' => $section->created_at ?? now(),
|
||||
'updated_at' => now(),
|
||||
]
|
||||
);
|
||||
$bar->advance();
|
||||
}
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* TAHAP 1B: Memindahkan data `classes` (Lama) ke `positions` (Baru)
|
||||
*/
|
||||
private function migratePositions()
|
||||
{
|
||||
$this->warn('1B. Menarik data Posisi/Jabatan (Classes)...');
|
||||
|
||||
$oldClasses = DB::table('lmsv2-old.classes')->get();
|
||||
$bar = $this->output->createProgressBar(count($oldClasses));
|
||||
$bar->start();
|
||||
|
||||
foreach ($oldClasses as $class) {
|
||||
DB::table('lmsv2.positions')->updateOrInsert(
|
||||
['id' => $class->id],
|
||||
[
|
||||
// Tabel ini HANYA punya id, name, created_at, updated_at
|
||||
// (Pastikan Anda sudah menjalankan Langkah 1 untuk menambah kolom 'name')
|
||||
'name' => trim($class->class),
|
||||
'created_at' => $class->created_at ?? now(),
|
||||
'updated_at' => now(),
|
||||
]
|
||||
);
|
||||
$bar->advance();
|
||||
}
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* TAHAP 2A: Memindahkan data `staff` (Trainer/Admin) ke tabel `users`
|
||||
*/
|
||||
private function migrateStaffToUsers()
|
||||
{
|
||||
$this->warn('2A. Menarik data Staff (Trainer/Admin)...');
|
||||
$oldStaffs = DB::connection('mysql_old')->table('staff')->get();
|
||||
$bar = $this->output->createProgressBar(count($oldStaffs));
|
||||
$bar->start();
|
||||
|
||||
foreach ($oldStaffs as $staff) {
|
||||
$email = !empty($staff->email) ? $staff->email : $staff->employee_id . '@tunggal-pharma.com';
|
||||
|
||||
$gender = null;
|
||||
if (strtolower($staff->gender) == 'male') $gender = 'L';
|
||||
if (strtolower($staff->gender) == 'female') $gender = 'P';
|
||||
|
||||
User::updateOrCreate(
|
||||
['email' => $email],
|
||||
[
|
||||
'nik' => $staff->employee_id,
|
||||
'first_name' => trim($staff->name),
|
||||
'last_name' => trim($staff->surname),
|
||||
'gender' => $gender,
|
||||
'phone' => $staff->contact_no,
|
||||
'password' => Hash::make('Tunggal123!'),
|
||||
'role' => 'trainer',
|
||||
'old_id' => $staff->id,
|
||||
'old_password_hash' => $staff->password,
|
||||
]
|
||||
);
|
||||
$bar->advance();
|
||||
}
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* TAHAP 2B: Memindahkan data `students` (Karyawan) ke tabel `users`
|
||||
*/
|
||||
private function migrateStudentsToUsers()
|
||||
{
|
||||
$this->warn('2B. Menarik data Karyawan (Students)...');
|
||||
$oldStudents = DB::connection('mysql_old')->table('students')->get();
|
||||
$bar = $this->output->createProgressBar(count($oldStudents));
|
||||
$bar->start();
|
||||
|
||||
foreach ($oldStudents as $student) {
|
||||
$email = !empty($student->email) ? $student->email : $student->admission_no . '@tunggal-pharma.com';
|
||||
|
||||
$gender = null;
|
||||
if (strtolower($student->gender) == 'male') $gender = 'L';
|
||||
if (strtolower($student->gender) == 'female') $gender = 'P';
|
||||
|
||||
User::updateOrCreate(
|
||||
['email' => $email],
|
||||
[
|
||||
'nik' => $student->admission_no,
|
||||
'first_name' => trim($student->firstname),
|
||||
'last_name' => trim($student->lastname),
|
||||
'gender' => $gender,
|
||||
'phone' => $student->mobileno,
|
||||
'date_of_birth' => $student->dob,
|
||||
'password' => Hash::make('Karyawan123!'),
|
||||
'role' => 'karyawan',
|
||||
'old_id' => $student->id,
|
||||
]
|
||||
);
|
||||
$bar->advance();
|
||||
}
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* TAHAP 3: MENGHUBUNGKAN USER DENGAN DEPARTEMEN & POSISI
|
||||
*/
|
||||
private function syncUserDepartmentAndPosition()
|
||||
{
|
||||
$this->warn('3. Menyinkronkan Karyawan dengan Departemen & Posisi...');
|
||||
|
||||
// Membaca relasi dari tabel student_session di DB lama
|
||||
$oldSessions = DB::connection('mysql_old')->table('student_session')->get();
|
||||
$bar = $this->output->createProgressBar(count($oldSessions));
|
||||
$bar->start();
|
||||
|
||||
foreach ($oldSessions as $session) {
|
||||
// Cari user di database baru berdasarkan old_id
|
||||
$user = User::where('old_id', $session->student_id)
|
||||
->where('role', 'karyawan')
|
||||
->first();
|
||||
|
||||
if ($user) {
|
||||
// Update jabatan dan departemen
|
||||
// Asumsi: ID Departemen dan Posisi sama dengan ID Sections dan Classes dari DB Lama
|
||||
$user->update([
|
||||
'position_id' => $session->class_id,
|
||||
'department_id' => $session->section_id,
|
||||
]);
|
||||
}
|
||||
$bar->advance();
|
||||
}
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* TAHAP 4A: Memindahkan data Bank Soal
|
||||
*/
|
||||
private function migrateQuestions()
|
||||
{
|
||||
$this->warn('4A. Menarik data Bank Soal...');
|
||||
$oldQuestions = DB::connection('mysql_old')->table('questions')->get();
|
||||
$bar = $this->output->createProgressBar(count($oldQuestions));
|
||||
$bar->start();
|
||||
|
||||
foreach ($oldQuestions as $q) {
|
||||
DB::table('question_banks')->updateOrInsert(
|
||||
['old_id' => $q->id],
|
||||
[
|
||||
'question_text' => $q->question,
|
||||
'option_a' => $q->opt_a,
|
||||
'option_b' => $q->opt_b,
|
||||
'option_c' => $q->opt_c,
|
||||
'option_d' => $q->opt_d,
|
||||
'option_e' => $q->opt_e,
|
||||
'correct_answer' => $q->correct,
|
||||
]
|
||||
);
|
||||
$bar->advance();
|
||||
}
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* TAHAP 4B: Memindahkan data Ujian & Hasil Historis Karyawan
|
||||
*/
|
||||
private function migrateExamHistory()
|
||||
{
|
||||
$this->warn('4B. Menarik data Historis Nilai Ujian...');
|
||||
|
||||
// Tarik Master Ujian
|
||||
$oldExams = DB::connection('mysql_old')->table('onlineexam')->get();
|
||||
foreach ($oldExams as $exam) {
|
||||
DB::table('exams')->updateOrInsert(
|
||||
['old_id' => $exam->id],
|
||||
[
|
||||
'title' => $exam->exam,
|
||||
'duration' => $exam->duration,
|
||||
'passing_percentage' => $exam->passing_percentage,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// Tarik Hasil Test Karyawan
|
||||
$oldResults = DB::connection('mysql_old')
|
||||
->table('onlineexam_students')
|
||||
->join('student_session', 'onlineexam_students.student_session_id', '=', 'student_session.id')
|
||||
->join('students', 'student_session.student_id', '=', 'students.id')
|
||||
->select('onlineexam_students.*', 'students.id as old_student_id')
|
||||
->get();
|
||||
|
||||
$bar = $this->output->createProgressBar(count($oldResults));
|
||||
$bar->start();
|
||||
|
||||
foreach ($oldResults as $result) {
|
||||
$user = DB::table('users')->where('old_id', $result->old_student_id)->where('role', 'karyawan')->first();
|
||||
$exam = DB::table('exams')->where('old_id', $result->onlineexam_id)->first();
|
||||
|
||||
if ($user && $exam) {
|
||||
DB::table('exam_results')->updateOrInsert(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'exam_id' => $exam->id
|
||||
],
|
||||
[
|
||||
'is_attempted' => $result->is_attempted,
|
||||
'created_at' => $result->created_at,
|
||||
]
|
||||
);
|
||||
}
|
||||
$bar->advance();
|
||||
}
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* TAHAP 1C: Memindahkan pemetaan class_sections (Lama) ke department_position (Baru)
|
||||
*/
|
||||
private function migrateDepartmentPositions()
|
||||
{
|
||||
$this->warn('1C. Menarik data Relasi Departemen & Posisi (Class Sections)...');
|
||||
|
||||
$oldRelations = \Illuminate\Support\Facades\DB::table('lmsv2-old.class_sections')->get();
|
||||
$bar = $this->output->createProgressBar(count($oldRelations));
|
||||
$bar->start();
|
||||
|
||||
foreach ($oldRelations as $relation) {
|
||||
// Asumsi kolom lama bernama section_id dan class_id
|
||||
\Illuminate\Support\Facades\DB::table('lmsv2.department_position')->updateOrInsert(
|
||||
[
|
||||
'department_id' => $relation->section_id,
|
||||
'position_id' => $relation->class_id,
|
||||
]
|
||||
);
|
||||
$bar->advance();
|
||||
}
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\QuestionBank;
|
||||
use App\Models\User;
|
||||
|
||||
class MigrateOldQuestions extends Command
|
||||
{
|
||||
protected $signature = 'lms:migrate-questions';
|
||||
protected $description = 'Menyalin data soal dari lmsv2-old.questions ke lmsv2.question_banks secara presisi';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Memulai Sinkronisasi Bank Soal dari Database Lama...');
|
||||
|
||||
$oldQuestions = DB::table('lmsv2-old.questions')->get();
|
||||
|
||||
if ($oldQuestions->isEmpty()) {
|
||||
$this->warn('Tidak ada data di tabel lmsv2-old.questions!');
|
||||
return;
|
||||
}
|
||||
|
||||
$bar = $this->output->createProgressBar(count($oldQuestions));
|
||||
$bar->start();
|
||||
|
||||
$successCount = 0;
|
||||
|
||||
foreach ($oldQuestions as $old) {
|
||||
|
||||
// 1. Pemetaan Tipe Soal
|
||||
$type = 'single';
|
||||
$oldType = strtolower($old->question_type ?? '');
|
||||
if (str_contains($oldType, 'multiple')) { $type = 'multiple'; }
|
||||
elseif (str_contains($oldType, 'true') || str_contains($oldType, 'boolean')) { $type = 'true_false'; }
|
||||
elseif (str_contains($oldType, 'desc') || str_contains($oldType, 'essay')) { $type = 'descriptive'; }
|
||||
|
||||
// 2. Pemetaan Level
|
||||
$level = 'sedang';
|
||||
$oldLevel = strtolower($old->level ?? '');
|
||||
if (str_contains($oldLevel, 'mudah') || str_contains($oldLevel, 'easy')) { $level = 'mudah'; }
|
||||
elseif (str_contains($oldLevel, 'sulit') || str_contains($oldLevel, 'hard')) { $level = 'sulit'; }
|
||||
|
||||
// 3. Pemetaan Pembuat (Creator)
|
||||
$creatorId = null;
|
||||
if (isset($old->staff_id)) {
|
||||
$oldStaff = DB::table('lmsv2-old.staff')->where('id', $old->staff_id)->first();
|
||||
if ($oldStaff && !empty($oldStaff->email)) {
|
||||
$user = User::where('email', $oldStaff->email)->first();
|
||||
if ($user) $creatorId = $user->id;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Penanganan Kunci Jawaban (Karena di Model di-cast sebagai Array)
|
||||
$correctAnswer = null;
|
||||
if (!empty($old->correct)) {
|
||||
// Dibungkus ke dalam array agar tidak error saat Laravel mencoba json_encode
|
||||
$correctAnswer = [$old->correct];
|
||||
}
|
||||
|
||||
// 5. Simpan menggunakan format nama kolom yang BARU
|
||||
QuestionBank::updateOrCreate(
|
||||
['old_id' => $old->id], // Pencocokan menggunakan old_id
|
||||
[
|
||||
'question_type' => $type,
|
||||
'question_level' => $level,
|
||||
'question_text' => $old->question,
|
||||
|
||||
// Opsi A sampai E
|
||||
'option_a' => $old->opt_a,
|
||||
'option_b' => $old->opt_b,
|
||||
'option_c' => $old->opt_c,
|
||||
'option_d' => $old->opt_d,
|
||||
'option_e' => $old->opt_e,
|
||||
|
||||
'correct_answer' => $correctAnswer, // Sudah dalam bentuk array
|
||||
|
||||
'created_by' => $creatorId,
|
||||
'created_at' => $old->created_at ?? now(),
|
||||
'updated_at' => $old->updated_at ?? now(),
|
||||
]
|
||||
);
|
||||
|
||||
$successCount++;
|
||||
$bar->advance();
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
$this->info("Sinkronisasi Selesai! Berhasil memindahkan {$successCount} Soal beserta kunci jawabannya.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\User;
|
||||
use Spatie\Permission\Models\Role; // Pastikan library Role dari Spatie dipanggil
|
||||
|
||||
class MigrateStaffToTrainer extends Command
|
||||
{
|
||||
protected $signature = 'lms:migrate-trainers';
|
||||
protected $description = 'Mencocokkan data staff lama dan menetapkannya sebagai Trainer & Trainee';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Memastikan Role (Hak Akses) tersedia di database...');
|
||||
|
||||
// Membuat role otomatis jika belum ada di tabel 'roles'
|
||||
Role::firstOrCreate(['name' => 'admin', 'guard_name' => 'web']);
|
||||
Role::firstOrCreate(['name' => 'trainer', 'guard_name' => 'web']);
|
||||
Role::firstOrCreate(['name' => 'trainee', 'guard_name' => 'web']);
|
||||
|
||||
$this->info('Memulai pencocokan data Staff (Trainer)...');
|
||||
|
||||
$oldStaffs = DB::table('lmsv2-old.staff')->get();
|
||||
$bar = $this->output->createProgressBar(count($oldStaffs));
|
||||
$bar->start();
|
||||
|
||||
$successCount = 0;
|
||||
|
||||
foreach ($oldStaffs as $staff) {
|
||||
$matchedUser = null;
|
||||
|
||||
// Prioritas 1: Pencocokan Email
|
||||
if (!empty($staff->email)) {
|
||||
$matchedUser = User::where('email', $staff->email)->first();
|
||||
}
|
||||
|
||||
// Prioritas 2: Pencocokan Nama
|
||||
if (!$matchedUser && !empty($staff->name)) {
|
||||
$matchedUser = User::where(DB::raw("CONCAT(first_name, ' ', COALESCE(last_name, ''))"), 'LIKE', "%{$staff->name}%")->first();
|
||||
}
|
||||
|
||||
// Jika ketemu, tetapkan role-nya
|
||||
if ($matchedUser) {
|
||||
// assignRole() kini dijamin aman karena role sudah dibuat di awal script
|
||||
$matchedUser->assignRole(['trainer', 'trainee']);
|
||||
$successCount++;
|
||||
}
|
||||
|
||||
$bar->advance();
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
$this->info("Selesai! {$successCount} karyawan berhasil diperbarui sebagai Trainer.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigrateUserInitials extends Command
|
||||
{
|
||||
protected $signature = 'lms:migrate-initials';
|
||||
protected $description = 'Migrasi kolom roll_no dari tabel student lama dengan pencocokan Email / Nama karyawan';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Memulai tarik data inisial (roll_no) dengan pencocokan pintar...');
|
||||
|
||||
// Ambil data student dari database lama yang memiliki roll_no
|
||||
$oldStudents = DB::table('lmsv2-old.students')->whereNotNull('roll_no')->get();
|
||||
|
||||
$bar = $this->output->createProgressBar(count($oldStudents));
|
||||
$bar->start();
|
||||
|
||||
$successCount = 0;
|
||||
$failCount = 0;
|
||||
|
||||
foreach ($oldStudents as $oldStudent) {
|
||||
// Ubah object ke array agar lebih aman saat mengecek keberadaan kolom (mencegah error jika kolom tidak ada)
|
||||
$old = (array) $oldStudent;
|
||||
|
||||
$matchedUser = null;
|
||||
|
||||
// PRIORITAS 1: Cocokkan berdasarkan Email (Paling Akurat)
|
||||
if (!empty($old['email'])) {
|
||||
$matchedUser = DB::table('lmsv2.users')->where('email', $old['email'])->first();
|
||||
}
|
||||
|
||||
// PRIORITAS 2: Jika email tidak cocok/kosong, cocokkan berdasarkan Nama
|
||||
if (!$matchedUser) {
|
||||
$query = DB::table('lmsv2.users');
|
||||
|
||||
// Cek apakah database lama menggunakan 'first_name' atau 'name' tunggal
|
||||
if (!empty($old['first_name'])) {
|
||||
$query->where('first_name', $old['first_name']);
|
||||
if (!empty($old['last_name'])) {
|
||||
$query->where('last_name', $old['last_name']);
|
||||
}
|
||||
} elseif (!empty($old['name'])) {
|
||||
// Jika DB lama hanya punya 1 kolom 'name'
|
||||
$query->where(DB::raw("CONCAT(first_name, ' ', COALESCE(last_name, ''))"), 'LIKE', "%{$old['name']}%");
|
||||
} else {
|
||||
// Tidak ada indikator nama yang bisa dicari
|
||||
$query->where('id', '<', 0); // Force empty result
|
||||
}
|
||||
|
||||
$matchedUser = $query->first();
|
||||
}
|
||||
|
||||
// JIKA KETEMU: Update tabel users yang baru
|
||||
if ($matchedUser) {
|
||||
DB::table('lmsv2.users')
|
||||
->where('id', $matchedUser->id) // Update berdasarkan ID baru yang ditemukan
|
||||
->update(['initial' => $old['roll_no']]);
|
||||
|
||||
$successCount++;
|
||||
} else {
|
||||
$failCount++;
|
||||
}
|
||||
|
||||
$bar->advance();
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
$this->info("Selesai! Berhasil memetakan: {$successCount} data. Tidak ditemukan: {$failCount} data.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigrateUserKtp extends Command
|
||||
{
|
||||
protected $signature = 'lms:migrate-ktp';
|
||||
protected $description = 'Migrasi data nomor KTP dari adhar_no atau note berdasarkan Email/Nama';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Memulai pemetaan Nomor KTP (Identity Number)...');
|
||||
|
||||
// Ambil dari database lama yang adhar_no ATAU note-nya ada isinya
|
||||
$oldStudents = DB::table('lmsv2-old.students')
|
||||
->where(function($query) {
|
||||
$query->whereNotNull('adhar_no')->where('adhar_no', '!=', '')
|
||||
->orWhereNotNull('note')->where('note', '!=', '');
|
||||
})->get();
|
||||
|
||||
$bar = $this->output->createProgressBar(count($oldStudents));
|
||||
$bar->start();
|
||||
|
||||
$successCount = 0;
|
||||
$failCount = 0;
|
||||
|
||||
foreach ($oldStudents as $oldStudent) {
|
||||
$old = (array) $oldStudent;
|
||||
|
||||
// Prioritaskan adhar_no, jika kosong gunakan note
|
||||
$ktpNumber = !empty($old['adhar_no']) ? $old['adhar_no'] : $old['note'];
|
||||
|
||||
$matchedUser = null;
|
||||
|
||||
// PRIORITAS 1: Pencocokan Email
|
||||
if (!empty($old['email'])) {
|
||||
$matchedUser = DB::table('lmsv2.users')->where('email', $old['email'])->first();
|
||||
}
|
||||
|
||||
// PRIORITAS 2: Pencocokan Nama
|
||||
if (!$matchedUser) {
|
||||
$query = DB::table('lmsv2.users');
|
||||
|
||||
if (!empty($old['first_name'])) {
|
||||
$query->where('first_name', $old['first_name']);
|
||||
if (!empty($old['last_name'])) {
|
||||
$query->where('last_name', $old['last_name']);
|
||||
}
|
||||
} elseif (!empty($old['name'])) {
|
||||
$query->where(DB::raw("CONCAT(first_name, ' ', COALESCE(last_name, ''))"), 'LIKE', "%{$old['name']}%");
|
||||
} else {
|
||||
$query->where('id', '<', 0); // Skip jika data nama rusak
|
||||
}
|
||||
|
||||
$matchedUser = $query->first();
|
||||
}
|
||||
|
||||
// JIKA KETEMU: Update kolom identity_number
|
||||
if ($matchedUser) {
|
||||
DB::table('lmsv2.users')
|
||||
->where('id', $matchedUser->id)
|
||||
->update(['identity_number' => $ktpNumber]);
|
||||
|
||||
$successCount++;
|
||||
} else {
|
||||
$failCount++;
|
||||
}
|
||||
|
||||
$bar->advance();
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
$this->info("Pembaruan KTP Selesai! Berhasil terpetakan: {$successCount} data. Tidak ditemukan (Nama/Email beda): {$failCount} data.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user