/** * Try to get platform hash. * If it's upgrade it try to read database (searches old config/preference tables) * If this fails it returns 'OXP_upgrade-unknown_platform_hash' * If it's fresh install then it checks if there is already generated * platformHash by previous call of this method, or use suggested one, or generate new one. * New platform hash is stored as already generated. * * @param string $suggestedPlatformHash * @param boolean $forceCheck should check be done once again (or we can use cached results) * @return string platform Hash */ public function getPlatformHash($suggestedPlatformHash = null, $forceCheck = false) { if (!$forceCheck && isset(self::$foundPlatformHash)) { return self::$foundPlatformHash; } // is it upgrade? $oUpgrader = new OA_Upgrade(); if (!$oUpgrader->isFreshInstall()) { // YES: // prepare database connection data $oUpgrader->canUpgradeOrInstall(); $oUpgrader->initDatabaseConnection(); // try read platform hash from database (3 possible locations) $platformHash = $this->readPlatformHashFromDatabase(); // if can't find platformHash - set 'OXP_upgrade-unknown_platform_hash' $platformHash = $platformHash ? $platformHash : self::$UNKNOWN_PLATFORM_HASH; } else { // NO: // is already set generatedPlatformHash if (isset(self::$generatedPlatformHash)) { $platformHash = self::$generatedPlatformHash; } else { // use sugested or generate new one (and remember) if (isset($suggestedPlatformHash)) { $platformHash = $suggestedPlatformHash; } else { $platformHash = OA_Dal_ApplicationVariables::generatePlatformHash(); } // remember genereted platform hash self::$generatedPlatformHash = $platformHash; } } self::$foundPlatformHash = $platformHash; return $platformHash; }
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 test_runScript() { $aExpectation = $this->_generateTestData(); $oUpgrade = new OA_Upgrade(); $oUpgrade->initDatabaseConnection(); $this->assertTrue($oUpgrade->runScript('postscript_openads_upgrade_2.7.11-dev.php')); $this->_assertTestData($aExpectation); DataGenerator::cleanUp(); }
function expandOSURow($id) { $oUpgrader = new OA_Upgrade(); $oUpgrader->initDatabaseConnection(); $html = getDBAuditTable($oUpgrader->oAuditor->queryAuditBackupTablesByUpgradeId($id)); $objResponse = new xajaxResponse(); $objResponse->addAssign('cell_' . $id, "style.display", 'block'); $objResponse->addAssign('cell_' . $id, 'text-align', 'center'); $objResponse->addAssign('cell_' . $id, 'innerHTML', $html); $objResponse->addAssign('img_expand_' . $id, "style.display", 'none'); $objResponse->addAssign('img_collapse_' . $id, "style.display", 'inline'); $objResponse->addAssign('text_expand_' . $id, "style.display", 'none'); $objResponse->addAssign('text_collapse_' . $id, "style.display", 'inline'); $objResponse->addAssign('info_expand_' . $id, "style.display", 'none'); $objResponse->addAssign('info_collapse_' . $id, "style.display", 'inline'); return $objResponse; }
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(); }
function testUpdate() { $oUpgrade = new OA_Upgrade(); $this->oConfiguration = $oUpgrade->oConfiguration; $oUpgrade->initDatabaseConnection(); // run the upgrade Mock::generatePartial('OA_UpgradePostscript_2_5_67', $mockName = 'OA_UpgradePostscript_2_5_67_' . rand(), array('logOnly', 'logError')); $oMockPostUpgrade = new $mockName($this); $oMockPostUpgrade->oUpgrade =& $oUpgrade; $aContexts = array_keys($oMockPostUpgrade->aContexts); $aTables = array_values($oMockPostUpgrade->aContexts); array_push($aTables, 'audit'); $this->initDatabase(581, $aTables); array_pop($aTables); // prepare data $tblAudit = $this->oDbh->quoteIdentifier($this->getPrefix() . 'audit', true); foreach ($aContexts as $i => $context) { $query = "INSERT INTO {$tblAudit} (actionid, context, details, userid, usertype, account_id) VALUES ({$i}, '{$context}', 'details', 1, 0, 1)"; $this->oDbh->exec($query); } $query = "SELECT actionid, context FROM {$tblAudit}"; $result = $this->oDbh->queryAll($query); $this->assertIsA($result, 'array'); foreach ($result as $i => $row) { $this->assertEqual($row['context'], $aContexts[$row['actionid']]); //$aData[$row['actionid']]['original']); } $oMockPostUpgrade->updateAuditContext(); // test results $query = "SELECT actionid, context FROM {$tblAudit}"; $result = $this->oDbh->queryAll($query); $this->assertIsA($result, 'array'); foreach ($result as $i => $row) { $this->assertEqual($row['context'], $aTables[$row['actionid']]); //$aData[$row['actionid']]['expected']); } }
/** * tests an upgrade package containing two schema upgrades * */ function test_upgradeSchemas() { $this->_deleteTestAppVarRecord('tables_core', ''); $this->assertEqual($this->_getTestAppVarValue('tables_core', ''), '', ''); $this->_createTestAppVarRecord('tables_core', '997'); $this->assertEqual($this->_getTestAppVarValue('tables_core', '997'), '997', ''); $this->_createTestAppVarRecord('oa_version', '2.3.00'); $oUpgrade->versionInitialSchema['tables_core'] = 997; $oUpgrade->versionInitialApplication = '2.3.00'; $oUpgrade = new OA_Upgrade(); $oUpgrade->upgradePath = MAX_PATH . '/lib/OA/Upgrade/tests/data/'; $oUpgrade->oDBUpgrader->path_changes = $oUpgrade->upgradePath; $oUpgrade->oDBUpgrader->path_schema = $oUpgrade->upgradePath; $input_file = 'openads_upgrade_2.3.00_to_2.3.02_beta.xml'; $oUpgrade->initDatabaseConnection(); $oUpgrade->_parseUpgradePackageFile($oUpgrade->upgradePath . $input_file); $this->assertTrue($oUpgrade->upgradeSchemas(), 'upgradeSchemas'); $this->_checkTablesUpgraded($oUpgrade); $this->assertEqual($this->_getTestAppVarValue('tables_core', '999'), '999', ''); // remove the fake application variable records $this->_deleteTestAppVarRecordAllNames('oa_version'); $this->_deleteTestAppVarRecordAllNames('tables_core'); TestEnv::restoreConfig(); TestEnv::restoreEnv(); }
//$schemas.= sprintf($td, "<input type=\"checkbox\" id=\"chk_tbl[{$aRec['database_action_id']}]\" name=\"chk_tbl[{$aRec['database_action_id']}]\" checked />"); $schemas .= "</tr>"; $totalSize = $totalSize + $aRec['backup_size']; $totalRows = $totalRows + $aRec['backup_rows']; } $schemas .= "<tr>"; $schemas .= sprintf($th, 'Total'); $schemas .= sprintf($th, count($aAudit) . ' tables'); $schemas .= sprintf($th, round($totalSize * 10, 2) . ' kb'); $schemas .= sprintf($th, $totalRows); //$schemas.= sprintf($th, 'Delete'); $schemas .= "</tr>"; $schemas .= "</table>"; return $schemas; } $oUpgrader->initDatabaseConnection(); if (array_key_exists('btn_clean_audit', $_POST)) { $upgrade_id = $_POST['upgrade_action_id']; $oUpgrader->oAuditor->cleanAuditArtifacts($upgrade_id); } $aAudit = $oUpgrader->oAuditor->queryAuditAllDescending(); /*-------------------------------------------------------*/ /* Error handling */ /*-------------------------------------------------------*/ $aErrors = $oUpgrader->getErrors(); if (count($aErrors) > 0) { ?> <div class='errormessage'><img class='errormessage' src='<?php echo OX::assetPath(); ?> /images/errormessage.gif' width='16' height='16' border='0' align='absmiddle'>