Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/moodle/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
pcharsle committed Aug 27, 2012
2 parents 4a52712 + d71c486 commit 4873a89
Show file tree
Hide file tree
Showing 141 changed files with 3,601 additions and 887 deletions.
10 changes: 4 additions & 6 deletions admin/roles/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1039,12 +1039,10 @@ public function find_users($search) {
$countfields = 'SELECT COUNT(u.id)';

$sql = " FROM {user} u
WHERE u.id IN ($enrolsql) $wherecondition
AND u.id NOT IN (
SELECT r.userid
FROM {role_assignments} r
WHERE r.contextid = :contextid
AND r.roleid = :roleid)";
LEFT JOIN {role_assignments} ra ON (ra.userid = u.id AND ra.roleid = :roleid AND ra.contextid = :contextid)
WHERE u.id IN ($enrolsql)
$wherecondition
AND ra.id IS NULL";
$order = ' ORDER BY lastname ASC, firstname ASC';

$params['contextid'] = $this->context->id;
Expand Down
5 changes: 5 additions & 0 deletions admin/settings/courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
$temp->add(new admin_setting_configselect('moodlecourse/legacyfiles', new lang_string('courselegacyfiles'), new lang_string('courselegacyfiles_help'), key($choices), $choices));
}

$choices = array();
$choices[COURSE_DISPLAY_SINGLEPAGE] = new lang_string('coursedisplay_single');
$choices[COURSE_DISPLAY_MULTIPAGE] = new lang_string('coursedisplay_multi');
$temp->add(new admin_setting_configselect('moodlecourse/coursedisplay', new lang_string('coursedisplay'), new lang_string('coursedisplay_help'), COURSE_DISPLAY_SINGLEPAGE, $choices));

$temp->add(new admin_setting_heading('groups', new lang_string('groups', 'group'), ''));
$choices = array();
$choices[NOGROUPS] = new lang_string('groupsnone', 'group');
Expand Down
2 changes: 1 addition & 1 deletion admin/settings/location.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

$temp->add(new admin_setting_heading('iplookup', new lang_string('iplookup', 'admin'), new lang_string('iplookupinfo', 'admin')));
$temp->add(new admin_setting_configfile('geoipfile', new lang_string('geoipfile', 'admin'), new lang_string('configgeoipfile', 'admin', $CFG->dataroot.'/geoip/'), $CFG->dataroot.'/geoip/GeoLiteCity.dat'));
$temp->add(new admin_setting_configtext('googlemapkey', new lang_string('googlemapkey', 'admin'), new lang_string('configgooglemapkey', 'admin', $CFG->wwwroot), ''));
$temp->add(new admin_setting_configtext('googlemapkey3', new lang_string('googlemapkey3', 'admin'), new lang_string('googlemapkey3_help', 'admin'), '', PARAM_RAW, 60));

$temp->add(new admin_setting_configtext('allcountrycodes', new lang_string('allcountrycodes', 'admin'), new lang_string('configallcountrycodes', 'admin'), '', '/^(?:\w+(?:,\w+)*)?$/'));

