Merge branch 'wip-MDL-41384-master' of git://github.com/marinaglancy/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2014-02-04 10:11:42 +01:00
commit 845e11407f
4 changed files with 60 additions and 9 deletions

View File

@ -45,8 +45,11 @@ if ($id) {
print_error('cannoteditsiteform');
}
$course = course_get_format($id)->get_course();
// Login to the course and retrieve also all fields defined by course format.
$course = get_course($id);
require_login($course);
$course = course_get_format($course)->get_course();
$category = $DB->get_record('course_categories', array('id'=>$course->category), '*', MUST_EXIST);
$coursecontext = context_course::instance($course->id);
require_capability('moodle/course:update', $coursecontext);

View File

@ -237,14 +237,21 @@ abstract class format_base {
if ($this->course === false) {
$this->course = get_course($this->courseid);
$options = $this->get_format_options();
$dbcoursecolumns = null;
foreach ($options as $optionname => $optionvalue) {
if (!isset($this->course->$optionname)) {
$this->course->$optionname = $optionvalue;
} else {
debugging('The option name '.$optionname.' in course format '.$this->format.
' is invalid because the field with the same name exists in {course} table',
DEBUG_DEVELOPER);
if (isset($this->course->$optionname)) {
// Course format options must not have the same names as existing columns in db table "course".
if (!isset($dbcoursecolumns)) {
$dbcoursecolumns = $DB->get_columns('course');
}
if (isset($dbcoursecolumns[$optionname])) {
debugging('The option name '.$optionname.' in course format '.$this->format.
' is invalid because the field with the same name exists in {course} table',
DEBUG_DEVELOPER);
continue;
}
}
$this->course->$optionname = $optionvalue;
}
}
return $this->course;

View File

@ -85,7 +85,7 @@ defined('MOODLE_INTERNAL') || die();
* @return bool always true
*/
function xmldb_main_upgrade($oldversion) {
global $CFG, $USER, $DB, $OUTPUT, $SITE;
global $CFG, $USER, $DB, $OUTPUT, $SITE, $COURSE;
require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions
@ -316,6 +316,10 @@ function xmldb_main_upgrade($oldversion) {
$dbman->drop_field($table, $field);
}
// Since structure of 'course' table has changed we need to re-read $SITE from DB.
$SITE = $DB->get_record('course', array('id' => $SITE->id));
$COURSE = clone($SITE);
upgrade_main_savepoint(true, 2012031500.02);
}
@ -447,6 +451,10 @@ function xmldb_main_upgrade($oldversion) {
$dbman->add_field($table, $field);
}
// Since structure of 'course' table has changed we need to re-read $SITE from DB.
$SITE = $DB->get_record('course', array('id' => $SITE->id));
$COURSE = clone($SITE);
// Main savepoint reached
upgrade_main_savepoint(true, 2012050300.03);
}
@ -563,6 +571,10 @@ function xmldb_main_upgrade($oldversion) {
$dbman->add_field($table, $field);
}
// Since structure of 'course' table has changed we need to re-read $SITE from DB.
$SITE = $DB->get_record('course', array('id' => $SITE->id));
$COURSE = clone($SITE);
// Add course_sections_availability to add completion & grade availability conditions
$table = new xmldb_table('course_sections_availability');
@ -1334,6 +1346,10 @@ function xmldb_main_upgrade($oldversion) {
// Launch change of type for field format
$dbman->change_field_type($table, $field);
// Since structure of 'course' table has changed we need to re-read $SITE from DB.
$SITE = $DB->get_record('course', array('id' => $SITE->id));
$COURSE = clone($SITE);
// Main savepoint reached
upgrade_main_savepoint(true, 2012110200.00);
}
@ -1386,6 +1402,10 @@ function xmldb_main_upgrade($oldversion) {
}
}
// Since structure of 'course' table has changed we need to re-read $SITE from DB.
$SITE = $DB->get_record('course', array('id' => $SITE->id));
$COURSE = clone($SITE);
// Main savepoint reached
upgrade_main_savepoint(true, 2012110201.00);
}
@ -1501,6 +1521,7 @@ function xmldb_main_upgrade($oldversion) {
if ($SITE->format !== 'site') {
$DB->set_field('course', 'format', 'site', array('id' => $SITE->id));
$SITE->format = 'site';
$COURSE->format = 'site';
}
// Main savepoint reached
@ -1989,6 +2010,10 @@ function xmldb_main_upgrade($oldversion) {
$dbman->drop_field($table, $field);
}
// Since structure of 'course' table has changed we need to re-read $SITE from DB.
$SITE = $DB->get_record('course', array('id' => $SITE->id));
$COURSE = clone($SITE);
// Main savepoint reached.
upgrade_main_savepoint(true, 2013040300.01);
}
@ -2376,6 +2401,10 @@ function xmldb_main_upgrade($oldversion) {
$dbman->add_field($table, $field);
}
// Since structure of 'course' table has changed we need to re-read $SITE from DB.
$SITE = $DB->get_record('course', array('id' => $SITE->id));
$COURSE = clone($SITE);
// Define field calendartype to be added to user.
$table = new xmldb_table('user');
$field = new xmldb_field('calendartype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, 'gregorian');
@ -2400,6 +2429,10 @@ function xmldb_main_upgrade($oldversion) {
$dbman->add_field($table, $field);
}
// Since structure of 'course' table has changed we need to re-read $SITE from DB.
$SITE = $DB->get_record('course', array('id' => $SITE->id));
$COURSE = clone($SITE);
// Main savepoint reached.
upgrade_main_savepoint(true, 2013091000.02);
}
@ -2423,6 +2456,10 @@ function xmldb_main_upgrade($oldversion) {
$dbman->drop_field($table, $field);
}
// Since structure of 'course' table has changed we need to re-read $SITE from DB.
$SITE = $DB->get_record('course', array('id' => $SITE->id));
$COURSE = clone($SITE);
// Main savepoint reached.
upgrade_main_savepoint(true, 2013091000.03);
}

View File

@ -1503,7 +1503,7 @@ function install_core($version, $verbose) {
* @return void, may throw exception
*/
function upgrade_core($version, $verbose) {
global $CFG;
global $CFG, $SITE, $DB, $COURSE;
raise_memory_limit(MEMORY_EXTRA);
@ -1534,6 +1534,10 @@ function upgrade_core($version, $verbose) {
upgrade_main_savepoint($result, $version, false);
}
// In case structure of 'course' table has been changed and we forgot to update $SITE, re-read it from db.
$SITE = $DB->get_record('course', array('id' => $SITE->id));
$COURSE = clone($SITE);
// perform all other component upgrade routines
update_capabilities('moodle');
log_update_descriptions('moodle');