original_string: public static function publish_course($courseinfo, $files) {
          global $DB;
  
          // Register course and get id of the course on moodle.net ($hubcourseid).
          $courseid = $courseinfo->sitecourseid;
          try {
              $hubcourseid = api::register_course($courseinfo);
          } catch (Exception $e) {
              throw new moodle_exception('errorcoursepublish', 'hub',
                  new moodle_url('/course/view.php', array('id' => $courseid)), $e->getMessage());
          }
  
          // Insert/update publication record in the local DB.
          $publication = $DB->get_record('course_published', array('hubcourseid' => $hubcourseid, 'huburl' => HUB_MOODLEORGHUBURL));
  
          if ($publication) {
              $DB->update_record('course_published', ['id' => $publication->id, 'timepublished' => time()]);
          } else {
              $publication = new stdClass();
              $publication->huburl = HUB_MOODLEORGHUBURL;
              $publication->courseid = $courseid;
              $publication->hubcourseid = $hubcourseid;
              $publication->enrollable = (int)$courseinfo->enrollable;
              $publication->timepublished = time();
              $publication->id = $DB->insert_record('course_published', $publication);
          }
  
          // Send screenshots.
          if ($files) {
              $screenshotnumber = $courseinfo->screenshots - count($files);
              foreach ($files as $file) {
                  $screenshotnumber++;
                  api::add_screenshot($hubcourseid, $file, $screenshotnumber);
              }
          }
  
          return $hubcourseid;
      }
code: public static function publish_course($courseinfo, $files) {
          global $DB;
  
          // Register course and get id of the course on moodle.net ($hubcourseid).
          $courseid = $courseinfo->sitecourseid;
          try {
              $hubcourseid = api::register_course($courseinfo);
          } catch (Exception $e) {
              throw new moodle_exception('errorcoursepublish', 'hub',
                  new moodle_url('/course/view.php', array('id' => $courseid)), $e->getMessage());
          }
  
          // Insert/update publication record in the local DB.
          $publication = $DB->get_record('course_published', array('hubcourseid' => $hubcourseid, 'huburl' => HUB_MOODLEORGHUBURL));
  
          if ($publication) {
              $DB->update_record('course_published', ['id' => $publication->id, 'timepublished' => time()]);
          } else {
              $publication = new stdClass();
              $publication->huburl = HUB_MOODLEORGHUBURL;
              $publication->courseid = $courseid;
              $publication->hubcourseid = $hubcourseid;
              $publication->enrollable = (int)$courseinfo->enrollable;
              $publication->timepublished = time();
              $publication->id = $DB->insert_record('course_published', $publication);
          }
  
          // Send screenshots.
          if ($files) {
              $screenshotnumber = $courseinfo->screenshots - count($files);
              foreach ($files as $file) {
                  $screenshotnumber++;
                  api::add_screenshot($hubcourseid, $file, $screenshotnumber);
              }
          }
  
          return $hubcourseid;
      }
code_tokens: public static function publish_course ( $ courseinfo , $ files ) { global $ DB ; // Register course and get id of the course on moodle.net ($hubcourseid). $ courseid = $ courseinfo -> sitecourseid ; try { $ hubcourseid = api :: register_course ( $ courseinfo ) ; } catch ( Exception $ e ) { throw new moodle_exception ( 'errorcoursepublish' , 'hub' , new moodle_url ( '/course/view.php' , array ( 'id' => $ courseid ) ) , $ e -> getMessage ( ) ) ; } // Insert/update publication record in the local DB. $ publication = $ DB -> get_record ( 'course_published' , array ( 'hubcourseid' => $ hubcourseid , 'huburl' => HUB_MOODLEORGHUBURL ) ) ; if ( $ publication ) { $ DB -> update_record ( 'course_published' , [ 'id' => $ publication -> id , 'timepublished' => time ( ) ] ) ; } else { $ publication = new stdClass ( ) ; $ publication -> huburl = HUB_MOODLEORGHUBURL ; $ publication -> courseid = $ courseid ; $ publication -> hubcourseid = $ hubcourseid ; $ publication -> enrollable = ( int ) $ courseinfo -> enrollable ; $ publication -> timepublished = time ( ) ; $ publication -> id = $ DB -> insert_record ( 'course_published' , $ publication ) ; } // Send screenshots. if ( $ files ) { $ screenshotnumber = $ courseinfo -> screenshots - count ( $ files ) ; foreach ( $ files as $ file ) { $ screenshotnumber ++ ; api :: add_screenshot ( $ hubcourseid , $ file , $ screenshotnumber ) ; } } return $ hubcourseid ; }
docstring: Publish a course
  
  @param \stdClass $courseinfo
  @param \stored_file[] $files
docstring_tokens: Publish a course