Expand Down
2 changes: 1 addition & 1 deletion admin/tool/phpunit/cli/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
} else if ($drop) {
// make sure tests do not run in parallel
phpunit_util::acquire_test_lock();
phpunit_util::drop_site();
phpunit_util::drop_site(true);
// note: we must stop here because $CFG is messed up and we can not reinstall, sorry
exit(0);

Expand Down
4 changes: 3 additions & 1 deletion auth/email/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ function user_confirm($username, $confirmsecret) {

} else if ($user->secret == $confirmsecret) { // They have provided the secret key to get in
$DB->set_field("user", "confirmed", 1, array("id"=>$user->id));
$DB->set_field("user", "firstaccess", time(), array("id"=>$user->id));
if ($user->firstaccess == 0) {
$DB->set_field("user", "firstaccess", time(), array("id"=>$user->id));
}
return AUTH_CONFIRM_OK;
}
} else {
Expand Down
4 changes: 3 additions & 1 deletion auth/ldap/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,9 @@ function user_confirm($username, $confirmsecret) {
return AUTH_CONFIRM_FAIL;
}
$DB->set_field('user', 'confirmed', 1, array('id'=>$user->id));
$DB->set_field('user', 'firstaccess', time(), array('id'=>$user->id));
if ($user->firstaccess == 0) {
$DB->set_field('user', 'firstaccess', time(), array('id'=>$user->id));
}
return AUTH_CONFIRM_OK;
}
} else {
Expand Down
4 changes: 3 additions & 1 deletion auth/manual/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ function user_confirm($username, $confirmsecret = null) {
return AUTH_CONFIRM_ALREADY;
} else {
$DB->set_field("user", "confirmed", 1, array("id"=>$user->id));
$DB->set_field("user", "firstaccess", time(), array("id"=>$user->id));
if ($user->firstaccess == 0) {
$DB->set_field("user", "firstaccess", time(), array("id"=>$user->id));
}
return AUTH_CONFIRM_OK;
}
} else {
Expand Down
27 changes: 18 additions & 9 deletions backup/moodle2/backup_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,17 @@ abstract class backup_questions_activity_structure_step extends backup_activity_
/**
* Attach to $element (usually attempts) the needed backup structures
* for question_usages and all the associated data.
*
* @param backup_nested_element $element the element that will contain all the question_usages data.
* @param string $usageidname the name of the element that holds the usageid.
* This must be child of $element, and must be a final element.
* @param string $nameprefix this prefix is added to all the element names we create.
* Element names in the XML must be unique, so if you are using usages in
* two different ways, you must give a prefix to at least one of them. If
* you only use one sort of usage, then you can just use the default empty prefix.
* This should include a trailing underscore. For example "myprefix_"
*/
protected function add_question_usages($element, $usageidname) {
protected function add_question_usages($element, $usageidname, $nameprefix = '') {
global $CFG;
require_once($CFG->dirroot . '/question/engine/lib.php');

Expand All @@ -195,21 +204,21 @@ protected function add_question_usages($element, $usageidname) {
throw new backup_step_exception('question_states_bad_question_attempt_element', $usageidname);
}

$quba = new backup_nested_element('question_usage', array('id'),
$quba = new backup_nested_element($nameprefix . 'question_usage', array('id'),
array('component', 'preferredbehaviour'));

$qas = new backup_nested_element('question_attempts');
$qa = new backup_nested_element('question_attempt', array('id'), array(
$qas = new backup_nested_element($nameprefix . 'question_attempts');
$qa = new backup_nested_element($nameprefix . 'question_attempt', array('id'), array(
'slot', 'behaviour', 'questionid', 'maxmark', 'minfraction',
'flagged', 'questionsummary', 'rightanswer', 'responsesummary',
'timemodified'));

$steps = new backup_nested_element('steps');
$step = new backup_nested_element('step', array('id'), array(
$steps = new backup_nested_element($nameprefix . 'steps');
$step = new backup_nested_element($nameprefix . 'step', array('id'), array(
'sequencenumber', 'state', 'fraction', 'timecreated', 'userid'));

$response = new backup_nested_element('response');
$variable = new backup_nested_element('variable', null, array('name', 'value'));
$response = new backup_nested_element($nameprefix . 'response');
$variable = new backup_nested_element($nameprefix . 'variable', null, array('name', 'value'));

// Build the tree
$element->add_child($quba);
Expand Down Expand Up @@ -1835,7 +1844,7 @@ protected function define_execution() {
'backupid' => $this->get_backupid(), 'itemname' => 'userfinal'));
foreach ($rs as $record) {
$userid = $record->itemid;
$userctx = context_user::instance($userid);
$userctx = context_user::instance($userid, IGNORE_MISSING);
if (!$userctx) {
continue; // User has not context, sure it's a deleted user, so cannot have files
}
Expand Down
88 changes: 69 additions & 19 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3478,31 +3478,74 @@ abstract class restore_questions_activity_structure_step extends restore_activit
/**
* Attach below $element (usually attempts) the needed restore_path_elements
* to restore question_usages and all they contain.
*
* If you use the $nameprefix parameter, then you will need to implement some
* extra methods in your class, like
*
* protected function process_{nameprefix}question_attempt($data) {
* $this->restore_question_usage_worker($data, '{nameprefix}');
* }
* protected function process_{nameprefix}question_attempt($data) {
* $this->restore_question_attempt_worker($data, '{nameprefix}');
* }
* protected function process_{nameprefix}question_attempt_step($data) {
* $this->restore_question_attempt_step_worker($data, '{nameprefix}');
* }
*
* @param restore_path_element $element the parent element that the usages are stored inside.
* @param array $paths the paths array that is being built.
* @param string $nameprefix should match the prefix passed to the corresponding
* backup_questions_activity_structure_step::add_question_usages call.
*/
protected function add_question_usages($element, &$paths) {
protected function add_question_usages($element, &$paths, $nameprefix = '') {
// Check $element is restore_path_element
if (! $element instanceof restore_path_element) {
throw new restore_step_exception('element_must_be_restore_path_element', $element);
}

// Check $paths is one array
if (!is_array($paths)) {
throw new restore_step_exception('paths_must_be_array', $paths);
}
$paths[] = new restore_path_element('question_usage',
$element->get_path() . '/question_usage');
$paths[] = new restore_path_element('question_attempt',
$element->get_path() . '/question_usage/question_attempts/question_attempt');
$paths[] = new restore_path_element('question_attempt_step',
$element->get_path() . '/question_usage/question_attempts/question_attempt/steps/step',
$paths[] = new restore_path_element($nameprefix . 'question_usage',
$element->get_path() . "/{$nameprefix}question_usage");
$paths[] = new restore_path_element($nameprefix . 'question_attempt',
$element->get_path() . "/{$nameprefix}question_usage/{$nameprefix}question_attempts/{$nameprefix}question_attempt");
$paths[] = new restore_path_element($nameprefix . 'question_attempt_step',
$element->get_path() . "/{$nameprefix}question_usage/{$nameprefix}question_attempts/{$nameprefix}question_attempt/{$nameprefix}steps/{$nameprefix}step",
true);
$paths[] = new restore_path_element('question_attempt_step_data',
$element->get_path() . '/question_usage/question_attempts/question_attempt/steps/step/response/variable');
$paths[] = new restore_path_element($nameprefix . 'question_attempt_step_data',
$element->get_path() . "/{$nameprefix}question_usage/{$nameprefix}question_attempts/{$nameprefix}question_attempt/{$nameprefix}steps/{$nameprefix}step/{$nameprefix}response/{$nameprefix}variable");
}

/**
* Process question_usages
*/
protected function process_question_usage($data) {
$this->restore_question_usage_worker($data, '');
}

/**
* Process question_attempts
*/
protected function process_question_attempt($data) {
$this->restore_question_attempt_worker($data, '');
}

/**
* Process question_attempt_steps
*/
protected function process_question_attempt_step($data) {
$this->restore_question_attempt_step_worker($data, '');
}

/**
* This method does the acutal work for process_question_usage or
* process_{nameprefix}_question_usage.
* @param array $data the data from the XML file.
* @param string $nameprefix the element name prefix.
*/
protected function restore_question_usage_worker($data, $nameprefix) {
global $DB;

// Clear our caches.
Expand All @@ -3520,7 +3563,7 @@ protected function process_question_usage($data) {

$this->inform_new_usage_id($newitemid);

$this->set_mapping('question_usage', $oldid, $newitemid, false);
$this->set_mapping($nameprefix . 'question_usage', $oldid, $newitemid, false);
}

/**
Expand All @@ -3532,45 +3575,51 @@ protected function process_question_usage($data) {
abstract protected function inform_new_usage_id($newusageid);

/**
* Process question_attempts
* This method does the acutal work for process_question_attempt or
* process_{nameprefix}_question_attempt.
* @param array $data the data from the XML file.
* @param string $nameprefix the element name prefix.
*/
protected function process_question_attempt($data) {
protected function restore_question_attempt_worker($data, $nameprefix) {
global $DB;

$data = (object)$data;
$oldid = $data->id;
$question = $this->get_mapping('question', $data->questionid);

$data->questionusageid = $this->get_new_parentid('question_usage');
$data->questionusageid = $this->get_new_parentid($nameprefix . 'question_usage');
$data->questionid = $question->newitemid;
$data->timemodified = $this->apply_date_offset($data->timemodified);

$newitemid = $DB->insert_record('question_attempts', $data);

$this->set_mapping('question_attempt', $oldid, $newitemid);
$this->set_mapping($nameprefix . 'question_attempt', $oldid, $newitemid);
$this->qtypes[$newitemid] = $question->info->qtype;
$this->newquestionids[$newitemid] = $data->questionid;
}

/**
* Process question_attempt_steps
* This method does the acutal work for process_question_attempt_step or
* process_{nameprefix}_question_attempt_step.
* @param array $data the data from the XML file.
* @param string $nameprefix the element name prefix.
*/
protected function process_question_attempt_step($data) {
protected function restore_question_attempt_step_worker($data, $nameprefix) {
global $DB;

$data = (object)$data;
$oldid = $data->id;

// Pull out the response data.
$response = array();
if (!empty($data->response['variable'])) {
foreach ($data->response['variable'] as $variable) {
if (!empty($data->{$nameprefix . 'response'}[$nameprefix . 'variable'])) {
foreach ($data->{$nameprefix . 'response'}[$nameprefix . 'variable'] as $variable) {
$response[$variable['name']] = $variable['value'];
}
}
unset($data->response);

$data->questionattemptid = $this->get_new_parentid('question_attempt');
$data->questionattemptid = $this->get_new_parentid($nameprefix . 'question_attempt');
$data->timecreated = $this->apply_date_offset($data->timecreated);
$data->userid = $this->get_mappingid('user', $data->userid);

Expand All @@ -3583,6 +3632,7 @@ protected function process_question_attempt_step($data) {
$this->qtypes[$data->questionattemptid],
$this->newquestionids[$data->questionattemptid],
$data->sequencenumber, $response);

foreach ($response as $name => $value) {
$row = new stdClass();
$row->attemptstepid = $newitemid;
Expand Down
2 changes: 1 addition & 1 deletion backup/util/dbops/backup_plan_dbops.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static function get_sections_from_courseid($courseid) {

// Get all sections belonging to requested course
$sectionsarr = array();
$sections = $DB->get_records('course_sections', array('course' => $courseid));
$sections = $DB->get_records('course_sections', array('course' => $courseid), 'section');
foreach ($sections as $section) {
$sectionsarr[] = $section->id;
}
Expand Down
Loading

0 comments on commit 4873a89

Please sign in to comment.