From a66b2ae4f4e1dd59208e637ea36fb5b0ce146686 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sun, 15 Apr 2012 12:21:31 +0200 Subject: [PATCH] MDL-32434 deprecate drop_temp_table() in favour of drop_table() --- auth/ldap/auth.php | 2 +- .../dbops/backup_controller_dbops.class.php | 2 +- .../dbops/restore_controller_dbops.class.php | 2 +- backup/util/dbops/simpletest/testdbops.php | 2 +- backup/util/dbops/tests/dbops_test.php | 2 +- lib/ddl/database_manager.php | 14 +++---------- lib/ddl/mssql_sql_generator.php | 11 ---------- lib/ddl/mysql_sql_generator.php | 11 ---------- lib/ddl/oracle_sql_generator.php | 11 ---------- lib/ddl/postgres_sql_generator.php | 11 ---------- lib/ddl/simpletest/testddl.php | 10 +++++----- lib/ddl/sql_generator.php | 11 +--------- lib/ddl/tests/ddl_test.php | 20 ++++++++++--------- lib/dml/moodle_temptables.php | 2 +- 14 files changed, 26 insertions(+), 85 deletions(-) diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php index d1572a357e0..881887cbd71 100644 --- a/auth/ldap/auth.php +++ b/auth/ldap/auth.php @@ -862,7 +862,7 @@ class auth_plugin_ldap extends auth_plugin_base { print_string('nouserstobeadded', 'auth_ldap'); } - $dbman->drop_temp_table($table); + $dbman->drop_table($table); $this->ldap_close(); return true; diff --git a/backup/util/dbops/backup_controller_dbops.class.php b/backup/util/dbops/backup_controller_dbops.class.php index dffdb8d73a0..ac4725de668 100644 --- a/backup/util/dbops/backup_controller_dbops.class.php +++ b/backup/util/dbops/backup_controller_dbops.class.php @@ -147,7 +147,7 @@ abstract class backup_controller_dbops extends backup_dbops { $targettablename = 'backup_ids_temp'; $table = new xmldb_table($targettablename); - $dbman->drop_temp_table($table); // And drop it + $dbman->drop_table($table); // And drop it } /** diff --git a/backup/util/dbops/restore_controller_dbops.class.php b/backup/util/dbops/restore_controller_dbops.class.php index e3e2d00908a..dc0152f2612 100644 --- a/backup/util/dbops/restore_controller_dbops.class.php +++ b/backup/util/dbops/restore_controller_dbops.class.php @@ -105,7 +105,7 @@ abstract class restore_controller_dbops extends restore_dbops { $targettablenames = array('backup_ids_temp', 'backup_files_temp'); foreach ($targettablenames as $targettablename) { $table = new xmldb_table($targettablename); - $dbman->drop_temp_table($table); // And drop it + $dbman->drop_table($table); // And drop it } } } diff --git a/backup/util/dbops/simpletest/testdbops.php b/backup/util/dbops/simpletest/testdbops.php index 5a4af22ea35..0d875365db2 100644 --- a/backup/util/dbops/simpletest/testdbops.php +++ b/backup/util/dbops/simpletest/testdbops.php @@ -242,7 +242,7 @@ class backup_dbops_test extends UnitTestCase { // backup_ids_temp table tests // If, for any reason table exists, drop it if ($dbman->table_exists('backup_ids_temp')) { - $dbman->drop_temp_table(new xmldb_table('backup_ids_temp')); + $dbman->drop_table(new xmldb_table('backup_ids_temp')); } // Check backup_ids_temp table doesn't exist $this->assertFalse($dbman->table_exists('backup_ids_temp')); diff --git a/backup/util/dbops/tests/dbops_test.php b/backup/util/dbops/tests/dbops_test.php index 43682a53dc5..dc02ad9ca38 100644 --- a/backup/util/dbops/tests/dbops_test.php +++ b/backup/util/dbops/tests/dbops_test.php @@ -138,7 +138,7 @@ class backup_dbops_testcase extends advanced_testcase { // backup_ids_temp table tests // If, for any reason table exists, drop it if ($dbman->table_exists('backup_ids_temp')) { - $dbman->drop_temp_table(new xmldb_table('backup_ids_temp')); + $dbman->drop_table(new xmldb_table('backup_ids_temp')); } // Check backup_ids_temp table doesn't exist $this->assertFalse($dbman->table_exists('backup_ids_temp')); diff --git a/lib/ddl/database_manager.php b/lib/ddl/database_manager.php index c4409d02d01..ee6f9bd9dc0 100644 --- a/lib/ddl/database_manager.php +++ b/lib/ddl/database_manager.php @@ -459,21 +459,13 @@ class database_manager { * * It is recommended to drop temp table when not used anymore. * + * @deprecated since 2.3, use drop_table() for all table types * @param xmldb_table $xmldb_table Table object. * @return void */ public function drop_temp_table(xmldb_table $xmldb_table) { - - /// Check table doesn't exist - if (!$this->table_exists($xmldb_table)) { - throw new ddl_table_missing_exception($xmldb_table->getName()); - } - - if (!$sqlarr = $this->generator->getDropTempTableSQL($xmldb_table)) { - throw new ddl_exception('ddlunknownerror', null, 'temp table drop sql not generated'); - } - - $this->execute_sql_arr($sqlarr); + debugging('database_manager::drop_temp_table() is deprecated, use database_manager::drop_table() instead'); + $this->drop_table($xmldb_table); } /** diff --git a/lib/ddl/mssql_sql_generator.php b/lib/ddl/mssql_sql_generator.php index 5593d71ea78..ed9942e17a9 100644 --- a/lib/ddl/mssql_sql_generator.php +++ b/lib/ddl/mssql_sql_generator.php @@ -150,17 +150,6 @@ class mssql_sql_generator extends sql_generator { return $sqlarr; } - /** - * Given one correct xmldb_table, returns the SQL statements - * to drop it (inside one array) - * - * @param xmldb_table $xmldb_table The table to drop. - * @return array SQL statement(s) for dropping the specified table. - */ - public function getDropTempTableSQL($xmldb_table) { - return $this->getDropTableSQL($xmldb_table); - } - /** * Given one XMLDB Type, lenght and decimals, returns the DB proper SQL type */ diff --git a/lib/ddl/mysql_sql_generator.php b/lib/ddl/mysql_sql_generator.php index 9f27186e534..801d7401e0f 100644 --- a/lib/ddl/mysql_sql_generator.php +++ b/lib/ddl/mysql_sql_generator.php @@ -149,17 +149,6 @@ class mysql_sql_generator extends sql_generator { return $sqlarr; } - /** - * Given one correct xmldb_table, returns the SQL statements - * to drop it (inside one array) - * - * @param xmldb_table $xmldb_table The table to drop. - * @return array SQL statement(s) for dropping the specified table. - */ - public function getDropTempTableSQL($xmldb_table) { - return $this->getDropTableSQL($xmldb_table); - } - /** * Given one XMLDB Type, length and decimals, returns the DB proper SQL type */ diff --git a/lib/ddl/oracle_sql_generator.php b/lib/ddl/oracle_sql_generator.php index 2d622a2fabd..312c97d4e03 100644 --- a/lib/ddl/oracle_sql_generator.php +++ b/lib/ddl/oracle_sql_generator.php @@ -137,17 +137,6 @@ class oracle_sql_generator extends sql_generator { return $sqlarr; } - /** - * Given one correct xmldb_table, returns the SQL statements - * to drop it (inside one array) - * - * @param xmldb_table $xmldb_table The table to drop. - * @return array SQL statement(s) for dropping the specified table. - */ - public function getDropTempTableSQL($xmldb_table) { - return $this->getDropTableSQL($xmldb_table); - } - /** * Given one XMLDB Type, length and decimals, returns the DB proper SQL type */ diff --git a/lib/ddl/postgres_sql_generator.php b/lib/ddl/postgres_sql_generator.php index de22c537966..46436fc8156 100644 --- a/lib/ddl/postgres_sql_generator.php +++ b/lib/ddl/postgres_sql_generator.php @@ -100,17 +100,6 @@ class postgres_sql_generator extends sql_generator { return $sqlarr; } - /** - * Given one correct xmldb_table, returns the SQL statements - * to drop it (inside one array) - * - * @param xmldb_table $xmldb_table The table to drop. - * @return array SQL statement(s) for dropping the specified table. - */ - public function getDropTempTableSQL($xmldb_table) { - return $this->getDropTableSQL($xmldb_table); - } - /** * Given one XMLDB Type, length and decimals, returns the DB proper SQL type */ diff --git a/lib/ddl/simpletest/testddl.php b/lib/ddl/simpletest/testddl.php index 3224ecdaa7e..40a0d3d14cb 100644 --- a/lib/ddl/simpletest/testddl.php +++ b/lib/ddl/simpletest/testddl.php @@ -1540,13 +1540,13 @@ class ddl_test extends UnitTestCase { $this->assertEqual($records[2]->intro, $this->records['test_table1'][1]->intro); // Drop table1 - $dbman->drop_temp_table($table1); + $dbman->drop_table($table1); $this->assertFalse($dbman->table_exists('test_table1')); // Try to drop non-existing temp table, must throw exception $noetable = $this->tables['test_table1']; try { - $dbman->drop_temp_table($noetable); + $dbman->drop_table($noetable); $this->assertTrue(false); } catch (Exception $e) { $this->assertTrue($e instanceof ddl_table_missing_exception); @@ -1556,7 +1556,7 @@ class ddl_test extends UnitTestCase { // TODO: that's // Drop table0 - $dbman->drop_temp_table($table0); + $dbman->drop_table($table0); $this->assertFalse($dbman->table_exists('test_table0')); // Have dropped all these temp tables here, to avoid conflicts with other (normal tables) tests! @@ -1598,12 +1598,12 @@ class ddl_test extends UnitTestCase { $this->assertTrue($dbman2->table_exists('test_table1')); $inserted = $DB2->insert_record('test_table1', $record2); - $dbman2->drop_temp_table($table); // Drop temp table before closing DB2 + $dbman2->drop_table($table); // Drop temp table before closing DB2 $this->assertFalse($dbman2->table_exists('test_table1')); $DB2->dispose(); // Close DB2 $this->assertTrue($dbman->table_exists('test_table1')); // Check table continues existing for DB - $dbman->drop_temp_table($table); // Drop temp table + $dbman->drop_table($table); // Drop temp table $this->assertFalse($dbman->table_exists('test_table1')); } diff --git a/lib/ddl/sql_generator.php b/lib/ddl/sql_generator.php index cb187290870..4cc1eedb8b3 100644 --- a/lib/ddl/sql_generator.php +++ b/lib/ddl/sql_generator.php @@ -660,7 +660,7 @@ abstract class sql_generator { /** * Given one correct xmldb_table and the new name, returns the SQL statements - * to drop it (inside one array). + * to drop it (inside one array). Works also for temporary tables. * * @param xmldb_table $xmldb_table The table to drop. * @return array SQL statement(s) for dropping the specified table. @@ -1290,15 +1290,6 @@ abstract class sql_generator { */ abstract public function getCreateTempTableSQL($xmldb_table); - /** - * Given one correct xmldb_table and the new name, returns the SQL statements. - * to drop it (inside one array). - * - * @param xmldb_table $xmldb_table The xmldb_table object instance. - * @return array SQL statements. - */ - abstract public function getDropTempTableSQL($xmldb_table); - /** * Given one XMLDB Type, length and decimals, returns the DB proper SQL type. * diff --git a/lib/ddl/tests/ddl_test.php b/lib/ddl/tests/ddl_test.php index 11ca8854d02..352202f4190 100644 --- a/lib/ddl/tests/ddl_test.php +++ b/lib/ddl/tests/ddl_test.php @@ -1466,6 +1466,8 @@ class ddl_testcase extends database_driver_testcase { } public function test_temp_tables() { + global $CFG; + $DB = $this->tdb; // do not use global $DB! $dbman = $this->tdb->get_manager(); @@ -1514,13 +1516,13 @@ class ddl_testcase extends database_driver_testcase { $this->assertEquals($records[2]->intro, $this->records['test_table1'][1]->intro); // Drop table1 - $dbman->drop_temp_table($table1); + $dbman->drop_table($table1); $this->assertFalse($dbman->table_exists('test_table1')); // Try to drop non-existing temp table, must throw exception $noetable = $this->tables['test_table1']; try { - $dbman->drop_temp_table($noetable); + $dbman->drop_table($noetable); $this->assertTrue(false); } catch (Exception $e) { $this->assertTrue($e instanceof ddl_table_missing_exception); @@ -1530,7 +1532,7 @@ class ddl_testcase extends database_driver_testcase { // TODO: that's // Drop table0 - $dbman->drop_temp_table($table0); + $dbman->drop_table($table0); $this->assertFalse($dbman->table_exists('test_table0')); // Create another temp table1 @@ -1538,11 +1540,11 @@ class ddl_testcase extends database_driver_testcase { $dbman->create_temp_table($table1); $this->assertTrue($dbman->table_exists('test_table1')); - // make sure it can be dropped using normal drop_table() - since 2.3 - $dbman->drop_table($table1); + // Make sure it can be dropped using deprecated drop_temp_table() + $CFG->debug = 0; + $dbman->drop_temp_table($table1); $this->assertFalse($dbman->table_exists('test_table1')); - - // Have dropped all these temp tables here, to avoid conflicts with other (normal tables) tests! + $CFG->debug = DEBUG_DEVELOPER; } public function test_concurrent_temp_tables() { @@ -1581,12 +1583,12 @@ class ddl_testcase extends database_driver_testcase { $this->assertTrue($dbman2->table_exists('test_table1')); $inserted = $DB2->insert_record('test_table1', $record2); - $dbman2->drop_temp_table($table); // Drop temp table before closing DB2 + $dbman2->drop_table($table); // Drop temp table before closing DB2 $this->assertFalse($dbman2->table_exists('test_table1')); $DB2->dispose(); // Close DB2 $this->assertTrue($dbman->table_exists('test_table1')); // Check table continues existing for DB - $dbman->drop_temp_table($table); // Drop temp table + $dbman->drop_table($table); // Drop temp table $this->assertFalse($dbman->table_exists('test_table1')); } diff --git a/lib/dml/moodle_temptables.php b/lib/dml/moodle_temptables.php index 505292c6798..c89348ae1da 100644 --- a/lib/dml/moodle_temptables.php +++ b/lib/dml/moodle_temptables.php @@ -131,7 +131,7 @@ class moodle_temptables { if ($temptables = $this->get_temptables()) { error_log('Potential coding error - existing temptables found when disposing database. Must be dropped!'); foreach ($temptables as $temptable) { - $this->mdb->get_manager()->drop_temp_table(new xmldb_table($temptable)); + $this->mdb->get_manager()->drop_table(new xmldb_table($temptable)); } } $this->mdb = null;