Commit 06e3f6b8 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic

Bug 1797276: escape admin reserved word in Mysql8

reserved keyword found needing to be fixed:
admin
was set to reserved in mysql 8.0.2 and then changed
back to unreserved in 8.0.12
we need this patch for the version in between them

behatnotneeded
Change-Id: Ife693b3d490ca5fd1112d0a55ff1ae74a9579aa5
parent 7a085456
......@@ -862,7 +862,7 @@ function siteoptions_submit(Pieform $form, $values) {
$fields = array_merge($fields, array('dropdownmenu'));
}
$count = 0;
$where_sql = " WHERE admin = 0 AND id != 0";
$where_sql = " WHERE \"admin\" = 0 AND id != 0";
// if default account lifetime expiry has no end date
if (empty($values['defaultaccountlifetime'])) {
if ($values['defaultaccountlifetimeupdate'] == 'all') {
......
......@@ -58,10 +58,10 @@ function adminusers_submit(Pieform $form, $values) {
db_begin();
execute_sql('UPDATE {usr}
SET admin = 0
WHERE admin = 1');
SET "admin" = 0
WHERE "admin" = 1');
execute_sql('UPDATE {usr}
SET admin = 1
SET "admin" = 1
WHERE id IN (' . join(',', array_map('intval', $values['users'])) . ')');
activity_add_admin_defaults($values['users']);
db_commit();
......
......@@ -307,8 +307,8 @@ function delete_validate(Pieform $form, $values) {
$form->set_error(null, get_string('unabletodeleteself1', 'admin'));
}
// Not allowed to remove all site admins
$siteadmins = count_records_sql("SELECT COUNT(admin) FROM {usr}
WHERE id NOT IN (" . join(',', array_map('db_quote', $users)) . ") AND admin = 1", array());
$siteadmins = count_records_sql("SELECT COUNT(\"admin\") FROM {usr}
WHERE id NOT IN (" . join(',', array_map('db_quote', $users)) . ") AND \"admin\" = 1", array());
if (!$siteadmins) {
$form->set_error(null, get_string('unabletodeletealladmins1', 'admin'));
}
......
......@@ -77,11 +77,11 @@ function adminusers_submit(Pieform $form, $values) {
db_begin();
execute_sql('UPDATE {usr_institution}
SET admin = 0
WHERE admin = 1 AND institution = ' . db_quote($inst));
SET "admin" = 0
WHERE "admin" = 1 AND institution = ' . db_quote($inst));
if ($values['users']) {
execute_sql('UPDATE {usr_institution}
SET admin = 1
SET "admin" = 1
WHERE usr IN (' . join(',', array_map('intval', $values['users'])) . ') AND institution = ' . db_quote($inst));
}
require_once('activity.php');
......
......@@ -446,7 +446,7 @@ function auth_setup () {
// out of the admin section
if (in_admin_section()) {
// Reload site admin/staff permissions
$realuser = get_record('usr', 'id', $USER->id, null, null, null, null, 'admin,staff');
$realuser = get_record('usr', 'id', $USER->id, null, null, null, null, '"admin",staff');
if (!$USER->get('admin') && $realuser->admin) {
// The user has been made into an admin
$USER->admin = 1;
......
......@@ -399,7 +399,7 @@ class PluginAuthSaml extends PluginAuth {
private static function create_certificates($numberofdays = 3650) {
global $CFG;
// Get the details of the first site admin and use it for setting up the certificate
$userid = get_record_sql('SELECT id FROM {usr} WHERE admin = 1 AND deleted = 0 ORDER BY id LIMIT 1', array());
$userid = get_record_sql('SELECT id FROM {usr} WHERE "admin" = 1 AND deleted = 0 ORDER BY id LIMIT 1', array());
$id = $userid->id;
$user = new User;
$user->find_by_id($id);
......
......@@ -42,7 +42,7 @@ $USER->reload_background_fields();
$installedtypes = get_records_assoc(
'activity_type', '', '',
'plugintype,pluginname,name',
'name,admin,plugintype,pluginname'
'name,"admin",plugintype,pluginname'
);
$options = array();
......
......@@ -31,7 +31,7 @@ $USER->reload_background_fields();
$installedtypes = get_records_assoc(
'activity_type', '', '',
'plugintype,pluginname,name',
'name,admin,plugintype,pluginname'
'name,"admin",plugintype,pluginname'
);
$options = array();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment