Merge branch 'MDL-18375_master' of git://github.com/markn86/moodle
authorDamyon Wiese <damyon@moodle.com>
Mon, 9 Sep 2013 02:41:12 +0000 (10:41 +0800)
committerDamyon Wiese <damyon@moodle.com>
Mon, 9 Sep 2013 02:41:12 +0000 (10:41 +0800)
1  2 
course/edit_form.php
lib/classes/component.php
version.php

diff --combined course/edit_form.php
@@@ -6,12 -6,18 +6,18 @@@ require_once($CFG->libdir.'/formslib.ph
  require_once($CFG->libdir.'/completionlib.php');
  require_once($CFG->libdir. '/coursecatlib.php');
  
+ /**
+  * The form for handling editing a course.
+  */
  class course_edit_form extends moodleform {
      protected $course;
      protected $context;
  
+     /**
+      * Form definition.
+      */
      function definition() {
-         global $USER, $CFG, $DB, $PAGE;
+         global $CFG, $PAGE;
  
          $mform    = $this->_form;
          $PAGE->requires->yui_module('moodle-course-formatchooser', 'M.course.init_formatchooser',
@@@ -38,8 -44,7 +44,7 @@@
          $this->course  = $course;
          $this->context = $context;
  
- /// form definition with new course defaults
- //--------------------------------------------------------------------------------
+         // Form definition with new course defaults.
          $mform->addElement('header','general', get_string('general', 'form'));
  
          $mform->addElement('hidden', 'returnto', null);
          $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);
          $mform->setDefault('lang', $courseconfig->lang);
  
+         // Multi-Calendar Support - see MDL-18375.
+         $calendartypes = \core_calendar\type_factory::get_list_of_calendar_types();
+         // We do not want to show this option unless there is more than one calendar type to display.
+         if (count($calendartypes) > 1) {
+             $calendars = array();
+             $calendars[''] = get_string('forceno');
+             $calendars += $calendartypes;
+             $mform->addElement('select', 'calendartype', get_string('forcecalendartype', 'calendar'), $calendars);
+         }
          $options = range(0, 10);
          $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
          $mform->addHelpButton('newsitems', 'newsitemsnumber');
              $mform->setDefault('enablecompletion', 0);
          }
  
- //--------------------------------------------------------------------------------
          enrol_course_edit_form($mform, $course, $context);
  
- //--------------------------------------------------------------------------------
          $mform->addElement('header','groups', get_string('groupsettingsheader', 'group'));
  
          $choices = array();
          $options[0] = get_string('none');
          $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options);
  
- //--------------------------------------------------------------------------------
- /// customizable role names in this course
- //--------------------------------------------------------------------------------
+         // Customizable role names in this course.
          $mform->addElement('header','rolerenaming', get_string('rolerenaming'));
          $mform->addHelpButton('rolerenaming', 'rolerenaming');
  
              }
          }
  
- //--------------------------------------------------------------------------------
          $this->add_action_buttons();
- //--------------------------------------------------------------------------------
          $mform->addElement('hidden', 'id', null);
          $mform->setType('id', PARAM_INT);
  
- /// finally set the current form data
- //--------------------------------------------------------------------------------
+         // Finally set the current form data
          $this->set_data($course);
      }
  
+     /**
+      * Fill in the current page data for this course.
+      */
      function definition_after_data() {
          global $DB;
  
          }
      }
  
