]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10343 - abort early when can't create temporary tables when syning users
authorpoltawski <poltawski>
Sun, 22 Jul 2007 21:33:31 +0000 (21:33 +0000)
committerpoltawski <poltawski>
Sun, 22 Jul 2007 21:33:31 +0000 (21:33 +0000)
from LDAP

auth/ldap/auth.php

index 039b5209cbd2ac84d1d35c8e9ec7bbbf2f7009a8..6170eabcf1e141e20aa282143d50bb53bb2b770a 100644 (file)
@@ -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();