original_string: private function duplicate_course_module(stdClass $cm, $moduleid, $newinstanceid) {
          global $DB, $CFG;
  
          $newcm = new stdClass();
          $newcm->course           = $cm->course;
          $newcm->module           = $moduleid;
          $newcm->instance         = $newinstanceid;
          $newcm->visible          = $cm->visible;
          $newcm->section          = $cm->section;
          $newcm->score            = $cm->score;
          $newcm->indent           = $cm->indent;
          $newcm->groupmode        = $cm->groupmode;
          $newcm->groupingid       = $cm->groupingid;
          $newcm->completion                = $cm->completion;
          $newcm->completiongradeitemnumber = $cm->completiongradeitemnumber;
          $newcm->completionview            = $cm->completionview;
          $newcm->completionexpected        = $cm->completionexpected;
          if (!empty($CFG->enableavailability)) {
              $newcm->availability = $cm->availability;
          }
          $newcm->showdescription = $cm->showdescription;
  
          $newcmid = add_course_module($newcm);
          $newcm = get_coursemodule_from_id('', $newcmid, $cm->course);
          if (!$newcm) {
              return false;
          }
          $section = $DB->get_record("course_sections", array("id"=>$newcm->section));
          if (!$section) {
              return false;
          }
  
          $newcm->section = course_add_cm_to_section($newcm->course, $newcm->id, $section->section, $cm->id);
  
          // Make sure visibility is set correctly (in particular in calendar).
          // Note: Allow them to set it even without moodle/course:activityvisibility.
          set_coursemodule_visible($newcm->id, $newcm->visible);
  
          return $newcm;
      }
code: private function duplicate_course_module(stdClass $cm, $moduleid, $newinstanceid) {
          global $DB, $CFG;
  
          $newcm = new stdClass();
          $newcm->course           = $cm->course;
          $newcm->module           = $moduleid;
          $newcm->instance         = $newinstanceid;
          $newcm->visible          = $cm->visible;
          $newcm->section          = $cm->section;
          $newcm->score            = $cm->score;
          $newcm->indent           = $cm->indent;
          $newcm->groupmode        = $cm->groupmode;
          $newcm->groupingid       = $cm->groupingid;
          $newcm->completion                = $cm->completion;
          $newcm->completiongradeitemnumber = $cm->completiongradeitemnumber;
          $newcm->completionview            = $cm->completionview;
          $newcm->completionexpected        = $cm->completionexpected;
          if (!empty($CFG->enableavailability)) {
              $newcm->availability = $cm->availability;
          }
          $newcm->showdescription = $cm->showdescription;
  
          $newcmid = add_course_module($newcm);
          $newcm = get_coursemodule_from_id('', $newcmid, $cm->course);
          if (!$newcm) {
              return false;
          }
          $section = $DB->get_record("course_sections", array("id"=>$newcm->section));
          if (!$section) {
              return false;
          }
  
          $newcm->section = course_add_cm_to_section($newcm->course, $newcm->id, $section->section, $cm->id);
  
          // Make sure visibility is set correctly (in particular in calendar).
          // Note: Allow them to set it even without moodle/course:activityvisibility.
          set_coursemodule_visible($newcm->id, $newcm->visible);
  
          return $newcm;
      }
code_tokens: private function duplicate_course_module ( stdClass $ cm , $ moduleid , $ newinstanceid ) { global $ DB , $ CFG ; $ newcm = new stdClass ( ) ; $ newcm -> course = $ cm -> course ; $ newcm -> module = $ moduleid ; $ newcm -> instance = $ newinstanceid ; $ newcm -> visible = $ cm -> visible ; $ newcm -> section = $ cm -> section ; $ newcm -> score = $ cm -> score ; $ newcm -> indent = $ cm -> indent ; $ newcm -> groupmode = $ cm -> groupmode ; $ newcm -> groupingid = $ cm -> groupingid ; $ newcm -> completion = $ cm -> completion ; $ newcm -> completiongradeitemnumber = $ cm -> completiongradeitemnumber ; $ newcm -> completionview = $ cm -> completionview ; $ newcm -> completionexpected = $ cm -> completionexpected ; if ( ! empty ( $ CFG -> enableavailability ) ) { $ newcm -> availability = $ cm -> availability ; } $ newcm -> showdescription = $ cm -> showdescription ; $ newcmid = add_course_module ( $ newcm ) ; $ newcm = get_coursemodule_from_id ( '' , $ newcmid , $ cm -> course ) ; if ( ! $ newcm ) { return false ; } $ section = $ DB -> get_record ( "course_sections" , array ( "id" => $ newcm -> section ) ) ; if ( ! $ section ) { return false ; } $ newcm -> section = course_add_cm_to_section ( $ newcm -> course , $ newcm -> id , $ section -> section , $ cm -> id ) ; // Make sure visibility is set correctly (in particular in calendar). // Note: Allow them to set it even without moodle/course:activityvisibility. set_coursemodule_visible ( $ newcm -> id , $ newcm -> visible ) ; return $ newcm ; }
docstring: Create a duplicate course module record so we can create the upgraded
  assign module alongside the old assignment module.
  
  @param stdClass $cm The old course module record
  @param int $moduleid The id of the new assign module
  @param int $newinstanceid The id of the new instance of the assign module
  @return mixed stdClass|bool The new course module record or FALSE
docstring_tokens: Create a duplicate course module record so we can create the upgraded assign module alongside the old assignment module .