original_string: protected function update_course($course, $externalcourse, progress_trace $trace) {
          global $CFG, $DB;
  
          $coursefields = array ('shortname', 'fullname', 'summary');
          static $shouldupdate;
  
          // Initialize $shouldupdate variable. Set to true if one or more fields are marked for update.
          if (!isset($shouldupdate)) {
              $shouldupdate = false;
              foreach ($coursefields as $field) {
                  $shouldupdate = $shouldupdate || $this->get_config('course_'.$field.'_updateonsync');
              }
          }
  
          // If we should not update return immediately.
          if (!$shouldupdate) {
              return false;
          }
  
          require_once("$CFG->dirroot/course/lib.php");
          $courseupdated = false;
          $updatedcourse = new stdClass();
          $updatedcourse->id = $course->id;
  
          // Update course fields if necessary.
          foreach ($coursefields as $field) {
              // If field is marked to be updated on sync && field data was changed update it.
              if ($this->get_config('course_'.$field.'_updateonsync')
                      && isset($externalcourse[$this->get_config('course_'.$field)][0])
                      && $course->{$field} != $externalcourse[$this->get_config('course_'.$field)][0]) {
                  $updatedcourse->{$field} = $externalcourse[$this->get_config('course_'.$field)][0];
                  $courseupdated = true;
              }
          }
  
          if (!$courseupdated) {
              $trace->output(get_string('courseupdateskipped', 'enrol_ldap', $course));
              return false;
          }
  
          // Do not allow empty fullname or shortname.
          if ((isset($updatedcourse->fullname) && empty($updatedcourse->fullname))
                  || (isset($updatedcourse->shortname) && empty($updatedcourse->shortname))) {
              // We are in trouble!
              $trace->output(get_string('cannotupdatecourse', 'enrol_ldap', $course));
              return false;
          }
  
          // Check if the shortname already exists if it does - skip course updating.
          if (isset($updatedcourse->shortname)
                  && $DB->record_exists('course', array('shortname' => $updatedcourse->shortname))) {
              $trace->output(get_string('cannotupdatecourse_duplicateshortname', 'enrol_ldap', $course));
              return false;
          }
  
          // Finally - update course in DB.
          update_course($updatedcourse);
          $trace->output(get_string('courseupdated', 'enrol_ldap', $course));
  
          return true;
      }
code: protected function update_course($course, $externalcourse, progress_trace $trace) {
          global $CFG, $DB;
  
          $coursefields = array ('shortname', 'fullname', 'summary');
          static $shouldupdate;
  
          // Initialize $shouldupdate variable. Set to true if one or more fields are marked for update.
          if (!isset($shouldupdate)) {
              $shouldupdate = false;
              foreach ($coursefields as $field) {
                  $shouldupdate = $shouldupdate || $this->get_config('course_'.$field.'_updateonsync');
              }
          }
  
          // If we should not update return immediately.
          if (!$shouldupdate) {
              return false;
          }
  
          require_once("$CFG->dirroot/course/lib.php");
          $courseupdated = false;
          $updatedcourse = new stdClass();
          $updatedcourse->id = $course->id;
  
          // Update course fields if necessary.
          foreach ($coursefields as $field) {
              // If field is marked to be updated on sync && field data was changed update it.
              if ($this->get_config('course_'.$field.'_updateonsync')
                      && isset($externalcourse[$this->get_config('course_'.$field)][0])
                      && $course->{$field} != $externalcourse[$this->get_config('course_'.$field)][0]) {
                  $updatedcourse->{$field} = $externalcourse[$this->get_config('course_'.$field)][0];
                  $courseupdated = true;
              }
          }
  
          if (!$courseupdated) {
              $trace->output(get_string('courseupdateskipped', 'enrol_ldap', $course));
              return false;
          }
  
          // Do not allow empty fullname or shortname.
          if ((isset($updatedcourse->fullname) && empty($updatedcourse->fullname))
                  || (isset($updatedcourse->shortname) && empty($updatedcourse->shortname))) {
              // We are in trouble!
              $trace->output(get_string('cannotupdatecourse', 'enrol_ldap', $course));
              return false;
          }
  
          // Check if the shortname already exists if it does - skip course updating.
          if (isset($updatedcourse->shortname)
                  && $DB->record_exists('course', array('shortname' => $updatedcourse->shortname))) {
              $trace->output(get_string('cannotupdatecourse_duplicateshortname', 'enrol_ldap', $course));
              return false;
          }
  
          // Finally - update course in DB.
          update_course($updatedcourse);
          $trace->output(get_string('courseupdated', 'enrol_ldap', $course));
  
          return true;
      }
code_tokens: protected function update_course ( $ course , $ externalcourse , progress_trace $ trace ) { global $ CFG , $ DB ; $ coursefields = array ( 'shortname' , 'fullname' , 'summary' ) ; static $ shouldupdate ; // Initialize $shouldupdate variable. Set to true if one or more fields are marked for update. if ( ! isset ( $ shouldupdate ) ) { $ shouldupdate = false ; foreach ( $ coursefields as $ field ) { $ shouldupdate = $ shouldupdate || $ this -> get_config ( 'course_' . $ field . '_updateonsync' ) ; } } // If we should not update return immediately. if ( ! $ shouldupdate ) { return false ; } require_once ( "$CFG->dirroot/course/lib.php" ) ; $ courseupdated = false ; $ updatedcourse = new stdClass ( ) ; $ updatedcourse -> id = $ course -> id ; // Update course fields if necessary. foreach ( $ coursefields as $ field ) { // If field is marked to be updated on sync && field data was changed update it. if ( $ this -> get_config ( 'course_' . $ field . '_updateonsync' ) && isset ( $ externalcourse [ $ this -> get_config ( 'course_' . $ field ) ] [ 0 ] ) && $ course -> { $ field } != $ externalcourse [ $ this -> get_config ( 'course_' . $ field ) ] [ 0 ] ) { $ updatedcourse -> { $ field } = $ externalcourse [ $ this -> get_config ( 'course_' . $ field ) ] [ 0 ] ; $ courseupdated = true ; } } if ( ! $ courseupdated ) { $ trace -> output ( get_string ( 'courseupdateskipped' , 'enrol_ldap' , $ course ) ) ; return false ; } // Do not allow empty fullname or shortname. if ( ( isset ( $ updatedcourse -> fullname ) && empty ( $ updatedcourse -> fullname ) ) || ( isset ( $ updatedcourse -> shortname ) && empty ( $ updatedcourse -> shortname ) ) ) { // We are in trouble! $ trace -> output ( get_string ( 'cannotupdatecourse' , 'enrol_ldap' , $ course ) ) ; return false ; } // Check if the shortname already exists if it does - skip course updating. if ( isset ( $ updatedcourse -> shortname ) && $ DB -> record_exists ( 'course' , array ( 'shortname' => $ updatedcourse -> shortname ) ) ) { $ trace -> output ( get_string ( 'cannotupdatecourse_duplicateshortname' , 'enrol_ldap' , $ course ) ) ; return false ; } // Finally - update course in DB. update_course ( $ updatedcourse ) ; $ trace -> output ( get_string ( 'courseupdated' , 'enrol_ldap' , $ course ) ) ; return true ; }
docstring: Will update a moodle course with new values from LDAP
  A field will be updated only if it is marked to be updated
  on sync in plugin settings
  
  @param object $course
  @param array $externalcourse
  @param progress_trace $trace
  @return bool
docstring_tokens: Will update a moodle course with new values from LDAP A field will be updated only if it is marked to be updated on sync in plugin settings