/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); if (Exam::count()) { return; } $tests = DB::connection('old')->table('tests')->where('test_id', '>', 6)->WhereIn('test_type', [1, 2, 3, 11, 21])->get(); DB::statement('SET FOREIGN_KEY_CHECKS = 0'); Exam::truncate(); ExamQuestion::truncate(); $exam_type = [1 => 'midterm', 2 => 'final', 3 => 'summer', 11 => 'remidterm', 21 => 'refinal']; $all_test = []; $all_test_q = []; foreach ($tests as $test) { $exams = []; $exams['id'] = $test->test_id; $exams['name'] = $test->test_title; $exams['subject_id'] = $test->test_subjectid; $exams['type'] = $exam_type[$test->test_type]; $exams['semester_id'] = $test->test_semid; $exams['active'] = 1; $exams['start_at'] = date('Y-m-d H:i:s', $test->test_starttime); $exams['finish_at'] = date('Y-m-d H:i:s', $test->test_endtime); $exams['created_at'] = $test->test_created; $exams['updated_at'] = $test->test_modified; $all_test[] = $exams; foreach (explode(',', $test->test_question_ids) as $q_id) { $test_q = []; $test_q['question_id'] = $q_id; $test_q['exam_id'] = $test->test_id; $all_test_q[] = $test_q; } } foreach (array_chunk($all_test, 500) as $exam_group) { DB::table('exams')->insert($exam_group); } foreach (array_chunk($all_test_q, 500) as $test_q_group) { DB::table('exam_questions')->insert($test_q_group); } $this->command->info('table tests successfully transferd'); }