/** * rollback the upgrade executed during the previous test * copy the *fake* RECOVER file to the var folder * check the audit trail * delete the RECOVER file after * */ function test_recoverUpgrade() { $host = OX_getHostName(); $confFile = $host . '.conf.php'; if (file_exists(MAX_PATH . '/var/test_' . $confFile)) { if (!@unlink(MAX_PATH . '/var/test_' . $confFile)) { $this->oLogger->logError('failed to remove the backup configuration file'); return false; } } if (file_exists(MAX_PATH . '/var/' . $confFile)) { if (!copy(MAX_PATH . '/var/' . $confFile, MAX_PATH . '/var/test_' . $confFile)) { $this->assertTrue(false, 'test failed to backup conf file before upgrade recovery'); return false; } } $oUpgrade = new OA_Upgrade(); $oUpgrade->_pickupRecoveryFile(); $this->_writeTestRecoveryFile(); $oUpgrade->recoverUpgrade(); if (file_exists(MAX_PATH . '/var/' . $confFile)) { if (!@unlink(MAX_PATH . '/var/' . $confFile)) { $this->oLogger->logError('failed to remove the backup configuration file'); return false; } } if (file_exists(MAX_PATH . '/var/test_' . $confFile)) { if (!copy(MAX_PATH . '/var/test_' . $confFile, MAX_PATH . '/var/' . $confFile)) { $this->assertTrue(false, 'test failed to restore the test conf file after upgrade recovery'); return false; } @unlink(MAX_PATH . '/var/test_' . $confFile); } $aAudit = $oUpgrade->oAuditor->queryAuditAllDescending(); // we should have another 13 records in the upgrade_action audit table // we should have another 13 logfiles in the var folder // we should have 13 backup conf files in the var folder // one for each of the 12 packages plus a version stamp *package* $this->assertEqual(count($aAudit), 26, 'wrong number of audit records'); foreach ($aAudit as $k => $aRec) { $idx = 25 - $k; if ($idx > 12) { $this->assertEqual($aRec['upgrade_action_id'], $idx + 1, ''); $this->assertEqual($aRec['action'], UPGRADE_ACTION_ROLLBACK_SUCCEEDED, 'wrong action definition'); $result = $oUpgrade->oAuditor->queryAuditByUpgradeId($k + 1); $this->assertIsA($result, 'array', 'failed to retrieve the original audit record array'); $this->assertTrue(isset($result[0]), 'failed to retrieve the original audit record'); $aOriginalAuditRec = $result[0]; $this->assertEqual($aOriginalAuditRec['confbackup'], 'dropped during recovery', 'failure to audit that conf was dropped'); //$aOriginalAuditRec['confbackup']); // recovery should restore then drop the backup tables if (file_exists(MAX_PATH . '/var/' . ($k + 11) . '_old.www.mysite.net.conf.php')) { $this->assertFalse(true, 'conf backup was not deleted'); @unlink(MAX_PATH . '/var/' . ($k + 11) . '_old.www.mysite.net.conf.php'); } $this->assertTrue(file_exists(MAX_PATH . '/var/' . $aRec['logfile']), 'logfile does not exist'); $this->assertEqual($aRec['logfile'], $aOriginalAuditRec['logfile'] . '.rollback', 'wrong log file'); @unlink(MAX_PATH . '/var/' . $aRec['logfile']); $this->assertEqual($aRec['upgrade_name'], $aOriginalAuditRec['upgrade_name'], 'package mismatch: ' . $aRec['upgrade_name'] . ' and ' . $aOriginalAuditRec['upgrade_name']); } } // the application variable should match the initial version given in the previous test $this->assertEqual($oUpgrade->oVersioner->getApplicationVersion(), '2.3.32-beta-rc1', 'wrong initial application version: ' . $oUpgrade->versionInitialApplication); $this->assertFalse(file_exists($oUpgrade->recoveryFile), 'recovery file was not deleted after recovery'); // just in case of error, lose the recovery file so we can continue afresh // and not screw up someone's installation next time they run $oUpgrade->_pickupRecoveryFile(); // delete the *restored* dummy conf file @unlink(MAX_PATH . '/var/www.mysite.net.conf.php'); }
function checkFolderPermissions($folder) { if (!file_exists($folder)) { return false; } elseif (!is_writable($folder)) { return false; } return true; } if (array_key_exists('btn_startagain', $_POST)) { // Delete the cookie if user is restarting upgrader setcookie('oat', ''); } if ($oUpgrader->isRecoveryRequired()) { if (array_key_exists('btn_recovery', $_POST)) { $oUpgrader->recoverUpgrade(); $action = OA_UPGRADE_RECOVERY; } else { $action = OA_UPGRADE_RECOVERY_INFORM; } } else { if (array_key_exists('btn_syscheck', $_POST) || $_POST['dirPage'] == OA_UPGRADE_SYSCHECK) { // store checkForUpdates value into session, so that they can be inserted into DB once DB has been created session_start(); // Always check for updates $_SESSION['checkForUpdates'] = true; $aSysInfo = $oUpgrader->checkEnvironment(); // Do not check for an upgrade package if environment errors exist if (!$aSysInfo['PERMS']['error'] && !$aSysInfo['PHP']['error'] && !$aSysInfo['FILES']['error']) { $halt = !$oUpgrader->canUpgrade(); $installStatus = $oUpgrader->existing_installation_status;