Perbaikan modul data karyawan dan staff + modul SOP import
This commit is contained in:
@@ -22,11 +22,11 @@ class MigrateLmsData extends Command
|
||||
$this->migrateDepartmentPositions();
|
||||
|
||||
// 2. Eksekusi Data User
|
||||
$this->migrateStaffToUsers();
|
||||
$this->migrateStudentsToUsers();
|
||||
// $this->migrateStaffToUsers();
|
||||
// $this->migrateStudentsToUsers();
|
||||
|
||||
// 3. Sinkronisasi Departemen & Posisi ke User
|
||||
$this->syncUserDepartmentAndPosition();
|
||||
// $this->syncUserDepartmentAndPosition();
|
||||
|
||||
// 4. Eksekusi Ujian & Hasil
|
||||
$this->migrateQuestions();
|
||||
@@ -205,30 +205,79 @@ class MigrateLmsData extends Command
|
||||
/**
|
||||
* TAHAP 4A: Memindahkan data Bank Soal
|
||||
*/
|
||||
private function migrateQuestions()
|
||||
protected function migrateQuestions()
|
||||
{
|
||||
$this->warn('4A. Menarik data Bank Soal...');
|
||||
$oldQuestions = DB::connection('mysql_old')->table('questions')->get();
|
||||
$this->info('4A. Menarik data Bank Soal...');
|
||||
|
||||
// Pastikan Master Subject ditarik terlebih dahulu agar tidak ada yang terlewat
|
||||
$oldSubjects = DB::table('lmsv2-old.subjects')->get();
|
||||
foreach ($oldSubjects as $os) {
|
||||
\App\Models\Subject::updateOrCreate(
|
||||
['id' => $os->id],
|
||||
['name' => $os->name ?? $os->title ?? 'Materi ' . $os->id]
|
||||
);
|
||||
}
|
||||
|
||||
$oldQuestions = DB::table('lmsv2-old.questions')->get();
|
||||
|
||||
if ($oldQuestions->isEmpty()) {
|
||||
$this->warn('Tidak ada data soal ditemukan.');
|
||||
return;
|
||||
}
|
||||
|
||||
$bar = $this->output->createProgressBar(count($oldQuestions));
|
||||
$bar->start();
|
||||
|
||||
foreach ($oldQuestions as $q) {
|
||||
DB::table('question_banks')->updateOrInsert(
|
||||
['old_id' => $q->id],
|
||||
foreach ($oldQuestions as $old) {
|
||||
// Mapping Tipe
|
||||
$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'; }
|
||||
|
||||
// Mapping 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'; }
|
||||
|
||||
// Mapping ID (Departemen, Posisi, Subject, Creator)
|
||||
$deptId = (!empty($old->section_id) && $old->section_id != 0) ? $old->section_id : null;
|
||||
$posId = (!empty($old->class_id) && $old->class_id != 0) ? $old->class_id : null;
|
||||
$subjId = (!empty($old->subject_id) && $old->subject_id != 0) ? $old->subject_id : null;
|
||||
$creatorId = (!empty($old->staff_id) && $old->staff_id != 0) ? $old->staff_id : null;
|
||||
|
||||
$correctAnswer = !empty($old->correct) ? [$old->correct] : null;
|
||||
|
||||
// Menggunakan Model agar array di-cast otomatis menjadi format yang benar
|
||||
\App\Models\QuestionBank::updateOrCreate(
|
||||
['old_id' => $old->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,
|
||||
'department_id' => $deptId,
|
||||
'position_id' => $posId,
|
||||
'subject_id' => $subjId,
|
||||
'question_type' => $type,
|
||||
'question_level' => $level,
|
||||
'question_text' => $old->question,
|
||||
'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,
|
||||
'created_by' => $creatorId,
|
||||
'created_at' => $old->created_at ?? now(),
|
||||
'updated_at' => $old->updated_at ?? now(),
|
||||
]
|
||||
);
|
||||
|
||||
$bar->advance();
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
$this->info('Bank Soal berhasil ditarik!');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user