Index: mod/forum/db/upgrade.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/forum/db/upgrade.php,v
retrieving revision 1.27
diff -u -r1.27 upgrade.php
--- mod/forum/db/upgrade.php 8 Sep 2008 05:46:42 -0000 1.27
+++ mod/forum/db/upgrade.php 6 Nov 2008 05:56:48 -0000
@@ -49,7 +49,7 @@
JOIN {course} c ON c.id = f.course
JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = ".CONTEXT_COURSE.")
JOIN {forum_subscriptions} fs ON fs.forum = f.id
- LEFT JOIN {role_assignments} ra ON (ra.contextid = ctx.id AND ra.userid = fs.userid AND ra.roleid $usql)
+ LEFT JOIN {role_assignments} ra ON (ra.contextid = ctx.id AND ra.userid = fs.userid AND ra.roleid $usql AND ra.active = 1)
WHERE ra.id IS NULL";
if ($rs = $DB->get_recordset_sql($sql, $params)) {
Index: lib/accesslib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/accesslib.php,v
retrieving revision 1.530
diff -u -r1.530 accesslib.php
--- lib/accesslib.php 5 Nov 2008 08:17:31 -0000 1.530
+++ lib/accesslib.php 6 Nov 2008 05:56:27 -0000
@@ -517,6 +517,7 @@
ON ra.roleid=rc.roleid AND ra.contextid=ctx.id
WHERE ctx.contextlevel=10
AND ra.userid=?
+ AND ra.active = 1
AND rc.capability IN (?, ?, ?)
GROUP BY rc.capability
HAVING SUM(rc.permission) > 0";
@@ -1036,7 +1037,7 @@
JOIN {$CFG->prefix}context ctx
ON (c.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.")
JOIN {$CFG->prefix}role_assignments ra
- ON (ra.contextid=ctx.id AND ra.userid=:userid)
+ ON (ra.contextid=ctx.id AND ra.userid=:userid AND ra.active=1)
UNION
SELECT c.id,
ctx.id AS ctxid, ctx.path AS ctxpath,
@@ -1154,6 +1155,7 @@
LEFT OUTER JOIN {role_capabilities} rc
ON (rc.roleid=ra.roleid AND rc.contextid=ra.contextid)
WHERE ra.userid = ? AND ctx.contextlevel <= ".CONTEXT_COURSE."
+ AND ra.active=1
ORDER BY ctx.depth, ctx.path, ra.roleid";
$params = array($userid);
$rs = $DB->get_recordset_sql($sql, $params);
@@ -1255,6 +1257,7 @@
JOIN {role_capabilities} rco
ON (rco.roleid=ra.roleid AND rco.contextid=sctx.id)
WHERE ra.userid = ?
+ AND ra.active = 1
AND sctx.contextlevel <= ".CONTEXT_COURSE."
ORDER BY sctx.depth, sctx.path, ra.roleid";
$params = array($userid);
@@ -1326,6 +1329,7 @@
JOIN {context} ctx
ON ra.contextid=ctx.id
WHERE ra.userid = ?
+ AND ra.active = 1
AND (ctx.path = ? OR ctx.path LIKE ?)
ORDER BY ctx.depth, ctx.path, ra.roleid";
$params = array($userid, $context->path, $context->path."/%");
@@ -2565,7 +2569,7 @@
foreach ($adminroles as $adminrole) {
if ($adminrole->id != $roleid) {
// some other admin role
- if ($DB->record_exists('role_assignments', array('roleid'=>$adminrole->id, 'contextid'=>$systemcontext->id))) {
+ if ($DB->record_exists('role_assignments', array('roleid'=>$adminrole->id, 'contextid'=>$systemcontext->id, 'active'=>1))) {
// found another admin role with at least 1 user assigned
$status = true;
break;
@@ -2781,10 +2785,13 @@
$ra->userid = $userid;
$ra->hidden = $hidden;
$ra->enrol = $enrol;
- /// Always round timestart downto 100 secs to help DBs to use their own caching algorithms
- /// by repeating queries with the same exact parameters in a 100 secs time window
- $ra->timestart = round($timestart, -2);
+ $ra->timestart = $timestart;
$ra->timeend = $timeend;
+ /// If timestart is in the future then the role must be set to not be active
+ /// (otherwise, database defaults to active=1); will be activated later in cron
+ if($timestart > time()) {
+ $ra->active = 0;
+ }
$ra->timemodified = $timemodified;
$ra->modifierid = empty($USER->id) ? 0 : $USER->id;
@@ -2793,13 +2800,15 @@
}
} else { // We already have one, just update it
- $ra->id = $ra->id;
$ra->hidden = $hidden;
$ra->enrol = $enrol;
- /// Always round timestart downto 100 secs to help DBs to use their own caching algorithms
- /// by repeating queries with the same exact parameters in a 100 secs time window
- $ra->timestart = round($timestart, -2);
+ $ra->timestart = $timestart;
$ra->timeend = $timeend;
+ /// If timestart is in the future then the role must be set to not be active
+ /// (otherwise, database defaults to active=1); will be activated later in cron
+ if ($timestart > time()) {
+ $ra->active = 0;
+ }
$ra->timemodified = $timemodified;
$ra->modifierid = empty($USER->id) ? 0 : $USER->id;
@@ -3948,6 +3957,7 @@
FROM {role_assignments} ra, {role} r
WHERE r.id = ra.roleid
AND ra.contextid $contextlist
+ AND ra.active = 1
$hiddensql
ORDER BY r.sortorder ASC";
@@ -3966,7 +3976,7 @@
$rolestring = '';
$sql = "SELECT *
FROM {role_assignments} ra, {role} r
- WHERE ra.userid = ? and ra.contextid = ? and ra.roleid = r.id";
+ WHERE ra.userid = ? and ra.contextid = ? and ra.roleid = r.id AND ra.active = 1";
$params = array($userid, $context->id);
$rolenames = array();
if ($roles = $DB->get_records_sql($sql, $params)) {
@@ -4097,6 +4107,7 @@
WHERE ra.userid = ?
AND ra.roleid = r.id
AND ra.contextid = c.id
+ AND ra.active = 1
AND ra.contextid $contextids
$hiddensql
ORDER BY $order";
@@ -4177,7 +4188,7 @@
FROM {role} r,
{role_assignments} ra,
{role_allow_assign} raa
- WHERE ra.userid = :userid AND ra.contextid IN ($contexts)
+ WHERE ra.userid = :userid AND ra.contextid IN ($contexts) AND ra.active = 1
AND raa.roleid = ra.roleid AND r.id = raa.allowassign
) inline_view ON ro.id = inline_view.id
ORDER BY ro.sortorder ASC", $params)) {
@@ -4233,7 +4244,7 @@
{role_assignments} ra,
{role_allow_assign} raa,
{role_capabilities} rc
- WHERE ra.userid = :userid AND ra.contextid IN ($contexts)
+ WHERE ra.userid = :userid AND ra.contextid IN ($contexts) AND ra.active = 1
AND raa.roleid = ra.roleid AND r.id = raa.allowassign
AND r.id = rc.roleid AND rc.capability = :viewcap AND rc.capability <> :anythingcap
) inline_view ON ro.id = inline_view.id
@@ -4293,7 +4304,7 @@
FROM {role} r
JOIN {role_allow_override} rao ON r.id = rao.allowoverride
JOIN {role_assignments} ra ON rao.roleid = ra.roleid
- WHERE ra.userid = :userid AND ra.contextid IN ($contexts)
+ WHERE ra.userid = :userid AND ra.contextid IN ($contexts) AND ra.active = 1
) inline_view ON ro.id = inline_view.id
ORDER BY ro.sortorder ASC", $params)) {
return array();
@@ -4588,6 +4599,7 @@
FROM {role_assignments} ssra
WHERE ssra.contextid IN ($ctxids)
AND ssra.roleid IN (".implode(',',$roleids) .")
+ AND ssra.active = 1
$sscondhiddenra
) ra ON ra.userid = u.id
$uljoin ";
@@ -4647,6 +4659,7 @@
ON (ra.userid = u.id
AND ra.contextid IN ($ctxids)
AND ra.roleid IN (".implode(',',$roleids) .")
+ AND ra.active = 1
$condhiddenra)
LEFT OUTER JOIN {context} ctx
ON ra.contextid=ctx.id
@@ -4660,6 +4673,7 @@
JOIN {context} ctx
ON ra.contextid=ctx.id
WHERE ra.contextid IN ($ctxids)
+ AND ra.active = 1
$condhiddenra
AND ra.roleid IN (".implode(',',$roleids) .")";
}
@@ -4953,6 +4967,7 @@
JOIN {context} ctx
ON ra.contextid=ctx.id
WHERE $userswhere
+ AND ra.active = 1
$contextwhere
$roleswhere";
@@ -5082,6 +5097,7 @@
FROM {role_assignments} r
JOIN {user} u ON u.id = r.userid
WHERE (r.contextid = ? $parentcontexts)
+ AND r.active = 1
AND r.roleid = ? AND u.deleted = 0";
$params = array($context->id, $roleid);
@@ -5153,7 +5169,7 @@
}
/** This function finds the roles assigned directly to this context only
- * i.e. no parents role
+ * i.e. no parents role. Used by backup, so inactive ras are included.
* @param object $context
* @return array
*/
@@ -5168,6 +5184,35 @@
}
/**
+ * If the user has any role on the specified (exact) context which is not
+ * yet active, then we return the timestart of the role assignment.
+ * - If they have two such roles then we return the earliest timestart.
+ * - Note that they may have other active roles. This function is intended
+ * to be used after a has_capability fails, so that information can be
+ * displayed to the user about when they might have access again.
+ * @param int $contextid ID of context
+ * @param int $userid User ID, leave out for current user
+ * @return False if none, or an object containing fields from role_assignments
+ * (including timestart).
+ */
+function get_inactive_role_on_context($contextid,$userid=0) {
+ global $CFG,$USER;
+ if(!$userid) {
+ $userid=$USER->id;
+ }
+ $rs=get_recordset_sql("SELECT ra.*
+ FROM {$CFG->prefix}role_assignments ra
+ WHERE ra.userid=$userid
+ AND ra.contextid=$contextid
+ AND ra.active=0
+ AND ra.timestart<>0
+ ORDER BY ra.timestart");
+ $firstresult=rs_fetch_next_record($rs);
+ rs_close($rs);
+ return $firstresult; // False if no records, or the first record
+}
+
+/**
* Switches the current user to another role for the current session and only
* in the given context.
*
Index: lib/statslib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/statslib.php,v
retrieving revision 1.73
diff -u -r1.73 statslib.php
--- lib/statslib.php 13 Oct 2008 23:24:45 -0000 1.73
+++ lib/statslib.php 6 Nov 2008 05:56:39 -0000
@@ -847,7 +847,7 @@
$join = "JOIN {context} ctx ON ctx.id = ra.contextid
CROSS JOIN {course} c
JOIN {role_capabilities} rc ON rc.roleid = ra.roleid";
- $where = "((rc.capability = :sge_courseview_$n $adm)
+ $where = "ra.active = 1 AND ((rc.capability = :sge_courseview_$n $adm)
AND rc.permission = 1 AND rc.contextid = ".SYSCONTEXTID."
AND (ctx.contextlevel = ".CONTEXT_SYSTEM."
OR (c.id = ctx.instanceid AND ctx.contextlevel = ".CONTEXT_COURSE.")";
Index: lib/deprecatedlib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/deprecatedlib.php,v
retrieving revision 1.103
diff -u -r1.103 deprecatedlib.php
--- lib/deprecatedlib.php 16 Oct 2008 17:50:13 -0000 1.103
+++ lib/deprecatedlib.php 6 Nov 2008 05:56:30 -0000
@@ -86,14 +86,14 @@
$userid = $USER->id;
}
- if (!$DB->record_exists('role_assignments', array('userid'=>$userid))) { // Has no roles anywhere
+ if (!$DB->record_exists('role_assignments', array('userid'=>$userid, 'active'=>1))) { // Has no roles anywhere
return false;
}
/// If this user is assigned as an editing teacher anywhere then return true
if ($roles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW)) {
foreach ($roles as $role) {
- if ($DB->record_exists('role_assignments', array('roleid'=>$role->id, 'userid'=>$userid))) {
+ if ($DB->record_exists('role_assignments', array('roleid'=>$role->id, 'userid'=>$userid, 'active'=>1))) {
return true;
}
}
@@ -102,7 +102,7 @@
/// If this user is assigned as a non-editing teacher anywhere then return true
if ($roles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) {
foreach ($roles as $role) {
- if ($DB->record_exists('role_assignments', array('roleid'=>$role->id, 'userid'=>$userid))) {
+ if ($DB->record_exists('role_assignments', array('roleid'=>$role->id, 'userid'=>$userid, 'active'=>1))) {
return true;
}
}
@@ -197,6 +197,7 @@
AND ".$DB->sql_cast_char2int('l.info')." = u.id
AND u.id = ra.userid
AND ra.contextid ".get_related_contexts_string($context)."
+ AND ra.active = 1
ORDER BY l.time ASC";
$params = array($timestart, $courseid);
return $DB->get_records_sql($sql, $params);
Index: lib/moodlelib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/moodlelib.php,v
retrieving revision 1.1127
diff -u -r1.1127 moodlelib.php
--- lib/moodlelib.php 5 Nov 2008 08:17:31 -0000 1.1127
+++ lib/moodlelib.php 6 Nov 2008 05:56:38 -0000
@@ -2072,9 +2072,16 @@
}
}
- /// Non-guests who don't currently have access, check if they can be allowed in as a guest
+ /// Non-guests who don't currently have access...
if ($USER->username != 'guest' and !has_capability('moodle/course:view', $COURSE->context)) {
+ /// Is it because they have a role which hasn't started yet?
+ if($inactive=get_inactive_role_on_context($COURSE->context->id)) {
+ /// Display info about the start date and stop
+ notice(get_string('courserolenotstarted','',userdate($inactive->timestart)), $CFG->wwwroot .'/');
+ }
+
+ /// Check if they can be allowed in as a guest
if ($COURSE->guest == 1) {
// Temporarily assign them guest role for this context, if it fails later user is asked to enrol
$USER->access = load_temp_role($COURSE->context, $CFG->guestroleid, $USER->access);
@@ -2483,6 +2490,7 @@
SELECT ra.id, ra.roleid, ra.userid
FROM {role_assignments} ra, {context} con, {course_meta} cm
WHERE ra.contextid = con.id AND
+ ra.active = 1 AND
con.contextlevel = ".CONTEXT_COURSE." AND
con.instanceid = cm.child_course AND
cm.parent_course = ? AND
@@ -2510,6 +2518,7 @@
WHERE ra2.userid = ra.userid AND
ra2.roleid = ra.roleid AND
ra2.contextid = con2.id AND
+ ra2.active = 1 AND
con2.contextlevel = " . CONTEXT_COURSE . " AND
con2.instanceid = cm.child_course AND
cm.parent_course = ?
@@ -2534,7 +2543,8 @@
return $success;
// TODO: finish timeend and timestart
-// maybe we could rely on cron job to do the cleaning from time to time
+// We are currently relying on cron job to re-synchronsise role_assignments to metacourses
+// when timed assignments on the child course start or finishe. I guess that is OK for now.
}
/**
Index: lib/datalib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/datalib.php,v
retrieving revision 1.489
diff -u -r1.489 datalib.php
--- lib/datalib.php 7 Sep 2008 06:00:22 -0000 1.489
+++ lib/datalib.php 6 Nov 2008 05:56:29 -0000
@@ -58,7 +58,7 @@
$sql = "SELECT ra.userid, SUM(rc.permission) AS permission, MIN(ra.id) AS adminid
FROM {role_capabilities} rc
JOIN {context} ctx ON ctx.id=rc.contextid
- JOIN {role_assignments} ra ON ra.roleid=rc.roleid AND ra.contextid=ctx.id
+ JOIN {role_assignments} ra ON ra.roleid=rc.roleid AND ra.contextid=ctx.id AND ra.active = 1
WHERE ctx.contextlevel=10 AND rc.capability IN (?, ?, ?)
GROUP BY ra.userid
HAVING SUM(rc.permission) > 0";
@@ -188,7 +188,7 @@
$sql = "SELECT u.id, u.firstname, u.lastname, u.email
FROM {user} u
JOIN {role_assignments} ra ON ra.userid = u.id
- WHERE $select AND ra.contextid $contextlists
+ WHERE $select AND ra.contextid $contextlists AND ra.active = 1
$except
$order";
return $DB->get_records_sql($sql, $params);
@@ -650,7 +650,7 @@
JOIN {role} r ON ra.roleid = r.id
LEFT OUTER JOIN {course} c
ON (ctx.instanceid=c.id AND ctx.contextlevel=".CONTEXT_COURSE.")
- WHERE ( c.id IS NOT NULL";
+ WHERE ra.active = 1 AND ( c.id IS NOT NULL";
// under certain conditions, $catctxids is NULL
if($catctxids == NULL){
$sql .= ") ";
Index: admin/cron.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/cron.php,v
retrieving revision 1.152
diff -u -r1.152 cron.php
--- admin/cron.php 5 Nov 2008 07:13:26 -0000 1.152
+++ admin/cron.php 6 Nov 2008 05:56:12 -0000
@@ -242,6 +242,9 @@
}
+ mtrace('Activating any enrolments with start times ...');
+ execute_sql("UPDATE {$CFG->prefix}role_assignments SET active=1 WHERE active=0 AND timestart<".time(),false);
+ mtrace('done.');
mtrace('Starting main gradebook job ...');
grade_cron();
Index: grade/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/grade/lib.php,v
retrieving revision 1.146
diff -u -r1.146 lib.php
--- grade/lib.php 22 Sep 2008 15:51:28 -0000 1.146
+++ grade/lib.php 6 Nov 2008 05:56:16 -0000
@@ -115,7 +115,7 @@
// $params contents: gradebookroles and groupid (for $groupwheresql)
$users_sql = "SELECT u.* $ofields
FROM {user} u
- INNER JOIN {role_assignments} ra ON u.id = ra.userid
+ INNER JOIN {role_assignments} ra ON u.id = ra.userid AND ra.active = 1
$groupsql
WHERE ra.roleid $gradebookroles_sql
AND ra.contextid $relatedcontexts
@@ -133,7 +133,7 @@
$grades_sql = "SELECT g.* $ofields
FROM {grade_grades} g
INNER JOIN {user} u ON g.userid = u.id
- INNER JOIN {role_assignments} ra ON u.id = ra.userid
+ INNER JOIN {role_assignments} ra ON u.id = ra.userid AND ra.active = 1
$groupsql
WHERE ra.roleid $gradebookroles_sql
AND ra.contextid $relatedcontexts
Index: group/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/group/lib.php,v
retrieving revision 1.19
diff -u -r1.19 lib.php
--- group/lib.php 29 Oct 2008 08:18:25 -0000 1.19
+++ group/lib.php 6 Nov 2008 05:56:19 -0000
@@ -496,6 +496,7 @@
FROM {user} u
JOIN {role_assignments} r on u.id=r.userid
WHERE (r.contextid = :contextid OR r.contextid $listofcontexts)
+ AND ra.active = 1
AND u.deleted = 0 AND u.username != 'guest'
$selectrole $adminroles
ORDER BY $orderby";
@@ -592,8 +593,9 @@
JOIN {role_assignments} ra ON ra.userid = u.id
JOIN {role} r ON r.id = ra.roleid
WHERE gm.groupid=?
- AND ra.contextid ".get_related_contexts_string($context).
- $extrawheretest."
+ AND ra.contextid ".get_related_contexts_string($context)."
+ AND ra.active = 1
+ $extrawheretest
ORDER BY r.sortorder, $sort";
array_unshift($whereparams, $groupid);
$rs = $DB->get_recordset_sql($sql, $whereparams);
Index: lang/en_utf8/moodle.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/moodle.php,v
retrieving revision 1.205
diff -u -r1.205 moodle.php
--- lang/en_utf8/moodle.php 4 Nov 2008 05:12:12 -0000 1.205
+++ lang/en_utf8/moodle.php 6 Nov 2008 05:56:21 -0000
@@ -300,6 +300,7 @@
$string['courserequestreason'] = 'Reasons for wanting this course';
$string['courserequestsuccess'] = 'Successfully saved your course request. Expect an email within a few days with the outcome';
$string['courserestore'] = 'Course restore';
+$string['courserolenotstarted'] = 'You don\'t yet have access to this course. Your access should be enabled shortly after $a - please try again then.';
$string['courses'] = 'Courses';
$string['coursescategory'] = 'Courses in the same category';
$string['coursesettings'] = 'Course default settings';
Index: grade/report/grader/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/grade/report/grader/lib.php,v
retrieving revision 1.152
diff -u -r1.152 lib.php
--- grade/report/grader/lib.php 10 Oct 2008 07:18:19 -0000 1.152
+++ grade/report/grader/lib.php 6 Nov 2008 05:56:18 -0000
@@ -316,6 +316,7 @@
WHERE ra.roleid $usql AND u.deleted = 0
$this->groupwheresql
AND ra.contextid ".get_related_contexts_string($this->context)."
+ AND ra.active = 1
GROUP BY u.id, u.firstname, u.lastname, u.imagealt, u.picture, u.idnumber
ORDER BY $sort";
@@ -338,6 +339,7 @@
WHERE ra.roleid $usql AND u.deleted = 0
$this->groupwheresql
AND ra.contextid ".get_related_contexts_string($this->context)."
+ AND ra.active = 1
ORDER BY $sort";
}
@@ -956,6 +958,7 @@
WHERE gi.courseid = :courseid
AND ra.roleid $usql
AND ra.contextid ".get_related_contexts_string($this->context)."
+ AND ra.active = 1
AND g.finalgrade IS NOT NULL
$groupwheresql
GROUP BY g.itemid";
@@ -990,6 +993,7 @@
WHERE gi.courseid = :courseid
AND ra.roleid $usql
AND ra.contextid ".get_related_contexts_string($this->context)."
+ AND ra.active = 1
AND g.id IS NULL
$groupwheresql
GROUP BY gi.id";
Index: user/index.php
===================================================================
RCS file: /cvsroot/moodle/moodle/user/index.php,v
retrieving revision 1.223
diff -u -r1.223 index.php
--- user/index.php 29 Oct 2008 07:16:49 -0000 1.223
+++ user/index.php 6 Nov 2008 05:56:49 -0000
@@ -462,11 +462,13 @@
AND (ul.courseid = $course->id OR ul.courseid IS NULL)
AND u.username != 'guest'
$adminroles
+ AND r.active = 1
$hiddensql ";
$where .= get_course_lastaccess_sql($accesssince);
} else {
if ($roleid >= 0) {
$where = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts)
+ AND r.active = 1
AND u.deleted = 0 $selectrole
AND u.username != 'guest'";
$where .= get_user_lastaccess_sql($accesssince);
@@ -983,6 +985,7 @@
WHERE ra.userid IN ( $userids )
AND ra.contextid in ( $contextids )
+ AND ra.active = 1
$avoidrolescond
ORDER BY ra.userid, ctx.depth DESC";
Index: user/view.php
===================================================================
RCS file: /cvsroot/moodle/moodle/user/view.php,v
retrieving revision 1.193
diff -u -r1.193 view.php
--- user/view.php 10 Sep 2008 03:25:28 -0000 1.193
+++ user/view.php 6 Nov 2008 05:56:50 -0000
@@ -42,7 +42,7 @@
if (!empty($CFG->forcelogin) || $course->id != SITEID) {
// do not force parents to enrol
- if (!$DB->get_record('role_assignments', array('userid'=>$USER->id, 'contextid'=>$usercontext->id))) {
+ if (!$DB->get_record('role_assignments', array('userid'=>$USER->id, 'contextid'=>$usercontext->id, 'active'=>1))) {
require_login($course->id);
}
}
Index: user/selector/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/user/selector/lib.php,v
retrieving revision 1.13
diff -u -r1.13 lib.php
--- user/selector/lib.php 5 Nov 2008 02:16:07 -0000 1.13
+++ user/selector/lib.php 6 Nov 2008 05:56:51 -0000
@@ -661,16 +661,13 @@
$sql = " FROM {user} u
JOIN {role_assignments} ra ON ra.userid = u.id
- JOIN {role} r ON r.id = ra.roleid
WHERE ra.contextid " . get_related_contexts_string($this->context)."
$wherecondition
AND ra.roleid IN $roleids
+ AND ra.active = 1
AND u.id NOT IN (
- SELECT u.id
- FROM {role_assignments} r, {user} u
- WHERE r.contextid = ?
- AND u.id = r.userid
- AND r.roleid = ?)";
+ SELECT ssra.userid FROM {role_assignments} ssra
+ WHERE ssra.contextid = ? AND ssra.roleid = ?)";
$order = ' ORDER BY lastname ASC, firstname ASC';
$params[] = $this->context->id;
@@ -717,11 +714,8 @@
$sql = " FROM {user}
WHERE $wherecondition
AND id NOT IN (
- SELECT u.id
- FROM {role_assignments} r, {user} u
- WHERE r.contextid = ?
- AND u.id = r.userid
- AND r.roleid = ?)";
+ SELECT ssra.userid FROM {role_assignments} ssra
+ WHERE ssra.contextid = ? AND ssra.roleid = ?)";
$order = ' ORDER BY lastname ASC, firstname ASC';
$params[] = $this->context->id;
@@ -914,6 +908,7 @@
WHERE ra.contextid " . get_related_contexts_string($context) . "
AND u.deleted = 0
AND ra.roleid $roleids
+ AND ra.active = 1
AND u.id NOT IN (SELECT userid
FROM {groups_members}
WHERE groupid = ?)
Index: course/report/participation/index.php
===================================================================
RCS file: /cvsroot/moodle/moodle/course/report/participation/index.php,v
retrieving revision 1.26
diff -u -r1.26 index.php
--- course/report/participation/index.php 5 Jun 2008 20:35:29 -0000 1.26
+++ course/report/participation/index.php 6 Nov 2008 05:56:13 -0000
@@ -189,7 +189,7 @@
FROM {role_assignments} ra
JOIN {user} u ON u.id = ra.userid
LEFT JOIN {log} l ON l.userid = ra.userid
- WHERE ra.contextid $relatedcontexts AND ra.roleid = :roleid AND
+ WHERE ra.contextid $relatedcontexts AND ra.roleid = :roleid AND ra.active = 1
(l.id IS NULL OR
(l.cmid = :instanceid AND l.time > :timefrom AND $actionsql)
)";
@@ -211,7 +211,7 @@
FROM {role_assignments} ra
JOIN {user} u ON u.id = ra.userid
LEFT OUTER JOIN {log} l ON l.userid = ra.userid
- WHERE ra.contextid $relatedcontexts AND ra.roleid = :roleid AND
+ WHERE ra.contextid $relatedcontexts AND ra.roleid = :roleid AND ra.active = 1 AND
(l.id IS NULL OR
(l.cmid = :instanceid AND l.time > :timefrom AND $actionsql)
)";
Index: mod/forum/user.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/forum/user.php,v
retrieving revision 1.39
diff -u -r1.39 user.php
--- mod/forum/user.php 5 Jul 2008 14:52:39 -0000 1.39
+++ mod/forum/user.php 6 Nov 2008 05:56:48 -0000
@@ -29,7 +29,7 @@
$usercontext = get_context_instance(CONTEXT_USER, $id);
// do not force parents to enrol
- if (!$DB->get_record('role_assignments', array('userid' => $USER->id, 'contextid' => $usercontext->id))) {
+ if (!$DB->get_record('role_assignments', array('userid' => $USER->id, 'contextid' => $usercontext->id, 'active' => 1))) {
require_course_login($course);
}
Index: version.php
===================================================================
RCS file: /cvsroot/moodle/moodle/version.php,v
retrieving revision 1.866
diff -u -r1.866 version.php
--- version.php 5 Nov 2008 02:15:44 -0000 1.866
+++ version.php 6 Nov 2008 05:56:11 -0000
@@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2008101300; // YYYYMMDD = date of the last version bump
+ $version = 2008110600; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0 dev (Build: 20081105)'; // Human-friendly version name
Index: user/filters/courserole.php
===================================================================
RCS file: /cvsroot/moodle/moodle/user/filters/courserole.php,v
retrieving revision 1.7
diff -u -r1.7 courserole.php
--- user/filters/courserole.php 2 Jun 2008 21:56:06 -0000 1.7
+++ user/filters/courserole.php 6 Nov 2008 05:56:50 -0000
@@ -95,8 +95,7 @@
return array('', $params);
}
- $timenow = round(time(), 100); // rounding - enable sql caching
- $where = "b.contextlevel=50 AND a.timestart<$timenow AND (a.timeend=0 OR a.timeend>$timenow)";
+ $where = "b.contextlevel=50 AND a.active = 1)";
if ($roleid) {
$where .= " AND a.roleid=$roleid";
}
@@ -109,8 +108,8 @@
}
return array("id IN (SELECT userid
FROM {role_assignments} a
- INNER JOIN {context} b ON a.contextid=b.id
- INNER JOIN {course} c ON b.instanceid=c.id
+ JOIN {context} b ON a.contextid=b.id
+ JOIN {course} c ON b.instanceid=c.id
WHERE $where)", $params);
}
Index: user/filters/globalrole.php
===================================================================
RCS file: /cvsroot/moodle/moodle/user/filters/globalrole.php,v
retrieving revision 1.7
diff -u -r1.7 globalrole.php
--- user/filters/globalrole.php 5 Jun 2008 20:35:29 -0000 1.7
+++ user/filters/globalrole.php 6 Nov 2008 05:56:50 -0000
@@ -63,12 +63,9 @@
global $CFG;
$value = (int)$data['value'];
- $timenow = round(time(), 100);
-
$sql = "id IN (SELECT userid
FROM {role_assignments} a
- WHERE a.contextid=".SYSCONTEXTID." AND a.roleid=$value AND a.timestart<$timenow
- AND (a.timeend=0 OR a.timeend>$timenow))";
+ WHERE a.contextid=".SYSCONTEXTID." AND a.roleid=$value AND a.active = 1)";
return array($sql, array());
}
Index: grade/import/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/grade/import/lib.php,v
retrieving revision 1.17
diff -u -r1.17 lib.php
--- grade/import/lib.php 3 Jun 2008 16:10:59 -0000 1.17
+++ grade/import/lib.php 6 Nov 2008 05:56:16 -0000
@@ -183,7 +183,8 @@
LEFT JOIN {grade_import_newitem} gin ON gin.id = giv.newgradeitem
LEFT JOIN {role_assignments} ra ON (giv.userid = ra.userid AND
ra.roleid $usql AND
- ra.contextid $relatedctxcondition)
+ ra.contextid $relatedctxcondition AND
+ ra.active = 1)
WHERE giv.importcode = ?
AND ra.id IS NULL
ORDER BY gradeidnumber, u.lastname, u.firstname";
Index: blocks/mentees/block_mentees.php
===================================================================
RCS file: /cvsroot/moodle/moodle/blocks/mentees/block_mentees.php,v
retrieving revision 1.6
diff -u -r1.6 block_mentees.php
--- blocks/mentees/block_mentees.php 2 Jun 2008 20:15:52 -0000 1.6
+++ blocks/mentees/block_mentees.php 6 Nov 2008 05:56:12 -0000
@@ -31,6 +31,7 @@
FROM {role_assignments} ra, {context} c, {user} u
WHERE ra.userid = ?
AND ra.contextid = c.id
+ AND ra.active = 1
AND c.instanceid = u.id
AND c.contextlevel = ".CONTEXT_USER, array($USER->id))) {
Index: lib/db/upgrade.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/db/upgrade.php,v
retrieving revision 1.244
diff -u -r1.244 upgrade.php
--- lib/db/upgrade.php 5 Nov 2008 00:12:30 -0000 1.244
+++ lib/db/upgrade.php 6 Nov 2008 05:56:46 -0000
@@ -873,6 +873,21 @@
upgrade_main_savepoint($result, 2008101300);
}
+ if ($result && $oldversion < 2008110600) {
+
+ /// Define field active to be added to role_assignments
+ $table = new xmldb_table('role_assignments');
+ $field = new xmldb_field('active', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'sortorder');
+
+ /// Conditionally launch add field active
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ /// Main savepoint reached
+ upgrade_main_savepoint($result, 2008110600);
+ }
+
return $result;
}
Index: lib/db/install.xml
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/db/install.xml,v
retrieving revision 1.172
diff -u -r1.172 install.xml
--- lib/db/install.xml 10 Oct 2008 18:06:16 -0000 1.172
+++ lib/db/install.xml 6 Nov 2008 05:56:45 -0000
@@ -831,7 +831,8 @@
-
+
+
Index: grade/report/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/grade/report/lib.php,v
retrieving revision 1.44
diff -u -r1.44 lib.php
--- grade/report/lib.php 28 Aug 2008 17:42:49 -0000 1.44
+++ grade/report/lib.php 6 Nov 2008 05:56:17 -0000
@@ -286,7 +286,8 @@
$groupsql
WHERE ra.roleid $usql AND u.deleted = 0
$groupwheresql
- AND ra.contextid ".get_related_contexts_string($this->context);
+ AND ra.contextid ".get_related_contexts_string($this->context)."
+ AND ra.active = 1";
return $DB->count_records_sql($countsql, $params);
}
Index: blocks/online_users/block_online_users.php
===================================================================
RCS file: /cvsroot/moodle/moodle/blocks/online_users/block_online_users.php,v
retrieving revision 1.58
diff -u -r1.58 block_online_users.php
--- blocks/online_users/block_online_users.php 2 Jun 2008 20:15:52 -0000 1.58
+++ blocks/online_users/block_online_users.php 6 Nov 2008 05:56:13 -0000
@@ -90,7 +90,7 @@
$userids = implode(',', $userids);
$sql = "SELECT userid
FROM {role_assignments}
- WHERE userid IN ($userids) AND contextid $pcontext AND hidden = 1
+ WHERE userid IN ($userids) AND contextid $pcontext AND hidden = 1 AND active = 1
GROUP BY userid";
$hidden = $DB->get_records_sql($sql);
}
Index: message/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/message/lib.php,v
retrieving revision 1.80
diff -u -r1.80 lib.php
--- message/lib.php 25 Sep 2008 22:42:58 -0000 1.80
+++ message/lib.php 6 Nov 2008 05:56:47 -0000
@@ -667,6 +667,7 @@
ON mc.contactid = u.id AND mc.userid = ?
WHERE $select
AND ra.contextid $contextlists
+ AND ra.active = 1
AND ($fullname $LIKE ?)
$except
$order", $params);
Index: blog/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/blog/lib.php,v
retrieving revision 1.100
diff -u -r1.100 lib.php
--- blog/lib.php 31 Jul 2008 22:15:31 -0000 1.100
+++ blog/lib.php 6 Nov 2008 05:56:13 -0000
@@ -568,6 +568,7 @@
FROM {post} p, {user} u, {role_assignments} ra $tagtablesql
WHERE p.userid = ra.userid $tagquerysql
AND ra.contextid ".get_related_contexts_string($context)."
+ AND ra.active = 1
AND u.id = p.userid
AND u.deleted = 0
$hiddensql $permissionsql $typesql";