Commit de470bec authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon
Browse files

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
(cherry picked from commit 06e3f6b8)
parent 16dec02d
...@@ -862,7 +862,7 @@ function siteoptions_submit(Pieform $form, $values) { ...@@ -862,7 +862,7 @@ function siteoptions_submit(Pieform $form, $values) {
$fields = array_merge($fields, array('dropdownmenu')); $fields = array_merge($fields, array('dropdownmenu'));
} }
$count = 0; $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 default account lifetime expiry has no end date
if (empty($values['defaultaccountlifetime'])) { if (empty($values['defaultaccountlifetime'])) {
if ($values['defaultaccountlifetimeupdate'] == 'all') { if ($values['defaultaccountlifetimeupdate'] == 'all') {
......
...@@ -58,10 +58,10 @@ function adminusers_submit(Pieform $form, $values) { ...@@ -58,10 +58,10 @@ function adminusers_submit(Pieform $form, $values) {
db_begin(); db_begin();
execute_sql('UPDATE {usr} execute_sql('UPDATE {usr}
SET admin = 0 SET "admin" = 0
WHERE admin = 1'); WHERE "admin" = 1');
execute_sql('UPDATE {usr} execute_sql('UPDATE {usr}
SET admin = 1 SET "admin" = 1
WHERE id IN (' . join(',', array_map('intval', $values['users'])) . ')'); WHERE id IN (' . join(',', array_map('intval', $values['users'])) . ')');
activity_add_admin_defaults($values['users']); activity_add_admin_defaults($values['users']);
db_commit(); db_commit();
......
...@@ -307,8 +307,8 @@ function delete_validate(Pieform $form, $values) { ...@@ -307,8 +307,8 @@ function delete_validate(Pieform $form, $values) {
$form->set_error(null, get_string('unabletodeleteself1', 'admin')); $form->set_error(null, get_string('unabletodeleteself1', 'admin'));
} }
// Not allowed to remove all site admins // Not allowed to remove all site admins
$siteadmins = count_records_sql("SELECT COUNT(admin) FROM {usr} $siteadmins = count_records_sql("SELECT COUNT(\"admin\") FROM {usr}
WHERE id NOT IN (" . join(',', array_map('db_quote', $users)) . ") AND admin = 1", array()); WHERE id NOT IN (" . join(',', array_map('db_quote', $users)) . ") AND \"admin\" = 1", array());
if (!$siteadmins) { if (!$siteadmins) {
$form->set_error(null, get_string('unabletodeletealladmins1', 'admin')); $form->set_error(null, get_string('unabletodeletealladmins1', 'admin'));
} }
......
...@@ -77,11 +77,11 @@ function adminusers_submit(Pieform $form, $values) { ...@@ -77,11 +77,11 @@ function adminusers_submit(Pieform $form, $values) {
db_begin(); db_begin();
execute_sql('UPDATE {usr_institution} execute_sql('UPDATE {usr_institution}
SET admin = 0 SET "admin" = 0
WHERE admin = 1 AND institution = ' . db_quote($inst)); WHERE "admin" = 1 AND institution = ' . db_quote($inst));
if ($values['users']) { if ($values['users']) {
execute_sql('UPDATE {usr_institution} 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)); WHERE usr IN (' . join(',', array_map('intval', $values['users'])) . ') AND institution = ' . db_quote($inst));
} }
require_once('activity.php'); require_once('activity.php');
......
...@@ -446,7 +446,7 @@ function auth_setup () { ...@@ -446,7 +446,7 @@ function auth_setup () {
// out of the admin section // out of the admin section
if (in_admin_section()) { if (in_admin_section()) {
// Reload site admin/staff permissions // 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) { if (!$USER->get('admin') && $realuser->admin) {
// The user has been made into an admin // The user has been made into an admin
$USER->admin = 1; $USER->admin = 1;
......
...@@ -399,7 +399,7 @@ class PluginAuthSaml extends PluginAuth { ...@@ -399,7 +399,7 @@ class PluginAuthSaml extends PluginAuth {
private static function create_certificates($numberofdays = 3650) { private static function create_certificates($numberofdays = 3650) {
global $CFG; global $CFG;
// Get the details of the first site admin and use it for setting up the certificate // 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; $id = $userid->id;
$user = new User; $user = new User;
$user->find_by_id($id); $user->find_by_id($id);
......
...@@ -42,7 +42,7 @@ $USER->reload_background_fields(); ...@@ -42,7 +42,7 @@ $USER->reload_background_fields();
$installedtypes = get_records_assoc( $installedtypes = get_records_assoc(
'activity_type', '', '', 'activity_type', '', '',
'plugintype,pluginname,name', 'plugintype,pluginname,name',
'name,admin,plugintype,pluginname' 'name,"admin",plugintype,pluginname'
); );
$options = array(); $options = array();
......
...@@ -31,7 +31,7 @@ $USER->reload_background_fields(); ...@@ -31,7 +31,7 @@ $USER->reload_background_fields();
$installedtypes = get_records_assoc( $installedtypes = get_records_assoc(
'activity_type', '', '', 'activity_type', '', '',
'plugintype,pluginname,name', 'plugintype,pluginname,name',
'name,admin,plugintype,pluginname' 'name,"admin",plugintype,pluginname'
); );
$options = array(); $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