- /// perform some extra moodle validation
+     /**
+      * Validation.
+      *
+      * @param array $data
+      * @param array $files
+      * @return array the errors that were found
+      */
      function validation($data, $files) {
 -        global $DB, $CFG;
 +        global $DB;
  
          $errors = parent::validation($data, $files);
 -        if ($foundcourses = $DB->get_records('course', array('shortname'=>$data['shortname']))) {
 -            if (!empty($data['id'])) {
 -                unset($foundcourses[$data['id']]);
 +
 +        // Add field validation check for duplicate shortname.
 +        if ($course = $DB->get_record('course', array('shortname' => $data['shortname']), '*', IGNORE_MULTIPLE)) {
 +            if (empty($data['id']) || $course->id != $data['id']) {
 +                $errors['shortname'] = get_string('shortnametaken', '', $course->fullname);
              }
 -            if (!empty($foundcourses)) {
 -                foreach ($foundcourses as $foundcourse) {
 -                    $foundcoursenames[] = $foundcourse->fullname;
 +        }
 +
 +        // Add field validation check for duplicate idnumber.
 +        if (!empty($data['idnumber']) && (empty($data['id']) || $this->course->idnumber != $data['idnumber'])) {
 +            if ($course = $DB->get_record('course', array('idnumber' => $data['idnumber']), '*', IGNORE_MULTIPLE)) {
 +                if (empty($data['id']) || $course->id != $data['id']) {
 +                    $errors['idnumber'] = get_string('courseidnumbertaken', 'error', $course->fullname);
                  }
 -                $foundcoursenamestring = implode(',', $foundcoursenames);
 -                $errors['shortname']= get_string('shortnametaken', '', $foundcoursenamestring);
              }
          }
  
@@@ -43,8 -43,6 +43,8 @@@ class core_component 
      protected static $classmap = null;
      /** @var null list of some known files that can be included. */
      protected static $filemap = null;
 +    /** @var int|float core version. */
 +    protected static $version = null;
      /** @var array list of the files to map. */
      protected static $filestomap = array('lib.php', 'settings.php');
  
                  include($cachefile);
                  if (!is_array($cache)) {
                      // Something is very wrong.
 -                } else if (!isset($cache['plugintypes']) or !isset($cache['plugins']) or !isset($cache['subsystems']) or !isset($cache['classmap'])) {
 +                } else if (!isset($cache['version'])) {
                      // Something is very wrong.
 +                } else if ((float) $cache['version'] !== (float) self::fetch_core_version()) {
 +                    // Outdated cache. We trigger an error log to track an eventual repetitive failure of float comparison.
 +                    error_log('Resetting core_component cache after core upgrade to version ' . self::fetch_core_version());
                  } else if ($cache['plugintypes']['mod'] !== "$CFG->dirroot/mod") {
                      // $CFG->dirroot was changed.
                  } else {
              'plugins'     => self::$plugins,
              'classmap'    => self::$classmap,
              'filemap'     => self::$filemap,
 +            'version'     => self::$version,
          );
  
          return '<?php
@@@ -255,23 -249,6 +255,23 @@@ $cache = '.var_export($cache, true).'
  
          self::fill_classmap_cache();
          self::fill_filemap_cache();
 +        self::fetch_core_version();
 +    }
 +
 +    /**
 +     * Get the core version.
 +     *
 +     * In order for this to work properly, opcache should be reset beforehand.
 +     *
 +     * @return float core version.
 +     */
 +    protected static function fetch_core_version() {
 +        global $CFG;
 +        if (self::$version === null) {
 +            require($CFG->dirroot . '/version.php');
 +            self::$version = $version;
 +        }
 +        return self::$version;
      }
  
      /**
              'qtype'         => $CFG->dirroot.'/question/type',
              'mod'           => $CFG->dirroot.'/mod',
              'auth'          => $CFG->dirroot.'/auth',
+             'calendartype'  => $CFG->dirroot.'/calendar/type',
              'enrol'         => $CFG->dirroot.'/enrol',
              'message'       => $CFG->dirroot.'/message/output',
              'block'         => $CFG->dirroot.'/blocks',
          $versions = array();
  
          // Main version first.
 -        $version = null;
 -        include($CFG->dirroot.'/version.php');
 -        $versions['core'] = $version;
 +        $versions['core'] = self::fetch_core_version();
  
          // The problem here is tha the component cache might be stable,
          // we want this to work also on frontpage without resetting the component cache.
diff --combined version.php
  
  defined('MOODLE_INTERNAL') || die();
  
- $version  = 2013090500.00;              // YYYYMMDD      = weekly release date of this DEV branch.
+ $version  = 2013090500.01;              // YYYYMMDD      = weekly release date of this DEV branch.
                                          //         RR    = release increments - 00 in DEV branches.
                                          //           .XX = incremental changes.
  
 -$release  = '2.6dev (Build: 20130905)'; // Human-friendly version name
 +$release  = '2.6dev (Build: 20130907)'; // Human-friendly version name
  
  $branch   = '26';                       // This version's branch.
  $maturity = MATURITY_ALPHA;             // This version's maturity level.