Ejemplo n.º 1
0
 /**
  * Initializes the $oaTable with the schema specified by $schemaPath.
  * The $schemaPath is a path to the schema relative to the max installation
  * directory, e.g. '/etc/tables_core.xml'.
  *
  * @param unknown_type $schemaPath
  */
 function initOaTable($schemaPath)
 {
     $this->oaTable = new OA_DB_Table();
     $result = $this->oaTable->init(MAX_PATH . $schemaPath);
     if (PEAR::isError($result)) {
         return false;
     }
     return true;
 }
 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();
 }
Ejemplo n.º 3
0
 /**
  * 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()
 {
     $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();
 }
Ejemplo n.º 5
0
 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');
 }
 /**
  * the action_table_name table must exist for all upgrade events
  * currently the schema is stored in a separate xml file which is not part of an upgrade pkg
  * eventually this table schema should be merged into the core tables schema
  *
  * @return boolean
  */
 function _createAuditTable()
 {
     $xmlfile = MAX_PATH . $this->action_table_xml_filename;
     $oTable = new OA_DB_Table();
     $oTable->init($xmlfile);
     return $oTable->createTable($this->logTable);
 }
Ejemplo n.º 8
0
 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');
 }
 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');
 }
Ejemplo n.º 10
0
 /**
  * test reseting of all sequences
  *
  * @return boolean true on success, false otherwise
  */
 function test_resetAllSequences()
 {
     $oDbh =& OA_DB::singleton();
     //        if ($oDbh->dbsyntax == 'pgsql')
     //        {
     //            $sequence = 'test_table1_test_id1_seq';
     //        }
     //        else if ($oDbh->dbsyntax == 'mysql')
     //        {
     //            $sequence = 'test_table1';
     //        }
     $conf =& $GLOBALS['_MAX']['CONF'];
     $conf['table']['prefix'] = '';
     $oTable = new OA_DB_Table();
     $this->_writeSequenceTestDatabaseSchema();
     $oTable->init(MAX_PATH . '/var/test.xml');
     $oTable->createAllTables();
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     $this->assertEqual($aExistingTables[0], 'test_table1');
     $this->assertEqual($aExistingTables[1], 'test_table2');
     if ($oDbh->dbsyntax == 'pgsql') {
         OA_DB::setCaseSensitive();
         $aSequences = $oDbh->manager->listSequences();
         OA_DB::disableCaseSensitive();
         $this->assertEqual($aSequences[0], 'test_table1_test_id1');
         $this->assertEqual($aSequences[1], 'test_table2_test_id2');
     }
     // table1
     for ($i = 1; $i < 11; $i++) {
         $query = "INSERT INTO " . $oDbh->quoteIdentifier('test_table1', true) . " (test_desc1) VALUES ('{$i}')";
         $oDbh->query($query);
     }
     $query = "SELECT * FROM " . $oDbh->quoteIdentifier('test_table1', true);
     $aRows = $oDbh->queryAll($query);
     $this->assertEqual(count($aRows), 10, 'incorrect number of rows in test_table1');
     reset($aRows);
     foreach ($aRows as $k => $v) {
         $this->assertTrue($v['test_id1'] == $v['test_desc1'], 'sequence problem with new table');
     }
     $query = "DELETE FROM " . $oDbh->quoteIdentifier('test_table1', true);
     $oDbh->query($query);
     $query = "SELECT * FROM " . $oDbh->quoteIdentifier('test_table1', true);
     $aRows = $oDbh->queryAll($query);
     $this->assertEqual(count($aRows), 0, 'failed to delete rows from test_table1');
     // table2
     for ($i = 1; $i < 11; $i++) {
         $query = "INSERT INTO " . $oDbh->quoteIdentifier('test_table2', true) . " (test_desc2) VALUES ('{$i}')";
         $oDbh->query($query);
     }
     $query = "SELECT * FROM " . $oDbh->quoteIdentifier('test_table2', true);
     $aRows = $oDbh->queryAll($query);
     $this->assertEqual(count($aRows), 10, 'incorrect number of rows in test_table2');
     reset($aRows);
     foreach ($aRows as $k => $v) {
         $this->assertTrue($v['test_id2'] == $v['test_desc2'], 'sequence problem with new table');
     }
     $query = "DELETE FROM " . $oDbh->quoteIdentifier('test_table2', true);
     $oDbh->query($query);
     $query = "SELECT * FROM " . $oDbh->quoteIdentifier('test_table2', true);
     $aRows = $oDbh->queryAll($query);
     $this->assertEqual(count($aRows), 0, 'failed to delete rows from test_table2');
     $this->assertTrue($oTable->resetAllSequences(), 'failed to reset all sequences');
     // table1
     for ($i = 1; $i < 11; $i++) {
         $query = "INSERT INTO " . $oDbh->quoteIdentifier('test_table1', true) . " (test_desc1) VALUES ('{$i}')";
         $oDbh->query($query);
     }
     $query = "SELECT * FROM " . $oDbh->quoteIdentifier('test_table1', true);
     $aRows = $oDbh->queryAll($query);
     $this->assertEqual(count($aRows), 10, 'incorrect number of rows in test_table1');
     reset($aRows);
     foreach ($aRows as $k => $v) {
         $this->assertTrue($v['test_id1'] == $v['test_desc1'], 'sequence problem after reset: ' . $v['test_id1'] . '=>' . $v['test_desc1']);
     }
     $oTable->dropTable('test_table1');
     // table2
     for ($i = 1; $i < 11; $i++) {
         $query = "INSERT INTO " . $oDbh->quoteIdentifier('test_table2', true) . " (test_desc2) VALUES ('{$i}')";
         $oDbh->query($query);
     }
     $query = "SELECT * FROM " . $oDbh->quoteIdentifier('test_table2', true);
     $aRows = $oDbh->queryAll($query);
     $this->assertEqual(count($aRows), 10, 'incorrect number of rows in test_table2');
     reset($aRows);
     foreach ($aRows as $k => $v) {
         $this->assertTrue($v['test_id2'] == $v['test_desc2'], 'sequence problem after reset: ' . $v['test_id2'] . '=>' . $v['test_desc2']);
     }
     $oTable->dropTable('test_table2');
     @unlink(MAX_PATH . '/var/test.xml');
 }
 /**
  * internal function to set up some test tables
  *
  * @param mdb2 connection $oDbh
  */
 function _createTestTables($oDbh)
 {
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     if (!$this->_tableExists('z_test1', $aExistingTables)) {
         $conf =& $GLOBALS['_MAX']['CONF'];
         //$conf['table']['prefix'] = '';
         $oTable = new OA_DB_Table();
         $oTable->init($this->path . 'schema_test_backups.xml');
         $this->assertTrue($oTable->createTable('z_test1'), 'error creating test table1');
         $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
         $this->assertTrue($this->_tableExists('z_test1', $aExistingTables), '_createTestTables');
         return $oTable->aDefinition;
     }
     return false;
 }
 function test_Tables()
 {
     $prefix = $GLOBALS['_MAX']['CONF']['table']['prefix'];
     $oTable = new OA_DB_Table();
     $oTable->init(MAX_PATH . $this->testpathPackages . 'testPlugin/etc/tables_testplugin.xml');
     $version = $oTable->aDefinition['version'];
     $oPluginManager = new OX_Plugin_ComponentGroupManager();
     $oPluginManager->pathPackages = $this->testpathPackages;
     $aSchema = array('mdb2schema' => 'tables_testplugin');
     $aDbTables = OA_DB_Table::listOATablesCaseSensitive('testplugin_table');
     $this->assertEqual(count($aDbTables), 0);
     $this->assertEqual($oPluginManager->_createTables('testPlugin', $aSchema), $version);
     $aDbTables = OA_DB_Table::listOATablesCaseSensitive('testplugin_table');
     $this->assertEqual(count($aDbTables), 1);
     $this->assertEqual($aDbTables[0], $prefix . 'testplugin_table');
     $this->assertTrue($oPluginManager->_dropTables('testPlugin', $aSchema));
     $aDbTables = OA_DB_Table::listOATablesCaseSensitive('testplugin_table');
     $this->assertEqual(count($aDbTables), 0);
 }