/** * sets the list of tables and definitions * for use in generating the dataobjects * * table definitions are provided by OA_DB_Table * which uses mdb2schema an xml schema file * * this method unsets any excluded tables * and stores the db_dataobject datatype * */ function _createTableList($schema = '') { $options =& PEAR::getStaticProperty('DB_DataObject', 'options'); $oTable = new OA_DB_Table(); $oTable->init($schema, false); $aDefinition = $oTable->aDefinition['tables']; if (isset($options['generator_exclude_regex'])) { foreach ($aDefinition as $table => $aTable) { if (preg_match($options['generator_exclude_regex'], $table)) { unset($oTable->aDefinition['tables'][$table]); } else { foreach ($aTable['fields'] as $field => $aField) { $openxType = $aField['type']; $mdb2Type = $oTable->oDbh->datatype->mapPrepareDatatype($openxType); $aField['type'] = $mdb2Type; $dboType = $this->deriveDataType($aField, $oTable->oDbh->phptype); $oTable->aDefinition['tables'][$table]['fields'][$field]['oxtype'] = $openxType; $oTable->aDefinition['tables'][$table]['fields'][$field]['type'] = $mdb2Type; $oTable->aDefinition['tables'][$table]['fields'][$field]['dbotype'] = $dboType; //$this->debug("{$table}.{$field} type map :: {$openxType} => {$mdb2Type} => {$dboType} \n"); } } } } $this->_definitions = $oTable->aDefinition['tables']; $this->tables = $this->_definitions; }
function test_runScript() { $GLOBALS['_MAX']['CONF']['table']['prefix'] = $this->prefix; $oUpgrade = new OA_Upgrade(); $oUpgrade->initDatabaseConnection(); $oDbh =& $oUpgrade->oDbh; $oTable = new OA_DB_Table(); $testfile = MAX_PATH . "/etc/changes/tests/data/schema_tables_core_dashboard.xml"; $oTable->init($testfile); $table = 'preference'; $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); if (in_array($this->prefix . $table, $aExistingTables)) { $this->assertTrue($oTable->dropTable($this->prefix . $table), 'error dropping ' . $this->prefix . $table); } $this->assertTrue($oTable->createTable($table), 'error creating ' . $this->prefix . $table); $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); $this->assertTrue(in_array($this->prefix . $table, $aExistingTables), $this->prefix . $table . ' table not found'); $this->assertTrue($oUpgrade->runScript('postscript_openads_upgrade_2.3.36-beta-rc1.php')); $aExistingColumns = $oDbh->manager->listTableFields($this->prefix . $table); $aColumns = array('ad_clicks_sum', 'ad_views_sum', 'ad_clicks_per_second', 'ad_views_per_second', 'ad_cs_data_last_sent', 'ad_cs_data_last_sent', 'ad_cs_data_last_received'); foreach ($aColumns as $column) { $this->assertFalse(in_array($column, $aExistingColumns, $column . ' found in column list')); } TestEnv::restoreConfig(); TestEnv::restoreEnv(); }
function _dropAuditTable($table_name) { $oTable = new OA_DB_Table(); $aDBTables = OA_DB_Table::listOATablesCaseSensitive(); if (in_array($table_name, $aDBTables)) { $this->assertTrue($oTable->dropTable($table_name), 'error dropping audit table ' . $table_name); } $aDBTables = OA_DB_Table::listOATablesCaseSensitive(); $this->assertFalse(in_array($table_name, $aDBTables), '_dropAuditTable'); }
/** * Creates and truncates the tables in the list $aTables. * * @param array $aTables Names of the tables to be created. */ function initTables($aTables) { foreach ($aTables as $table) { $result = $this->oaTable->createTable($table); if (PEAR::isError($result)) { return false; } $result = $this->oaTable->truncateTable($table); if (PEAR::isError($result)) { return false; } } return true; }
/** * A method to test the MAX_Delivery_log_logVariableValues() function. */ function test_MAX_Delivery_log_logVariableValues() { $aConf =& $GLOBALS['_MAX']['CONF']; $aConf['maintenance']['operationInterval'] = 60; $GLOBALS['_MAX']['NOW'] = time(); $oNowDate = new Date($GLOBALS['_MAX']['NOW']); // Test to ensure that the openXDeliveryLog plugin's data bucket // table does not exist $oTable = new OA_DB_Table(); $tableExists = $oTable->extistsTable($aConf['table']['prefix'] . 'data_bkt_a_var'); $this->assertFalse($tableExists); // Test calling the main logging function without any plugins installed, // to ensure that this does not result in any kind of error $aVariables = array(55 => array('variable_id' => 55, 'tracker_id' => 1, 'name' => 'fooVar', 'type' => 'string', 'variablecode' => ''), 66 => array('variable_id' => 66, 'tracker_id' => 1, 'name' => 'barVar', 'type' => 'string', 'variablecode' => '')); $_GET['fooVar'] = 'foo'; $_GET['barVar'] = 'bar'; MAX_Delivery_log_logVariableValues($aVariables, 1, 1, 'singleDB'); // Install the openXDeliveryLog plugin TestEnv::installPluginPackage('openXDeliveryLog', false); // Test to ensure that the openXDeliveryLog plugin's data bucket // table now does exist $tableExists = $oTable->extistsTable($aConf['table']['prefix'] . 'data_bkt_a_var'); $this->assertTrue($tableExists); // Ensure that there are is nothing logged in the data bucket table $doData_bkt_a_var = OA_Dal::factoryDO('data_bkt_a_var'); $doData_bkt_a_var->find(); $rows = $doData_bkt_a_var->getRowCount(); $this->assertEqual($rows, 0); // Call the variable value logging function MAX_Delivery_log_logVariableValues($aVariables, 1, 1, 'singleDB'); // Ensure that the data was logged correctly $doData_bkt_a_var = OA_Dal::factoryDO('data_bkt_a_var'); $doData_bkt_a_var->find(); $rows = $doData_bkt_a_var->getRowCount(); $this->assertEqual($rows, 2); $doData_bkt_a_var = OA_Dal::factoryDO('data_bkt_a_var'); $doData_bkt_a_var->server_conv_id = 1; $doData_bkt_a_var->server_raw_ip = 'singleDB'; $doData_bkt_a_var->tracker_variable_id = 55; $doData_bkt_a_var->find(); $rows = $doData_bkt_a_var->getRowCount(); $this->assertEqual($rows, 1); $doData_bkt_a_var->fetch(); $this->assertEqual($doData_bkt_a_var->value, 'foo'); $this->assertEqual($doData_bkt_a_var->date_time, $oNowDate->format('%Y-%m-%d %H:%M:%S')); // Uninstall the openXDeliveryLog plugin TestEnv::uninstallPluginPackage('openXDeliveryLog', false); // Restore the test configuration file TestEnv::restoreConfig(); }
function test_backupTables() { $GLOBALS['_MAX']['CONF']['pluginPaths']['repo'] = $GLOBALS['_MAX']['CONF']['pluginPaths']['repo'] . '|' . MAX_PATH . $this->testpathData . 'plugins_repo/'; $zipFile = $this->testpathData . 'plugins_repo/' . 'testPluginPackage_v3.zip'; $plugin = $this->testpathData . 'plugins_repo/' . 'testPluginPackage.zip'; if (file_exists($zipFile) && !unlink($zipFile)) { $this->fail('error unlinking ' . $zipFile); return false; } if (!copy(MAX_PATH . $zipFile, MAX_PATH . $plugin)) { $this->fail('error copying ' . $zipFile); return false; } if (!file_exists(MAX_PATH . $plugin)) { $this->fail('file does not exist ' . $plugin); return false; } TestEnv::installPluginPackage('testPluginPackage', false); $prefix = $GLOBALS['_MAX']['CONF']['table']['prefix']; $oExport = new OX_PluginExport(); $oExport->init('testPluginPackage'); $aTables = OA_DB_Table::listOATablesCaseSensitive('testplugin_table'); $this->assertEqual(count($aTables), 1); $this->assertEqual($aTables[0], $prefix . 'testplugin_table'); $this->assertTrue($oExport->backupTables('testPluginPackage')); $aTables = OA_DB_Table::listOATablesCaseSensitive('testplugin_table'); $this->assertEqual(count($aTables), 2); $this->assertEqual($aTables[0], $prefix . 'testplugin_table'); $this->assertPattern('/' . $prefix . 'testplugin_table_' . date('Ymd') . '_[\\d]{6}/', $aTables[1]); TestEnv::uninstallPluginPackage('testPluginPackage', false); TestEnv::restoreConfig(); TestEnv::restoreEnv(); }
/** * 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(); }
function test_runScript() { $oUpgrade = new OA_Upgrade(); $this->oConfiguration = $oUpgrade->oConfiguration; $oUpgrade->initDatabaseConnection(); $oDbh =& $oUpgrade->oDbh; $oTable = new OA_DB_Table(); $table = 'database_action'; $testfile = MAX_PATH . "/lib/OA/Upgrade/tests/data/{$table}.xml"; $oTable->init($testfile); $this->assertTrue($oTable->dropTable($this->prefix . $table), 'error dropping ' . $this->prefix . $table); $this->assertTrue($oTable->createTable($table), 'error creating ' . $this->prefix . $table); $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); $this->assertTrue(in_array($this->prefix . $table, $aExistingTables), 'old database_action table not found'); $this->assertTrue($oUpgrade->runScript('prescript_openads_upgrade_2.3.33-beta-rc4.php')); TestEnv::restoreConfig(); }
/** * Enter description here... * * @param array $installvars * @return boolean */ function checkDatabaseExists($installvars) { $oDbh =& OA_DB::singleton(); $oTable = OA_DB_Table_Core::singleton(); $aTables = OA_DB_Table::listOATablesCaseSensitive(); $result = false; foreach ($oTable->tables as $k => $v) { if (is_array($aTables) && in_array($installvars['table_prefix'] . $k, $aTables)) { // Table exists $result = true; break; } } return $result; }
/** * Tests creating/dropping all of the core tables. * * Requirements: * Test 1: Test that all core tables can be created and dropped. */ function testAllCoreTables() { // Test 1 $conf =& $GLOBALS['_MAX']['CONF']; $conf['table']['prefix'] = ''; $oDbh =& OA_DB::singleton(); $oTable =& OA_DB_Table_Core::singleton(); $oTable->dropAllTables(); $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); if (PEAR::isError($aExistingTables)) { // Can't talk to database, test fails! $this->assertTrue(false); } $this->assertEqual(count($aExistingTables), 0); $oTable =& OA_DB_Table_Core::singleton(); $oTable->createAllTables(); $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); foreach ($conf['table'] as $key => $tableName) { if ($key == 'prefix' || $key == 'type') { continue; } // Test that the tables exists $this->assertTrue(in_array($tableName, $aExistingTables), 'does not exist: ' . $tableName . ' (found in conf file)'); } $oTable->dropAllTables(); $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); if (PEAR::isError($aExistingTables)) { // Can't talk to database, test fails! $this->assertTrue(false); } $this->assertEqual(count($aExistingTables), 0); // Ensure the singleton is destroyed $oTable->destroy(); }
/** * The class constructor method. */ function __construct() { parent::__construct(); $this->temporary = true; }
function _dropAuditTables($oDbh) { $oTable = new OA_DB_Table(); $testpath = MAX_PATH . '/lib/OA/Upgrade/tests/data/'; $oTable->init($testpath . 'schema_test_config.xml'); $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); if (in_array($this->prefix . 'database_action', $aExistingTables)) { $this->assertTrue($oTable->dropTable($this->prefix . 'database_action'), 'error dropping test ' . $this->prefix . 'database_action'); } if (in_array($this->prefix . 'upgrade_action', $aExistingTables)) { $this->assertTrue($oTable->dropTable($this->prefix . 'upgrade_action'), 'error dropping test ' . $this->prefix . 'upgrade_action'); } $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); $this->assertFalse(in_array($this->prefix . 'database_action', $aExistingTables), 'database_action'); $this->assertFalse(in_array($this->prefix . 'upgrade_action', $aExistingTables), 'upgrade_action'); }
function test_listBackups() { $oAuditor = $this->_getAuditObject('OA_DB_UpgradeAuditor'); $oTable = new OA_DB_Table(); $oTable->init($this->path . 'schema_test_backups.xml'); $this->assertTrue($oTable->createTable('z_test1'), 'error creating test backup z_test1'); $this->assertTrue($oTable->createTable('z_test2'), 'error creating test backup z_test2'); $this->assertTrue($oTable->createTable('z_test3'), 'error creating test backup z_test3'); $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); $this->assertTrue(in_array($oAuditor->prefix . 'z_test1', $aExistingTables), '_listBackups'); $this->assertTrue(in_array($oAuditor->prefix . 'z_test2', $aExistingTables), '_listBackups'); $this->assertTrue(in_array($oAuditor->prefix . 'z_test3', $aExistingTables), '_listBackups'); $aBackupTables = $oAuditor->_listBackups(); $this->assertIsA($aBackupTables, 'array', 'backup array not an array'); $this->assertEqual(count($aBackupTables), 3, 'wrong number of backups found in database: expected 3 got ' . count($aBackupTables)); $this->_dropAuditTable($oAuditor->prefix . $oAuditor->logTable); $this->_dropAuditTable($oAuditor->prefix . 'z_test1'); $this->_dropAuditTable($oAuditor->prefix . 'z_test2'); $this->_dropAuditTable($oAuditor->prefix . 'z_test3'); }
function _checkCreateAuditTable() { $this->aDBTables = OA_DB_Table::listOATablesCaseSensitive(); if (!in_array($this->prefix . $this->logTable, $this->aDBTables)) { $this->log('creating ' . $this->logTable . ' audit table'); if (!$this->_createAuditTable()) { $this->logError('failed to create ' . $this->logTable . ' audit table'); return false; } $this->log('successfully created ' . $this->logTable . ' audit table'); } return true; }
function backupTables($name) { foreach ($this->aGroups as $aGroup) { $path = $this->pathPackages . $aGroup['name'] . '/etc/'; if ($aGroup['install']['schema']['mdb2schema']) { $aSchemas[$aGroup['name']] = $path . $aGroup['install']['schema']['mdb2schema'] . '.xml'; } } if ($aSchemas) { $oDbh = OA_DB::singleton(); switch ($oDbh->dbsyntax) { case 'mysql': $engine = $oDbh->getOption('default_table_type'); $sql = "CREATE TABLE %s ENGINE={$engine} (SELECT * FROM %s)"; break; case 'pgsql': $sql = 'CREATE TABLE "%1$s" (LIKE "%2$s" INCLUDING DEFAULTS); INSERT INTO "%1$s" SELECT * FROM "%2$s"'; break; } $prefix = $GLOBALS['_MAX']['CONF']['table']['prefix']; foreach ($aSchemas as $group => $file) { $oTable = new OA_DB_Table(); if ($oTable->init($this->basePath . $file, false)) { foreach ($oTable->aDefinition['tables'] as $table => $aTable) { $tblSrc = $prefix . $table; $tblTgt = $tblSrc . '_' . date('Ymd_His'); $query = sprintf($sql, $tblTgt, $tblSrc); $result = $oDbh->exec($query); if (PEAR::isError($result)) { $aResult[] = $group . ' : ' . $tblSrc . ' backup failed'; $this->aErrors[] = 'error creating backup ' . $tblSrc . ' : ' . $result->getUserInfo(); } if (count(OA_DB_Table::listOATablesCaseSensitive($tblTgt) == 1)) { $aResult[] = $group . ' : ' . $tblSrc . ' copied to ' . $tblTgt; } } } else { $aResult = $group . ' : no tables copied'; $this->aErrors[] = 'error initialising ' . $group . ' schema ' . $file; } } } return $aResult ? $aResult : array(0 => 'plugin has no tables to backup'); }
/** * check if openads tables already exist in the specified database * * @return boolean */ function checkExistingTables() { $result = true; $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); $oldTableMessagePrefix = 'Your database contains an old OpenX configuration table: '; $oldTableMessagePostfix = 'If you are trying to upgrade this database, please copy your existing configuration file into the var folder of this install. If you wish to proceed with a fresh installation, please either choose a new Table Prefix or a new Database.'; if (in_array($this->aDsn['table']['prefix'] . 'config', $aExistingTables)) { $this->oLogger->logError($oldTableMessagePrefix . $this->aDsn['table']['prefix'] . 'config. ' . $oldTableMessagePostfix); return false; } if (in_array($this->aDsn['table']['prefix'] . 'preference', $aExistingTables)) { $this->oLogger->logError($oldTableMessagePrefix . $this->aDsn['table']['prefix'] . 'preference. ' . $oldTableMessagePostfix); return false; } if (in_array($this->aDsn['table']['prefix'] . 'preferences', $aExistingTables)) { $this->oLogger->logError($oldTableMessagePrefix . $this->aDsn['table']['prefix'] . 'preferences. ' . $oldTableMessagePostfix); return false; } $tablePrefixError = false; foreach ($aExistingTables as &$tablename) { if (substr($tablename, 0, strlen($this->aDsn['table']['prefix'])) == $this->aDsn['table']['prefix']) { $result = false; $this->oLogger->log('Table with the prefix ' . $this->aDsn['table']['prefix'] . ' found: ' . $tablename); if ($tablePrefixError == false) { $this->oLogger->logError('The database you have chosen already contains tables with the prefix ' . $this->aDsn['table']['prefix']); $this->oLogger->logError('Please either remove these tables or choose a new prefix'); $tablePrefixError = true; } } } return $result; }
/** * fixes sequence values for pgsql * * @param array $aTable */ function _fixSequences($prefix, $table_name, &$aTable) { if ($this->oDbh->dbsyntax == 'pgsql') { $oTable = new OA_DB_Table(); foreach ($aTable['fields'] as $fieldName => $fieldProperties) { if (!empty($fieldProperties['autoincrement'])) { $tblName = $this->oDbh->quoteIdentifier($prefix . $table_name, true); $seqName = "{$prefix}{$table_name}_{$fieldName}_seq"; $maxValue = $this->oDbh->queryOne("SELECT MAX({$fieldName}) FROM {$tblName}"); $oTable->resetSequence($seqName, $maxValue + 1); } } } }
/** * A method to perform the migration of logged bucket-based supplementary * raw statistics data from the bucket table(s) into a final statistics table. * * @param string $statisticsTableName The name of the statistics table the * data is to be migrated to. * @param array $aMigrationDetails An array containing the details of the * bucket data to migrate into the statistics * table. See the * Plugins_DeliveryLog::getStatisticsMigration() * method for details. * @param array $aDates An array containing the PEAR Date objects representing the * start and end dates for the operation interval being migrated, * indexed by "start" and "end", respectively. * @return mixed A PEAR_Error or MDB2_Error object on failure, otherwise, the number * of rows of raw data that were migrated from the bucket table to the * statistics table. */ function summariseBucketsRawSupplementary($statisticsTableName, $aMigrationDetails, $aDates) { // Perform basic checking of the parameters; assumes that $aMigrationDetails // has already been checked by the Plugins_DeliveryLog::testStatisticsMigration() // method if ($aMigrationDetails['method'] != 'rawSupplementary') { $message = "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with migration map method '{$aMigrationDetails['method']}' != 'rawSupplementary'."; $oError = new PEAR_Error($message, MAX_ERROR_INVALIDARGS); return $oError; } if (count($aMigrationDetails['masterTablePrimaryKeys']) != count($aMigrationDetails['bucketTablePrimaryKeys'])) { $message = "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with different number of 'masterTablePrimaryKeys' and 'bucketTablePrimaryKeys' columns."; $oError = new PEAR_Error($message, MAX_ERROR_INVALIDARGS); return $oError; } if (count($aMigrationDetails['masterTableKeys']) != count($aMigrationDetails['bucketTableKeys'])) { $message = "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with different number of 'masterTableKeys' and 'bucketTableKeys' columns."; $oError = new PEAR_Error($message, MAX_ERROR_INVALIDARGS); return $oError; } if (count($aMigrationDetails['source']) != count($aMigrationDetails['destination'])) { $message = "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with different number of 'source' and 'destination' columns."; $oError = new PEAR_Error($message, MAX_ERROR_INVALIDARGS); return $oError; } if (!is_a($aDates['start'], 'Date') || !is_a($aDates['end'], 'Date')) { $message = "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with invalid start/end date parameters -- not Date objects."; $oError = new PEAR_Error($message, MAX_ERROR_INVALIDARGS); return $oError; } if (!OX_OperationInterval::checkIntervalDates($aDates['start'], $aDates['end'])) { $message = "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with invalid start/end date parameters -- not operation interval bounds."; $oError = new PEAR_Error($message, MAX_ERROR_INVALIDARGS); return $oError; } // Ensure that tables exist before trying to run commands based on // plugin components $oTable = new OA_DB_Table(); if (!$oTable->extistsTable($statisticsTableName)) { $message = "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with invalid statistics table '{$statisticsTableName}'."; $oError = new PEAR_Error($message, MAX_ERROR_INVALIDREQUEST); return $oError; } if (!$oTable->extistsTable($aMigrationDetails['masterTable'])) { $message = "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with invalid master table '{$aMigrationDetails['masterTable']}'."; $oError = new PEAR_Error($message, MAX_ERROR_INVALIDREQUEST); return $oError; } if (!$oTable->extistsTable($aMigrationDetails['bucketTable'])) { $message = "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with invalid bucket table '{$aMigrationDetails['bucketTable']}'."; $oError = new PEAR_Error($message, MAX_ERROR_INVALIDREQUEST); return $oError; } // Prepare the previously migrated raw data statistics table columns array $aMasterColumns = array(); foreach ($aMigrationDetails['masterTablePrimaryKeys'] as $value) { $aMasterColumns[] = $this->oDbh->quoteIdentifier($value, true); } foreach ($aMigrationDetails['masterTableKeys'] as $value) { $aMasterColumns[] = $this->oDbh->quoteIdentifier($value, true); } // Prepare the query to locate the data in columns in the statistics // table which contains the previously migrated raw bucket data, // which will then be used to locate the supplementary raw data and // also to ensure that when this supplementary raw data is migrated // to its statistics table, the supplementary raw data can be // connected with the previously migrated raw data $query = "\n SELECT\n " . implode(', ', $aMasterColumns) . "\n FROM\n " . $this->oDbh->quoteIdentifier($aMigrationDetails['masterTable'], true) . "\n WHERE\n " . $this->oDbh->quoteIdentifier($aMigrationDetails['masterDateTimeColumn'], true) . " >= " . $this->oDbh->quote($aDates['start']->format('%Y-%m-%d %H:%M:%S'), 'timestamp') . "\n AND\n " . $this->oDbh->quoteIdentifier($aMigrationDetails['masterDateTimeColumn'], true) . " <= " . $this->oDbh->quote($aDates['end']->format('%Y-%m-%d %H:%M:%S'), 'timestamp'); // Prevent any strange database error from causing execution to halt // by overriding the error handler, run the query, and return the // MDB2_Error object, if required PEAR::pushErrorHandling(null); $rsResult = $this->oDbh->query($query); PEAR::popErrorHandling(); if (PEAR::isError($rsResult)) { return $rsResult; } // Were any rows found for previously migrated summarised raw data? if ($rsResult->numRows() == 0) { return 0; } // Ensure that the required arrays are sorted by key ksort($aMigrationDetails['masterTableKeys']); ksort($aMigrationDetails['bucketTableKeys']); ksort($aMigrationDetails['source']); ksort($aMigrationDetails['destination']); // Prepare the destination columns array $aDestinationColumns = array(); foreach ($aMigrationDetails['bucketTablePrimaryKeys'] as $value) { $aDestinationColumns[] = $this->oDbh->quoteIdentifier($value, true); } foreach ($aMigrationDetails['destination'] as $value) { $aDestinationColumns[] = $this->oDbh->quoteIdentifier($value, true); } $counter = 0; while ($aRow = $rsResult->fetchRow()) { // Prepare the select column statements array $aSelectColumnStatements = array(); foreach ($aMigrationDetails['bucketTablePrimaryKeys'] as $value) { $aSelectColumnStatements[] = $this->oDbh->quote($aRow[$value], 'text') . ' AS ' . $this->oDbh->quoteIdentifier($value, true); } foreach ($aMigrationDetails['destination'] as $key => $value) { $aSelectColumnStatements[] = $this->oDbh->quoteIdentifier($aMigrationDetails['source'][$key], true) . ' AS ' . $this->oDbh->quoteIdentifier($value, true); } // Prepare the where statementes array $aWhereStatements = array(); foreach ($aMigrationDetails['masterTableKeys'] as $key => $value) { $aWhereStatements[] = $this->oDbh->quoteIdentifier($aMigrationDetails['bucketTableKeys'][$key], true) . ' = ' . $this->oDbh->quote($aRow[$value], 'text'); } // Prepare the query to migrate the supplementary raw data from bucket // table to the statistics table $query = "\n INSERT INTO\n " . $this->oDbh->quoteIdentifier($statisticsTableName, true) . "\n (" . implode(', ', $aDestinationColumns) . ")\n SELECT\n " . implode(', ', $aSelectColumnStatements) . "\n FROM\n " . $this->oDbh->quoteIdentifier($aMigrationDetails['bucketTable'], true) . "\n WHERE\n " . implode(' AND ', $aWhereStatements); // Prevent any strange database error from causing execution to halt // by overriding the error handler, run the query, and return the // result (either the number or rows affected, or an MDB2_Error // object on query/database error) PEAR::pushErrorHandling(null); $result = $this->oDbh->exec($query); PEAR::popErrorHandling(); if (PEAR::isError($result)) { return $result; } $counter += $result; } return $counter; }
/** * A method to test the MAX_Delivery_log_logConversion() function. */ function test_MAX_Delivery_log_logConversion() { $aConf =& $GLOBALS['_MAX']['CONF']; $aConf['maintenance']['operationInterval'] = 60; $GLOBALS['_MAX']['NOW'] = time(); $oNowDate = new Date($GLOBALS['_MAX']['NOW']); $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oNowDate); $intervalStart = $aDates['start']->format('%Y-%m-%d %H:%M:%S'); $oConversionDate = new Date(); $oConversionDate->copy($oNowDate); $oConversionDate->subtractSeconds(60); $_SERVER['REMOTE_ADDR'] = '127.0.0.99'; // Test to ensure that the openXDeliveryLog plugin's data bucket // table does not exist $oTable = new OA_DB_Table(); $tableExists = $oTable->extistsTable($aConf['table']['prefix'] . 'data_bkt_a'); $this->assertFalse($tableExists); // Test calling the main logging function without any plugins installed, // to ensure that this does not result in any kind of error $aConversion = array('action_type' => MAX_CONNECTION_AD_CLICK, 'tracker_type' => MAX_CONNECTION_TYPE_SALE, 'status' => MAX_CONNECTION_STATUS_APPROVED, 'cid' => 2, 'zid' => 3, 'dt' => $GLOBALS['_MAX']['NOW'] - 60, 'window' => 60); MAX_Delivery_log_logConversion(1, $aConversion); // Install the openXDeliveryLog plugin TestEnv::installPluginPackage('openXDeliveryLog', false); // Test to ensure that the openXDeliveryLog plugin's data bucket // table now does exist $tableExists = $oTable->extistsTable($aConf['table']['prefix'] . 'data_bkt_a'); $this->assertTrue($tableExists); // Ensure that there are is nothing logged in the data bucket table $doData_bkt_a = OA_Dal::factoryDO('data_bkt_a'); $doData_bkt_a->find(); $rows = $doData_bkt_a->getRowCount(); $this->assertEqual($rows, 0); // Call the conversion logging function $aConversionInfo = MAX_Delivery_log_logConversion(1, $aConversion); // Ensure that the data was logged correctly $doData_bkt_a = OA_Dal::factoryDO('data_bkt_a'); $doData_bkt_a->find(); $rows = $doData_bkt_a->getRowCount(); $this->assertEqual($rows, 1); $doData_bkt_a = OA_Dal::factoryDO('data_bkt_a'); $doData_bkt_a->server_conv_id = 1; $doData_bkt_a->find(); $rows = $doData_bkt_a->getRowCount(); $this->assertEqual($rows, 1); $doData_bkt_a->fetch(); $this->assertEqual($doData_bkt_a->server_ip, 'singleDB'); $this->assertEqual($doData_bkt_a->tracker_id, 1); $this->assertEqual($doData_bkt_a->date_time, $oNowDate->format('%Y-%m-%d %H:%M:%S')); $this->assertEqual($doData_bkt_a->action_date_time, $oConversionDate->format('%Y-%m-%d %H:%M:%S')); $this->assertEqual($doData_bkt_a->creative_id, 2); $this->assertEqual($doData_bkt_a->zone_id, 3); $this->assertEqual($doData_bkt_a->ip_address, '127.0.0.99'); $this->assertEqual($doData_bkt_a->action, MAX_CONNECTION_AD_CLICK); $this->assertEqual($doData_bkt_a->window, 60); $this->assertEqual($doData_bkt_a->status, MAX_CONNECTION_STATUS_APPROVED); $this->assertTrue(is_array($aConversionInfo)); $this->assertTrue(is_array($aConversionInfo['deliveryLog:oxLogConversion:logConversion'])); $this->assertEqual($aConversionInfo['deliveryLog:oxLogConversion:logConversion']['server_conv_id'], 1); $this->assertEqual($aConversionInfo['deliveryLog:oxLogConversion:logConversion']['server_raw_ip'], 'singleDB'); $aConversion['cid'] = 5; // Call the conversion logging function $aConversionInfo = MAX_Delivery_log_logConversion(1, $aConversion); // Ensure that the data was logged correctly $doData_bkt_a = OA_Dal::factoryDO('data_bkt_a'); $doData_bkt_a->find(); $rows = $doData_bkt_a->getRowCount(); $this->assertEqual($rows, 2); $doData_bkt_a = OA_Dal::factoryDO('data_bkt_a'); $doData_bkt_a->server_conv_id = 1; $doData_bkt_a->find(); $rows = $doData_bkt_a->getRowCount(); $this->assertEqual($rows, 1); $doData_bkt_a->fetch(); $this->assertEqual($doData_bkt_a->server_ip, 'singleDB'); $this->assertEqual($doData_bkt_a->tracker_id, 1); $this->assertEqual($doData_bkt_a->date_time, $oNowDate->format('%Y-%m-%d %H:%M:%S')); $this->assertEqual($doData_bkt_a->action_date_time, $oConversionDate->format('%Y-%m-%d %H:%M:%S')); $this->assertEqual($doData_bkt_a->creative_id, 2); $this->assertEqual($doData_bkt_a->zone_id, 3); $this->assertEqual($doData_bkt_a->ip_address, '127.0.0.99'); $this->assertEqual($doData_bkt_a->action, MAX_CONNECTION_AD_CLICK); $this->assertEqual($doData_bkt_a->window, 60); $this->assertEqual($doData_bkt_a->status, MAX_CONNECTION_STATUS_APPROVED); $doData_bkt_a = OA_Dal::factoryDO('data_bkt_a'); $doData_bkt_a->server_conv_id = 2; $doData_bkt_a->find(); $rows = $doData_bkt_a->getRowCount(); $this->assertEqual($rows, 1); $doData_bkt_a->fetch(); $this->assertEqual($doData_bkt_a->server_ip, 'singleDB'); $this->assertEqual($doData_bkt_a->tracker_id, 1); $this->assertEqual($doData_bkt_a->date_time, $oNowDate->format('%Y-%m-%d %H:%M:%S')); $this->assertEqual($doData_bkt_a->action_date_time, $oConversionDate->format('%Y-%m-%d %H:%M:%S')); $this->assertEqual($doData_bkt_a->creative_id, 5); $this->assertEqual($doData_bkt_a->zone_id, 3); $this->assertEqual($doData_bkt_a->ip_address, '127.0.0.99'); $this->assertEqual($doData_bkt_a->action, MAX_CONNECTION_AD_CLICK); $this->assertEqual($doData_bkt_a->window, 60); $this->assertEqual($doData_bkt_a->status, MAX_CONNECTION_STATUS_APPROVED); $this->assertTrue(is_array($aConversionInfo)); $this->assertTrue(is_array($aConversionInfo['deliveryLog:oxLogConversion:logConversion'])); $this->assertEqual($aConversionInfo['deliveryLog:oxLogConversion:logConversion']['server_conv_id'], 2); $this->assertEqual($aConversionInfo['deliveryLog:oxLogConversion:logConversion']['server_raw_ip'], 'singleDB'); // Uninstall the openXDeliveryLog plugin TestEnv::uninstallPluginPackage('openXDeliveryLog', false); // Restore the test configuration file TestEnv::restoreConfig(); }
/** * retrieve an array of table names from currently connected database * * @return array */ function _listBackups() { $aResult = array(); $prefix = $this->prefix . 'z_'; OA_DB::setCaseSensitive(); $aBakTables = OA_DB_Table::listOATablesCaseSensitive(); OA_DB::disableCaseSensitive(); $prelen = strlen($prefix); krsort($aBakTables); foreach ($aBakTables as $k => &$name) { // workaround for mdb2 problem "show table like" if (substr($name, 0, $prelen) == $prefix) { $name = str_replace($this->prefix, '', $name); $aInfo = $this->queryAuditForABackup($name); $aResult[$k]['backup_table'] = $name; $aResult[$k]['copied_table'] = $aInfo[0]['tablename']; $aResult[$k]['copied_date'] = $aInfo[0]['updated']; $aStatus = $this->getTableStatus($name); $aResult[$k]['data_length'] = $aStatus[0]['data_length'] / 1024; $aResult[$k]['rows'] = $aStatus[0]['rows']; } } return $aResult; }
/** * A method to test the MAX_Delivery_log_logAdRequest(), * MAX_Delivery_log_logAdImpression() and MAX_Delivery_log_logAdClick() * functions. */ function testRequestImpressionClickFunction() { $aConf =& $GLOBALS['_MAX']['CONF']; $aConf['maintenance']['operationInterval'] = 60; $GLOBALS['_MAX']['NOW'] = time(); $oNowDate = new Date($GLOBALS['_MAX']['NOW']); $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oNowDate); $intervalStart = $aDates['start']->format('%Y-%m-%d %H:%M:%S'); $aTables = array('MAX_Delivery_log_logAdRequest' => 'data_bkt_r', 'MAX_Delivery_log_logAdImpression' => 'data_bkt_m', 'MAX_Delivery_log_logAdClick' => 'data_bkt_c'); foreach ($aTables as $function => $table) { // Test to ensure that the openXDeliveryLog plugin's data bucket // table does not exist $oTable = new OA_DB_Table(); $tableExists = $oTable->extistsTable($aConf['table']['prefix'] . $table); $this->assertFalse($tableExists); // Test calling the main logging function without any plugins installed, // to ensure that this does not result in any kind of error unset($GLOBALS['_MAX']['deliveryData']['Plugin_deliveryDataPrepare_oxDeliveryDataPrepare_dataCommon']); call_user_func_array($function, array(1, 1)); } // Install the openXDeliveryLog plugin TestEnv::installPluginPackage('openXDeliveryLog', false); foreach ($aTables as $function => $table) { // Test to ensure that the openXDeliveryLog plugin's data bucket // table now does exist $tableExists = $oTable->extistsTable($aConf['table']['prefix'] . $table); $this->assertTrue($tableExists); // Ensure that there are is nothing logged in the data bucket table $doData_bkt = OA_Dal::factoryDO($table); $doData_bkt->find(); $rows = $doData_bkt->getRowCount(); $this->assertEqual($rows, 0); // Call the main logging function unset($GLOBALS['_MAX']['deliveryData']['Plugin_deliveryDataPrepare_oxDeliveryDataPrepare_dataCommon']); call_user_func_array($function, array(1, 1)); // Ensure that the data was logged correctly $doData_bkt = OA_Dal::factoryDO($table); $doData_bkt->find(); $rows = $doData_bkt->getRowCount(); if ($table == 'data_bkt_r') { // Request logging is disabled by default. Nothing should have been logged by now $this->assertEqual($rows, 0); // Enable it $GLOBALS['_MAX']['CONF']['logging']['adRequests'] = true; unset($GLOBALS['_MAX']['deliveryData']['Plugin_deliveryDataPrepare_oxDeliveryDataPrepare_dataCommon']); call_user_func_array($function, array(1, 1)); // Now ensure that the data was logged correctly $doData_bkt->find(); $rows = $doData_bkt->getRowCount(); } $this->assertEqual($rows, 1); $doData_bkt = OA_Dal::factoryDO($table); $doData_bkt->creative_id = 1; $doData_bkt->zone_id = 1; $doData_bkt->find(); $rows = $doData_bkt->getRowCount(); $this->assertEqual($rows, 1); $doData_bkt->fetch(); $this->assertEqual($doData_bkt->count, 1); $this->assertEqual($doData_bkt->interval_start, $intervalStart); // Call the main logging function again unset($GLOBALS['_MAX']['deliveryData']['Plugin_deliveryDataPrepare_oxDeliveryDataPrepare_dataCommon']); call_user_func_array($function, array(1, 1)); // Ensure that the data was logged correctly $doData_bkt = OA_Dal::factoryDO($table); $doData_bkt->find(); $rows = $doData_bkt->getRowCount(); $this->assertEqual($rows, 1); $doData_bkt = OA_Dal::factoryDO($table); $doData_bkt->creative_id = 1; $doData_bkt->zone_id = 1; $doData_bkt->find(); $rows = $doData_bkt->getRowCount(); $this->assertEqual($rows, 1); $doData_bkt->fetch(); $this->assertEqual($doData_bkt->count, 2); $this->assertEqual($doData_bkt->interval_start, $intervalStart); // Call the main logging function again, but with a differen // creative/zone pair unset($GLOBALS['_MAX']['deliveryData']['Plugin_deliveryDataPrepare_oxDeliveryDataPrepare_dataCommon']); call_user_func_array($function, array(2, 1)); // Ensure that the data was logged correctly $doData_bkt = OA_Dal::factoryDO($table); $doData_bkt->find(); $rows = $doData_bkt->getRowCount(); $this->assertEqual($rows, 2); $doData_bkt = OA_Dal::factoryDO($table); $doData_bkt->creative_id = 1; $doData_bkt->zone_id = 1; $doData_bkt->find(); $rows = $doData_bkt->getRowCount(); $this->assertEqual($rows, 1); $doData_bkt->fetch(); $this->assertEqual($doData_bkt->count, 2); $this->assertEqual($doData_bkt->interval_start, $intervalStart); $doData_bkt = OA_Dal::factoryDO($table); $doData_bkt->creative_id = 2; $doData_bkt->zone_id = 1; $doData_bkt->find(); $rows = $doData_bkt->getRowCount(); $this->assertEqual($rows, 1); $doData_bkt->fetch(); $this->assertEqual($doData_bkt->count, 1); $this->assertEqual($doData_bkt->interval_start, $intervalStart); } // Uninstall the openXDeliveryLog plugin TestEnv::uninstallPluginPackage('openXDeliveryLog', false); // Restore the test configuration file TestEnv::restoreConfig(); }
function exportData($identity = '') { $oDbh = OA_DB::singleton(); switch ($oDbh->dbsyntax) { case 'mysql': $engine = $oDbh->getOption('default_table_type'); $sql = "CREATE TABLE %s ENGINE={$engine} (SELECT * FROM %s %s)"; break; case 'pgsql': $sql = 'CREATE TABLE "%1$s" (LIKE "%2$s" INCLUDING DEFAULTS); INSERT INTO "%1$s" SELECT * FROM "%2$s" "%3$s"'; break; } $aConf = $GLOBALS['_MAX']['CONF']['table']; if (!$identity) { $identity = 'z_' . $this->component . date('Ymd_His'); } $tblSrc = $aConf['prefix'] . 'banners_demo'; $tblTgt = $aConf['prefix'] . $identity . $tblSrc; $where = "WHERE 1=1"; $query = sprintf($sql, $tblTgt, $tblSrc, $where); $result1 = $oDbh->exec($query); $tblSrc = $aConf['prefix'] . 'banners'; $tblTgt = $aConf['prefix'] . $identity . $tblSrc; $where = "WHERE ext_bannertype = '" . $this->getComponentIdentifier() . "'"; $query = sprintf($sql, $tblTgt, $tblSrc, $where); $result2 = $oDbh->exec($query); if ($result1 && $result2) { return OA_DB_Table::listOATablesCaseSensitive($identity); } return false; }
/** * The class constructor method. */ function OA_DB_Table_Priority() { parent::OA_DB_Table(); $this->temporary = true; }
/** * A method to test the drop table method. * * Requirements: * Test 1: Test that a table can be dropped. * Test 2: Test that a temporary table can be dropped. * Test 3: Test that a tablename with uppercase prefix can be dropped. * Test 4: Test that a tablename with a mixed prefix can be dropped. */ function testDropTable() { // Test 1 $conf =& $GLOBALS['_MAX']['CONF']; $prefix = $conf['table']['prefix']; $oDbh =& OA_DB::singleton(); $table = $oDbh->quoteIdentifier($prefix . 'foo', true); $oTable = new OA_DB_Table(); $query = "CREATE TABLE {$table} ( a INTEGER )"; $oDbh->query($query); $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); $this->assertEqual($aExistingTables[0], $prefix . 'foo'); $this->assertTrue($oTable->dropTable($prefix . 'foo')); $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); $this->assertEqual(count($aExistingTables), 0, $prefix . 'foo'); //TestEnv::restoreEnv(); // Test 2 $conf =& $GLOBALS['_MAX']['CONF']; $oDbh =& OA_DB::singleton(); $oTable = new OA_DB_Table(); $table = $oDbh->quoteIdentifier($prefix . 'foo', true); $query = "CREATE TEMPORARY TABLE {$table} ( a INTEGER )"; $oDbh->query($query); // Test table exists with an insert $query = "INSERT INTO {$table} (a) VALUES (37)"; $result = $oDbh->query($query); $this->assertTrue($result); $this->assertTrue($oTable->dropTable($prefix . 'foo')); // Test table does not exist with an insert $query = "INSERT INTO {$table} (a) VALUES (37)"; RV::disableErrorHandling(); $result = $oDbh->query($query); RV::enableErrorHandling(); $this->assertEqual(strtolower(get_class($result)), 'mdb2_error'); //TestEnv::restoreEnv(); // Test 3 $conf =& $GLOBALS['_MAX']['CONF']; $conf['table']['prefix'] = 'OA_'; $prefix = $conf['table']['prefix']; $oDbh =& OA_DB::singleton(); $table = $oDbh->quoteIdentifier($prefix . 'foo', true); $query = "CREATE TABLE {$table} ( a INTEGER )"; $oDbh->query($query); $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); $this->assertEqual($aExistingTables[0], 'OA_foo'); $this->assertTrue($oTable->dropTable('OA_foo')); $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); $this->assertEqual(count($aExistingTables), 0, 'Table OA_foo'); //TestEnv::restoreEnv(); // Test 4 $conf =& $GLOBALS['_MAX']['CONF']; $conf['table']['prefix'] = 'oA_'; $prefix = $conf['table']['prefix']; $oDbh =& OA_DB::singleton(); $table = $oDbh->quoteIdentifier($prefix . 'foo', true); $oTable = new OA_DB_Table(); $query = "CREATE TABLE {$table} ( a INTEGER )"; $oDbh->query($query); $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); $this->assertEqual($aExistingTables[0], 'oA_foo'); $this->assertTrue($oTable->dropTable('oA_foo')); $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); $this->assertEqual(count($aExistingTables), 0, 'Table oA_foo'); //TestEnv::restoreEnv(); }
function _dropTestTables() { $conf =& $GLOBALS['_MAX']['CONF']; $conf['table']['prefix'] = ''; $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); if (in_array('table1', $aExistingTables)) { $this->assertTrue($this->oTable->dropTable('table1'), 'error dropping test table1'); } if (in_array('table2', $aExistingTables)) { $this->assertTrue($this->oTable->dropTable('table2'), 'error dropping test table2'); } $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); $this->assertFalse(in_array('table1', $aExistingTables), '_dropTestTables'); $this->assertFalse(in_array('table2', $aExistingTables), '_dropTestTables'); }
function test_installPackage() { $oPkgMgr = new OX_PluginManager(); $file = MAX_PATH . $this->testpathData . 'zipInstallTest/testPluginPackage.zip'; $oPkgMgr->clearErrors(); //install $this->assertTrue($oPkgMgr->installPackage(array('tmp_name' => $file, 'name' => 'testPluginPackage.zip'))); if (count($oPkgMgr->aErrors)) { foreach ($oPkgMgr->aErrors as $error) { $this->fail($error); } } $path = MAX_PATH . $oPkgMgr->pathPluginsAdmin . 'testPlugin/'; $this->assertTrue(file_exists($path . 'templates/testPlugin.html')); $this->assertTrue(file_exists($path . 'images/testPlugin1.jpg')); $this->assertTrue(file_exists($path . 'images/testPlugin2.jpg')); $this->assertTrue(file_exists($path . 'testPlugin-common.php')); $this->assertTrue(file_exists($path . 'testPlugin-index.php')); $this->assertTrue(file_exists($path . 'testPlugin-page.php')); $this->assertTrue(isset($GLOBALS['_MAX']['CONF']['plugins']['testPluginPackage'])); $this->assertTrue(isset($GLOBALS['_MAX']['CONF']['pluginGroupComponents']['testPlugin'])); $this->assertTrue(isset($GLOBALS['_MAX']['CONF']['testPlugin'])); $this->assertTrue(isset($GLOBALS['_MAX']['CONF']['testPlugin']['setting1'])); $this->assertTrue(isset($GLOBALS['_MAX']['CONF']['testPlugin']['setting2'])); $this->assertTrue(isset($GLOBALS['_MAX']['CONF']['testPlugin']['setting3'])); $doAppVar = OA_Dal::factoryDO('application_variable'); $doAppVar->name = 'tables_testplugin'; $doAppVar->find(true); $this->assertEqual($doAppVar->value, '001'); $doAppVar = OA_Dal::factoryDO('application_variable'); $doAppVar->name = 'testPlugin_version'; $doAppVar->find(true); $this->assertEqual($doAppVar->value, '0.0.1'); $doPrefs = OA_Dal::factoryDO('preferences'); $doPrefs->preference_name = 'testPlugin_preference1'; $doPrefs->find(true); $this->assertEqual($doPrefs->account_type, OA_ACCOUNT_MANAGER); $doPrefs = OA_Dal::factoryDO('preferences'); $doPrefs->preference_name = 'testPlugin_preference2'; $doPrefs->find(true); $this->assertEqual($doPrefs->account_type, OA_ACCOUNT_ADMIN); $aTables = OA_DB_Table::listOATablesCaseSensitive('testPlugin_table'); $this->assertIsA($aTables, 'array'); $doTestPluginTable = OA_Dal::factoryDO('testPlugin_table'); $this->assertIsA($doTestPluginTable, 'DataObjects_Testplugin_table'); $this->assertEqual($id = $doTestPluginTable->insert(), 1); $this->assertTrue($doTestPluginTable->delete()); // try reinstalling $this->assertFalse($oPkgMgr->installPackage(array('tmp_name' => $file, 'name' => 'testPluginPackage.zip'))); $this->assertEqual($oPkgMgr->aErrors[0], "Plugin with this name is already installed testPluginPackage"); //uninstall $oPkgMgr->clearErrors(); $this->assertTrue($oPkgMgr->uninstallPackage('testPluginPackage')); if (count($oPkgMgr->aErrors)) { foreach ($oPkgMgr->aErrors as $error) { $this->fail($error); } } $path = MAX_PATH . $oPkgMgr->pathPluginsAdmin . 'testPlugin/'; $this->assertFalse(file_exists($path . 'templates/testPlugin.html')); $this->assertFalse(file_exists($path . 'images/testPlugin1.jpg')); $this->assertFalse(file_exists($path . 'images/testPlugin2.jpg')); $this->assertFalse(file_exists($path . 'testPlugin-common.php')); $this->assertFalse(file_exists($path . 'testPlugin-index.php')); $this->assertFalse(file_exists($path . 'testPlugin-page.php')); $this->assertFalse(isset($GLOBALS['_MAX']['CONF']['plugins']['testPluginPackage'])); $this->assertFalse(isset($GLOBALS['_MAX']['CONF']['pluginGroupComponents']['testPlugin'])); $this->assertFalse(isset($GLOBALS['_MAX']['CONF']['testPlugin'])); $this->assertFalse(isset($GLOBALS['_MAX']['CONF']['testPlugin']['setting1'])); $this->assertFalse(isset($GLOBALS['_MAX']['CONF']['testPlugin']['setting2'])); $this->assertFalse(isset($GLOBALS['_MAX']['CONF']['testPlugin']['setting3'])); $doAppVar = OA_Dal::factoryDO('application_variable'); $doAppVar->name = 'tables_testplugin'; $doAppVar->find(true); $this->assertNull($doAppVar->value, 'Expected null got ' . $doAppVar->value); $doAppVar = OA_Dal::factoryDO('application_variable'); $doAppVar->name = 'testPlugin_version'; $doAppVar->find(true); $this->assertNull($doAppVar->value, 'Expected null got ' . $doAppVar->value); $doPrefs = OA_Dal::factoryDO('preferences'); $doPrefs->preference_name = 'testPlugin_preference1'; $doPrefs->find(true); $this->assertNull($doPrefs->account_type, 'Expected null got ' . $doPrefs->account_type); $doPrefs = OA_Dal::factoryDO('preferences'); $doPrefs->preference_name = 'testPlugin_preference2'; $doPrefs->find(true); $this->assertNull($doPrefs->account_type, 'Expected null got ' . $doPrefs->account_type); $aTables = OA_DB_Table::listOATablesCaseSensitive('testplugin_table'); $this->assertEqual(count($aTables), 0); TestEnv::restoreConfig(); }
/** * The class constructor method. */ function OA_DB_Table_Core() { parent::OA_DB_Table(); }
function _tableExists($table) { return count(OA_DB_Table::listOATablesCaseSensitive($table)); }
/** * The class constructor method. */ function OA_DB_Table_Statistics() { parent::OA_DB_Table(); $this->temporary = true; }
function _dropTestTableAutoInc($oDbh) { $conf =& $GLOBALS['_MAX']['CONF']; $conf['table']['split'] = false; $oTable = new OA_DB_Table(); $oTable->init($this->path . 'schema_test_autoinc.xml'); $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); if ($this->_tableExists('table1_autoinc', $aExistingTables)) { $this->assertTrue($oTable->dropTable($this->prefix . 'table1_autoinc'), 'error dropping test table1_autoinc'); } $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); $this->assertFalse($this->_tableExists('table1_autoinc', $aExistingTables), '_dropTestTableAutoInc'); }