mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
Changes throughout Moodle to remove any reserved words from the
Moodle tables. ie user -> userid in many tables, plus in user_students start -> starttime and end -> endtime I've just done all this as carefully as I could ... I don't think I missed anything but it's pretty intensive work and I'd be fooling myself if I didn't think I'd missed a couple. Note that this version should pretty much be able to bootstrap itself using PostgreSQL now ... but this is untested
This commit is contained in:
parent
1f48942e7d
commit
ebc3bd2b24
68 changed files with 277 additions and 461 deletions
|
@ -433,6 +433,8 @@ function insert_record($table, $dataobject, $returnid=true) {
|
|||
function update_record($table, $dataobject) {
|
||||
/// Update a record in a table
|
||||
/// $dataobject is an object containing needed data
|
||||
/// Relies on $dataobject having a variable "id" to
|
||||
/// specify the record to update
|
||||
|
||||
global $db, $CFG;
|
||||
|
||||
|
@ -505,21 +507,21 @@ function get_user_info_from_db($field, $value) {
|
|||
if ( $result->RecordCount() == 1 ) {
|
||||
$user = (object)$result->fields;
|
||||
|
||||
$rs = $db->Execute("SELECT course FROM {$CFG->prefix}user_students WHERE user = '$user->id' ");
|
||||
$rs = $db->Execute("SELECT course FROM {$CFG->prefix}user_students WHERE userid = '$user->id' ");
|
||||
while (!$rs->EOF) {
|
||||
$course = $rs->fields["course"];
|
||||
$user->student["$course"] = true;
|
||||
$rs->MoveNext();
|
||||
}
|
||||
|
||||
$rs = $db->Execute("SELECT course FROM {$CFG->prefix}user_teachers WHERE user = '$user->id' ");
|
||||
$rs = $db->Execute("SELECT course FROM {$CFG->prefix}user_teachers WHERE userid = '$user->id' ");
|
||||
while (!$rs->EOF) {
|
||||
$course = $rs->fields["course"];
|
||||
$user->teacher["$course"] = true;
|
||||
$rs->MoveNext();
|
||||
}
|
||||
|
||||
$rs = $db->Execute("SELECT * FROM {$CFG->prefix}user_admins WHERE user = '$user->id' ");
|
||||
$rs = $db->Execute("SELECT * FROM {$CFG->prefix}user_admins WHERE userid = '$user->id' ");
|
||||
while (!$rs->EOF) {
|
||||
$user->admin = true;
|
||||
$rs->MoveNext();
|
||||
|
@ -563,7 +565,7 @@ function adminlogin($username, $md5password) {
|
|||
return record_exists_sql("SELECT u.id
|
||||
FROM {$CFG->prefix}user u,
|
||||
{$CFG->prefix}user_admins a
|
||||
WHERE u.id = a.user
|
||||
WHERE u.id = a.userid
|
||||
AND u.username = '$username'
|
||||
AND u.password = '$md5password'");
|
||||
}
|
||||
|
@ -623,9 +625,11 @@ function get_admins() {
|
|||
|
||||
global $CFG;
|
||||
|
||||
return get_records_sql("SELECT u.* FROM {$CFG->prefix}user u, {$CFG->prefix}user_admins a
|
||||
WHERE a.user = u.id
|
||||
ORDER BY u.id ASC");
|
||||
return get_records_sql("SELECT u.*
|
||||
FROM {$CFG->prefix}user u,
|
||||
{$CFG->prefix}user_admins a
|
||||
WHERE a.userid = u.id
|
||||
ORDER BY u.id ASC");
|
||||
}
|
||||
|
||||
|
||||
|
@ -651,7 +655,7 @@ function get_course_students($courseid, $sort="u.lastaccess DESC") {
|
|||
global $CFG;
|
||||
|
||||
return get_records_sql("SELECT u.* FROM {$CFG->prefix}user u, {$CFG->prefix}user_students s
|
||||
WHERE s.course = '$courseid' AND s.user = u.id AND u.deleted = '0'
|
||||
WHERE s.course = '$courseid' AND s.userid = u.id AND u.deleted = '0'
|
||||
ORDER BY $sort");
|
||||
}
|
||||
|
||||
|
@ -661,7 +665,7 @@ function get_course_teachers($courseid, $sort="t.authority ASC") {
|
|||
global $CFG;
|
||||
|
||||
return get_records_sql("SELECT u.*,t.authority,t.role FROM {$CFG->prefix}user u, {$CFG->prefix}user_teachers t
|
||||
WHERE t.course = '$courseid' AND t.user = u.id AND u.deleted = '0'
|
||||
WHERE t.course = '$courseid' AND t.userid = u.id AND u.deleted = '0'
|
||||
ORDER BY $sort");
|
||||
}
|
||||
|
||||
|
@ -680,8 +684,8 @@ function get_course_users($courseid, $sort="u.lastaccess DESC") {
|
|||
}
|
||||
|
||||
/// return get_records_sql("SELECT u.* FROM user u, user_students s, user_teachers t
|
||||
/// WHERE (s.course = '$courseid' AND s.user = u.id) OR
|
||||
/// (t.course = '$courseid' AND t.user = u.id)
|
||||
/// WHERE (s.course = '$courseid' AND s.userid = u.id) OR
|
||||
/// (t.course = '$courseid' AND t.userid = u.id)
|
||||
/// ORDER BY $sort");
|
||||
}
|
||||
|
||||
|
@ -743,7 +747,7 @@ function get_users_longtimenosee($cutofftime) {
|
|||
{$CFG->prefix}user_students s
|
||||
WHERE lastaccess > '0'
|
||||
AND lastaccess < '$cutofftime'
|
||||
AND u.id = s.user
|
||||
AND u.id = s.userid
|
||||
GROUP BY u.id");
|
||||
}
|
||||
|
||||
|
@ -821,15 +825,23 @@ function add_to_log($course, $module, $action, $url="", $info="") {
|
|||
$timenow = time();
|
||||
$info = addslashes($info);
|
||||
|
||||
$result = $db->Execute("INSERT INTO log
|
||||
SET time = '$timenow',
|
||||
user = '$USER->id',
|
||||
course = '$course',
|
||||
ip = '$REMOTE_ADDR',
|
||||
module = '$module',
|
||||
action = '$action',
|
||||
url = '$url',
|
||||
info = '$info'");
|
||||
$result = $db->Execute("INSERT INTO log (time,
|
||||
userid,
|
||||
course,
|
||||
ip,
|
||||
module,
|
||||
action,
|
||||
url,
|
||||
info)
|
||||
VALUES ('$timenow',
|
||||
'$USER->id',
|
||||
'$course',
|
||||
'$REMOTE_ADDR',
|
||||
'$module',
|
||||
'$action',
|
||||
'$url',
|
||||
'$info')");
|
||||
|
||||
if (!$result) {
|
||||
echo "<P>Error: Could not insert a new entry to the Moodle log</P>"; // Don't throw an error
|
||||
}
|
||||
|
@ -850,7 +862,7 @@ function get_logs_usercourse($userid, $courseid, $coursestart) {
|
|||
|
||||
return get_records_sql("SELECT floor((`time` - $coursestart)/86400) as day, count(*) as num
|
||||
FROM {$CFG->prefix}log
|
||||
WHERE user = '$userid'
|
||||
WHERE userid = '$userid'
|
||||
AND course = '$courseid'
|
||||
AND `time` > '$coursestart'
|
||||
GROUP BY day ");
|
||||
|
@ -861,7 +873,7 @@ function get_logs_userday($userid, $courseid, $daystart) {
|
|||
|
||||
return get_records_sql("SELECT floor((`time` - $daystart)/3600) as hour, count(*) as num
|
||||
FROM {$CFG->prefix}log
|
||||
WHERE user = '$userid'
|
||||
WHERE userid = '$userid'
|
||||
AND course = '$courseid'
|
||||
AND `time` > '$daystart'
|
||||
GROUP BY hour ");
|
||||
|
|
|
@ -216,6 +216,15 @@ function main_upgrade($oldversion=0) {
|
|||
set_config("guestloginbutton", 1);
|
||||
}
|
||||
|
||||
if ($oldversion < 2002122300) {
|
||||
execute_sql("ALTER TABLE `log` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
|
||||
execute_sql("ALTER TABLE `user_admins` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
|
||||
execute_sql("ALTER TABLE `user_students` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
|
||||
execute_sql("ALTER TABLE `user_teachers` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
|
||||
execute_sql("ALTER TABLE `user_students` CHANGE `start` `timestart` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
|
||||
execute_sql("ALTER TABLE `user_students` CHANGE `end` `timeend` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ CREATE TABLE `prefix_course_sections` (
|
|||
CREATE TABLE `prefix_log` (
|
||||
`id` int(10) unsigned NOT NULL auto_increment,
|
||||
`time` int(10) unsigned NOT NULL default '0',
|
||||
`user` int(10) unsigned NOT NULL default '0',
|
||||
`userid` int(10) unsigned NOT NULL default '0',
|
||||
`ip` varchar(15) NOT NULL default '',
|
||||
`course` int(10) unsigned NOT NULL default '0',
|
||||
`module` varchar(10) NOT NULL default '',
|
||||
|
@ -191,7 +191,7 @@ CREATE TABLE `prefix_user` (
|
|||
|
||||
CREATE TABLE `prefix_user_admins` (
|
||||
`id` int(10) unsigned NOT NULL auto_increment,
|
||||
`user` int(10) unsigned NOT NULL default '0',
|
||||
`userid` int(10) unsigned NOT NULL default '0',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id` (`id`)
|
||||
) TYPE=MyISAM COMMENT='One record per administrator user';
|
||||
|
@ -203,10 +203,10 @@ CREATE TABLE `prefix_user_admins` (
|
|||
|
||||
CREATE TABLE `prefix_user_students` (
|
||||
`id` int(10) unsigned NOT NULL auto_increment,
|
||||
`user` int(10) unsigned NOT NULL default '0',
|
||||
`userid` int(10) unsigned NOT NULL default '0',
|
||||
`course` int(10) unsigned NOT NULL default '0',
|
||||
`start` int(10) unsigned NOT NULL default '0',
|
||||
`end` int(10) unsigned NOT NULL default '0',
|
||||
`timestart` int(10) unsigned NOT NULL default '0',
|
||||
`timeend` int(10) unsigned NOT NULL default '0',
|
||||
`time` int(10) unsigned NOT NULL default '0',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id` (`id`)
|
||||
|
@ -219,7 +219,7 @@ CREATE TABLE `prefix_user_students` (
|
|||
|
||||
CREATE TABLE `prefix_user_teachers` (
|
||||
`id` int(10) unsigned NOT NULL auto_increment,
|
||||
`user` int(10) unsigned NOT NULL default '0',
|
||||
`userid` int(10) unsigned NOT NULL default '0',
|
||||
`course` int(10) unsigned NOT NULL default '0',
|
||||
`authority` int(10) NOT NULL default '3',
|
||||
`role` varchar(40) NOT NULL default '',
|
||||
|
|
|
@ -54,7 +54,7 @@ CREATE TABLE course_sections (
|
|||
CREATE TABLE log (
|
||||
id SERIAL PRIMARY KEY,
|
||||
time integer NOT NULL default '0',
|
||||
"user" integer NOT NULL default '0',
|
||||
userid integer NOT NULL default '0',
|
||||
ip varchar(15) NOT NULL default '',
|
||||
course integer NOT NULL default '0',
|
||||
module varchar(10) NOT NULL default '',
|
||||
|
@ -115,21 +115,21 @@ CREATE TABLE "user" (
|
|||
|
||||
CREATE TABLE user_admins (
|
||||
id SERIAL PRIMARY KEY,
|
||||
"user" integer NOT NULL default '0'
|
||||
userid integer NOT NULL default '0'
|
||||
);
|
||||
|
||||
CREATE TABLE user_students (
|
||||
id SERIAL PRIMARY KEY,
|
||||
"user" integer NOT NULL default '0',
|
||||
userid integer NOT NULL default '0',
|
||||
course integer NOT NULL default '0',
|
||||
"start" integer NOT NULL default '0',
|
||||
"end" integer NOT NULL default '0',
|
||||
timestart integer NOT NULL default '0',
|
||||
timeend integer NOT NULL default '0',
|
||||
time integer NOT NULL default '0'
|
||||
);
|
||||
|
||||
CREATE TABLE user_teachers (
|
||||
id SERIAL PRIMARY KEY,
|
||||
"user" integer NOT NULL default '0',
|
||||
userid integer NOT NULL default '0',
|
||||
course integer NOT NULL default '0',
|
||||
authority integer NOT NULL default '3',
|
||||
role varchar(40) NOT NULL default ''
|
||||
|
|
|
@ -358,10 +358,10 @@ function isadmin($userid=0) {
|
|||
global $USER;
|
||||
|
||||
if (!$userid) {
|
||||
return record_exists("user_admins", "user", $USER->id);
|
||||
return record_exists("user_admins", "userid", $USER->id);
|
||||
}
|
||||
|
||||
return record_exists("user_admins", "user", $userid);
|
||||
return record_exists("user_admins", "userid", $userid);
|
||||
}
|
||||
|
||||
|
||||
|
@ -377,7 +377,7 @@ function isteacher($courseid, $userid=0) {
|
|||
return $USER->teacher[$courseid];
|
||||
}
|
||||
|
||||
return record_exists("user_teachers", "user", $userid, "course", $courseid);
|
||||
return record_exists("user_teachers", "userid", $userid, "course", $courseid);
|
||||
}
|
||||
|
||||
|
||||
|
@ -389,9 +389,9 @@ function isstudent($courseid, $userid=0) {
|
|||
return $USER->student[$courseid];
|
||||
}
|
||||
|
||||
$timenow = time(); // todo: add time check below
|
||||
// $timenow = time(); // todo: add time check below
|
||||
|
||||
return record_exists("user_students", "user", $userid, "course", $courseid);
|
||||
return record_exists("user_students", "userid", $userid, "course", $courseid);
|
||||
}
|
||||
|
||||
function isguest($userid=0) {
|
||||
|
@ -519,13 +519,13 @@ function enrol_student($user, $course) {
|
|||
/// Enrols a student in a given course
|
||||
global $db;
|
||||
|
||||
$record->user = $user;
|
||||
$record->userid = $user;
|
||||
$record->course = $course;
|
||||
$record->start = 0;
|
||||
$record->end = 0;
|
||||
$record->time = time();
|
||||
|
||||
return insert_record("user", $record);
|
||||
return insert_record("user_students", $record);
|
||||
}
|
||||
|
||||
function unenrol_student($user, $course=0) {
|
||||
|
@ -536,14 +536,14 @@ function unenrol_student($user, $course=0) {
|
|||
/// First delete any crucial stuff that might still send mail
|
||||
if ($forums = get_records("forum", "course", $course)) {
|
||||
foreach ($forums as $forum) {
|
||||
delete_records("forum_subscriptions", "forum", $forum->id, "user", $user);
|
||||
delete_records("forum_subscriptions", "forum", $forum->id, "userid", $user);
|
||||
}
|
||||
}
|
||||
return delete_records("user_students", "user", $user, "course", $course);
|
||||
return delete_records("user_students", "userid", $user, "course", $course);
|
||||
|
||||
} else {
|
||||
delete_records("forum_subscriptions", "user", $user);
|
||||
return delete_records("user_students", "user", $user);
|
||||
delete_records("forum_subscriptions", "userid", $user);
|
||||
return delete_records("user_students", "userid", $user);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -556,13 +556,13 @@ function remove_teacher($user, $course=0) {
|
|||
/// First delete any crucial stuff that might still send mail
|
||||
if ($forums = get_records("forum", "course", $course)) {
|
||||
foreach ($forums as $forum) {
|
||||
delete_records("forum_subscriptions", "forum", $forum->id, "user", $user);
|
||||
delete_records("forum_subscriptions", "forum", $forum->id, "userid", $user);
|
||||
}
|
||||
}
|
||||
return delete_records("user_teachers", "user", $user, "course", $course);
|
||||
return delete_records("user_teachers", "userid", $user, "course", $course);
|
||||
} else {
|
||||
delete_records("forum_subscriptions", "user", $user);
|
||||
return delete_records("user_teachers", "user", $user);
|
||||
delete_records("forum_subscriptions", "userid", $user);
|
||||
return delete_records("user_teachers", "userid", $user);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -570,7 +570,7 @@ function remove_admin($user) {
|
|||
/// Removes an admin from a site
|
||||
global $db;
|
||||
|
||||
return delete_records("user_admins", "user", $user);
|
||||
return delete_records("user_admins", "userid", $user);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue