/** * A singleton method to create or return a single instance * of the {@link OA_DB_Table_Statistics} object. * * @static * @return OA_DB_Table_Statistics The created {@link OA_DB_Table_Statistics} object. */ function &singleton() { $static =& $GLOBALS['_OA']['TABLES'][__CLASS__]; if (!isset($static)) { $static = new OA_DB_Table_Statistics(); // Don't use a reference here! $static->init(MAX_PATH . '/etc/tables_temp_statistics.xml'); } return $static; }
/** * Tests creating/dropping all of the MPE temporary tables. * * Requirements: * Test 1: Test that all MPE temporary tables can be created and dropped. */ function testAllMaintenanceStatisticsTables() { $tmpTables = array('tmp_ad_impression', 'tmp_ad_click', 'tmp_tracker_impression_ad_impression_connection', 'tmp_tracker_impression_ad_click_connection', 'tmp_ad_connection'); // Test 1 $conf =& $GLOBALS['_MAX']['CONF']; $conf['table']['prefix'] = ''; $oDbh =& OA_DB::singleton(); foreach ($tmpTables as $tableName) { $query = "SELECT * FROM {$tableName}"; OA::disableErrorHandling(); $result = $oDbh->query($query); OA::enableErrorHandling(); $this->assertEqual(strtolower(get_class($result)), 'mdb2_error'); } $oTable =& OA_DB_Table_Statistics::singleton(); foreach ($tmpTables as $tableName) { $oTable->createTable($tableName); } $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); foreach ($tmpTables as $tableName) { // Test that the table has been created $query = "SELECT * FROM {$tableName}"; $result = $oDbh->query($query); $this->assertTrue($result); // Test that the table can be dropped // Use a different query to overcome MDB2 query buffering $query = "SELECT foo FROM {$tableName}"; OA::disableErrorHandling(); $result = $oDbh->query($query); OA::enableErrorHandling(); $this->assertEqual(strtolower(get_class($result)), 'mdb2_error'); } // Restore the testing environment TestEnv::restoreEnv(); }
static function dropTempTables() { $oDbh =& OA_DB::singleton(); // Truncate & drop all existing temporary tables $oTable =& OA_DB_Table_Priority::singleton(); foreach ($oTable->aDefinition['tables'] as $tableName => $aTable) { if ($oTable->existsTemporaryTable($tableName)) { $oTable->truncateTable($tableName); $oTable->dropTable($tableName); } } $oTable =& OA_DB_Table_Statistics::singleton(); foreach ($oTable->aDefinition['tables'] as $tableName => $aTable) { if ($oTable->existsTemporaryTable($tableName)) { $oTable->truncateTable($tableName); $oTable->dropTable($tableName); } } }