original_string: protected function migrateLesson($oldLesson)
      {
              if ($this->lessonNotExists($oldLesson)) {
                  DB::beginTransaction();
                try {
                      $lesson = new ScoolLesson;
                      $lesson->location_id = $this->translateLocationId($oldLesson->location_id);
                      $lesson->day_id = $this->translateDayId($oldLesson->day);
                      $lesson->timeslot_id = $this->translateTimeslotId($oldLesson->time_slot_id);
                      $lesson->state='Validated';
                      $lesson->save();
                      $lesson->addTeacher($this->translateTeacher($oldLesson->teacher_id));
                      $module = Module::findOrFail($this->translateModuleId($oldLesson->study_module_id));
                      foreach ($module->submodules as $submodule) {
                          $lesson->addSubmodule($submodule);
                      }
  
                      $classroom = Classroom::findOrFail($this->translateClassroomId($oldLesson->classroom_group_id));
                      $lesson->addClassroom($classroom);
  
                      $lesson_migration = new LessonMigration();
                      $lesson_migration->newlesson_id = $lesson->id;
                      $lesson_migration->lesson()->associate($oldLesson);
                      $lesson_migration->save();
                      DB::commit();
              } catch (\Exception $e) {
                  DB::rollBack();
                  $this->output->error(
                      'Error migrating lesson. ' . class_basename($e) . ' ' .  $e->getMessage());
                  return null;
              }
  
              }
      }
code: protected function migrateLesson($oldLesson)
      {
              if ($this->lessonNotExists($oldLesson)) {
                  DB::beginTransaction();
                try {
                      $lesson = new ScoolLesson;
                      $lesson->location_id = $this->translateLocationId($oldLesson->location_id);
                      $lesson->day_id = $this->translateDayId($oldLesson->day);
                      $lesson->timeslot_id = $this->translateTimeslotId($oldLesson->time_slot_id);
                      $lesson->state='Validated';
                      $lesson->save();
                      $lesson->addTeacher($this->translateTeacher($oldLesson->teacher_id));
                      $module = Module::findOrFail($this->translateModuleId($oldLesson->study_module_id));
                      foreach ($module->submodules as $submodule) {
                          $lesson->addSubmodule($submodule);
                      }
  
                      $classroom = Classroom::findOrFail($this->translateClassroomId($oldLesson->classroom_group_id));
                      $lesson->addClassroom($classroom);
  
                      $lesson_migration = new LessonMigration();
                      $lesson_migration->newlesson_id = $lesson->id;
                      $lesson_migration->lesson()->associate($oldLesson);
                      $lesson_migration->save();
                      DB::commit();
              } catch (\Exception $e) {
                  DB::rollBack();
                  $this->output->error(
                      'Error migrating lesson. ' . class_basename($e) . ' ' .  $e->getMessage());
                  return null;
              }
  
              }
      }
code_tokens: protected function migrateLesson ( $ oldLesson ) { if ( $ this -> lessonNotExists ( $ oldLesson ) ) { DB :: beginTransaction ( ) ; try { $ lesson = new ScoolLesson ; $ lesson -> location_id = $ this -> translateLocationId ( $ oldLesson -> location_id ) ; $ lesson -> day_id = $ this -> translateDayId ( $ oldLesson -> day ) ; $ lesson -> timeslot_id = $ this -> translateTimeslotId ( $ oldLesson -> time_slot_id ) ; $ lesson -> state = 'Validated' ; $ lesson -> save ( ) ; $ lesson -> addTeacher ( $ this -> translateTeacher ( $ oldLesson -> teacher_id ) ) ; $ module = Module :: findOrFail ( $ this -> translateModuleId ( $ oldLesson -> study_module_id ) ) ; foreach ( $ module -> submodules as $ submodule ) { $ lesson -> addSubmodule ( $ submodule ) ; } $ classroom = Classroom :: findOrFail ( $ this -> translateClassroomId ( $ oldLesson -> classroom_group_id ) ) ; $ lesson -> addClassroom ( $ classroom ) ; $ lesson_migration = new LessonMigration ( ) ; $ lesson_migration -> newlesson_id = $ lesson -> id ; $ lesson_migration -> lesson ( ) -> associate ( $ oldLesson ) ; $ lesson_migration -> save ( ) ; DB :: commit ( ) ; } catch ( \ Exception $ e ) { DB :: rollBack ( ) ; $ this -> output -> error ( 'Error migrating lesson. ' . class_basename ( $ e ) . ' ' . $ e -> getMessage ( ) ) ; return null ; } } }
docstring: Migrate lesson.
docstring_tokens: Migrate lesson .