From: poltawski Date: Sun, 22 Jul 2007 21:33:31 +0000 (+0000) Subject: MDL-10343 - abort early when can't create temporary tables when syning users X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=63b1cf1fe2d3ed62299f57cdd90890de7745b4b8;p=moodle.git MDL-10343 - abort early when can't create temporary tables when syning users from LDAP --- diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php index 039b5209cb..6170eabcf1 100644 --- a/auth/ldap/auth.php +++ b/auth/ldap/auth.php @@ -478,44 +478,43 @@ class auth_plugin_ldap extends auth_plugin_base { $droptablesql = array(); /// sql commands to drop the table (because session scope could be a problem for /// some persistent drivers like ODBTP (mssql) or if this function is invoked /// from within a PHP application using persistent connections + $temptable = $CFG->prefix . 'extuser'; + $createtemptablesql = ''; // configure a temp table print "Configuring temp table\n"; switch (strtolower($CFG->dbfamily)) { case 'mysql': - $temptable = $CFG->prefix . 'extuser'; $droptablesql[] = 'DROP TEMPORARY TABLE ' . $temptable; // sql command to drop the table (because session scope could be a problem) - execute_sql_arr($droptablesql, true, false); /// Drop temp table to avoid persistence problems later - echo "Creating temp table $temptable\n"; - execute_sql('CREATE TEMPORARY TABLE ' . $temptable . ' (username VARCHAR(64), PRIMARY KEY (username)) TYPE=MyISAM', false); + $createtemptablesql = 'CREATE TEMPORARY TABLE ' . $temptable . ' (username VARCHAR(64), PRIMARY KEY (username)) TYPE=MyISAM'; break; case 'postgres': - $temptable = $CFG->prefix . 'extuser'; $droptablesql[] = 'DROP TABLE ' . $temptable; // sql command to drop the table (because session scope could be a problem) - execute_sql_arr($droptablesql, true, false); /// Drop temp table to avoid persistence problems later - echo "Creating temp table $temptable\n"; $bulk_insert_records = 1; // no support for multiple sets of values - execute_sql('CREATE TEMPORARY TABLE '. $temptable . ' (username VARCHAR(64), PRIMARY KEY (username))', false); + $createtemptablesql = 'CREATE TEMPORARY TABLE '. $temptable . ' (username VARCHAR(64), PRIMARY KEY (username))'; break; case 'mssql': - $temptable = '#'.$CFG->prefix . 'extuser'; /// MSSQL temp tables begin with # + $temptable = '#'. $temptable; /// MSSQL temp tables begin with # $droptablesql[] = 'DROP TABLE ' . $temptable; // sql command to drop the table (because session scope could be a problem) - execute_sql_arr($droptablesql, true, false); /// Drop temp table to avoid persistence problems later - echo "Creating temp table $temptable\n"; $bulk_insert_records = 1; // no support for multiple sets of values - execute_sql('CREATE TABLE ' . $temptable . ' (username VARCHAR(64), PRIMARY KEY (username))', false); + $createtemptablesql = 'CREATE TABLE ' . $temptable . ' (username VARCHAR(64), PRIMARY KEY (username))'; break; case 'oracle': - $temptable = $CFG->prefix . 'extuser'; $droptablesql[] = 'TRUNCATE TABLE ' . $temptable; // oracle requires truncate before being able to drop a temp table $droptablesql[] = 'DROP TABLE ' . $temptable; // sql command to drop the table (because session scope could be a problem) - execute_sql_arr($droptablesql, true, false); /// Drop temp table to avoid persistence problems later - echo "Creating temp table $temptable\n"; $bulk_insert_records = 1; // no support for multiple sets of values - execute_sql('CREATE GLOBAL TEMPORARY TABLE '.$temptable.' (username VARCHAR(64), PRIMARY KEY (username)) ON COMMIT PRESERVE ROWS', false); + $createtemptablesql = 'CREATE GLOBAL TEMPORARY TABLE '.$temptable.' (username VARCHAR(64), PRIMARY KEY (username)) ON COMMIT PRESERVE ROWS'; break; } + + execute_sql_arr($droptablesql, true, false); /// Drop temp table to avoid persistence problems later + echo "Creating temp table $temptable\n"; + if(! execute_sql($createtemptablesql, false) ){ + print "Failed to create temporary users table - aborting\n"; + exit; + } + print "Connecting to ldap...\n"; $ldapconnection = $this->ldap_connect();