Exemple #1
0
 /**
  * Check administrator login during the upgrade steps
  *
  * @return boolean True if login succeded
  */
 function checkLogin()
 {
     if (empty($_COOKIE['oat']) || $_COOKIE['oat'] != OA_UPGRADE_UPGRADE) {
         return true;
     }
     // Clean up session
     $GLOBALS['session'] = array();
     // Detection needs to happen every time to make sure that database parameters are
     $oUpgrader = new OA_Upgrade();
     $openadsDetected = $oUpgrader->detectOpenads(true) || $oUpgrader->existing_installation_status == OA_STATUS_CURRENT_VERSION;
     // Sequentially check, to avoid useless work
     if (!$openadsDetected) {
         if (!($panDetected = $oUpgrader->detectPAN(true))) {
             if (!($maxDetected = $oUpgrader->detectMAX(true))) {
                 if (!($max01Detected = $oUpgrader->detectMAX01(true))) {
                     // No upgrade-able version detected, return
                     return false;
                 }
             }
         }
     }
     phpAds_SessionStart();
     OA_Upgrade_Login::readSession($panDetected);
     $oPlugin = new Plugins_Authentication();
     if ($oPlugin->suppliedCredentials()) {
         // The new Users, Account, Permissions & Preference feature was introduced in OpenX 2.5.46-dev
         $newLogin = $openadsDetected && version_compare($oUpgrader->versionInitialApplication, '2.5.46-dev', '>=') == -1;
         if ($newLogin) {
             OA_Upgrade_Login::_checkLoginNew();
         } else {
             if ($openadsDetected || $maxDetected) {
                 OA_Upgrade_Login::_checkLoginOld('preference', true);
             } elseif ($max01Detected) {
                 OA_Upgrade_Login::_checkLoginOld('config', true);
             } elseif ($panDetected) {
                 OA_Upgrade_Login::_checkLoginOld('config', false);
             } else {
                 return false;
             }
         }
     }
     return OA_Permission::isAccount(OA_ACCOUNT_ADMIN) || OA_Permission::isUserLinkedToAdmin();
 }
 /**
  * tests an openads upgrade where a series of upgrade packages may be required
  * the upgrade method will detectOpenXand cycle through the list of upgrade packages
  * executing the upgrade packages in the right order
  * until it runs out of upgrade packages
  * when no more upgrade packages are found
  * the application is stamped with the latest version
  *
  */
 function test_upgradeIncremental()
 {
     $oUpgrade = new OA_Upgrade();
     Mock::generatePartial('OA_Upgrade_Config', $mockConfig = 'OA_Upgrade_Config' . rand(), array('backupConfig', 'mergeConfig', 'setupConfigDatabase', 'setupConfigTable', 'setValue', 'writeConfig', 'getConfigBackupName', 'clearConfigBackupName', 'setBulkValue'));
     $oUpgrade->oConfiguration = new $mockConfig($this);
     $oUpgrade->oConfiguration->setReturnValue('setupConfigDatabase', true);
     $oUpgrade->oConfiguration->setReturnValue('setupConfigTable', true);
     $oUpgrade->oConfiguration->setReturnValue('setValue', true);
     $oUpgrade->oConfiguration->setReturnValue('writeConfig', true);
     $oUpgrade->oConfiguration->expectCallCount('backupConfig', 1);
     $oUpgrade->oConfiguration->setReturnValue('backupConfig', true);
     $oUpgrade->oConfiguration->expectCallCount('mergeConfig', 1);
     $oUpgrade->oConfiguration->setReturnValue('mergeConfig', true);
     $oUpgrade->oConfiguration->expectCallCount('getConfigBackupName', 13);
     for ($i = 0; $i < 13; $i++) {
         $oUpgrade->oConfiguration->setReturnValueAt($i, 'getConfigBackupName', $i . '_old.www.mysite.net.conf.php');
         // drop a fake conf backup
         @copy(MAX_PATH . '/var/test.conf.php', MAX_PATH . '/var/' . $i . '_old.www.mysite.net.conf.php');
     }
     // divert objects to test data
     $oUpgrade->upgradePath = MAX_PATH . '/lib/OA/Upgrade/tests/data/changes/';
     $GLOBALS['_MAX']['CONF']['openads']['installed'] = true;
     $this->_dropTestTable($oUpgrade->oDbh, 'database_action');
     $this->_dropTestTable($oUpgrade->oDbh, 'upgrade_action');
     // just in case of error, lose this so we can continue afresh
     $oUpgrade->_pickupRecoveryFile();
     // fake the versions we are starting with
     $this->_createTestAppVarRecord('oa_version', '2.3.32-beta-rc1');
     // mock the integrity checker
     Mock::generatePartial('OA_DB_Integrity', $mockInteg = 'OA_DB_Integrity' . rand(), array('checkIntegrityQuick'));
     $oUpgrade->oIntegrity = new $mockInteg($this);
     $oUpgrade->oIntegrity->setReturnValue('checkIntegrityQuick', true);
     // do the initial detection
     $this->assertTrue($oUpgrade->detectOpenads());
     // this should identify 12 upgrade packages to be executed
     // (from /lib/OA/Upgrade/tests/data/changes)
     $this->assertEqual(count($oUpgrade->aPackageList), 12, 'wrong number of packages in upgrader package list');
     $this->assertIsA($oUpgrade->oAuditor, 'OA_UpgradeAuditor', 'class mismatch: OA_UpgradeAuditor');
     // perform the upgrade
     $this->assertTrue($oUpgrade->upgrade(), 'upgrade');
     $aAudit = $oUpgrade->oAuditor->queryAuditAllDescending();
     // we should have 13 records in the upgrade_action audit table
     // we should have 13 logfiles in the var folder
     // one for each package plus a version stamp
     $this->assertEqual(count($aAudit), 13, 'wrong number of audit records');
     $aPackageList = $oUpgrade->aPackageList;
     krsort($aPackageList, SORT_NUMERIC);
     foreach ($aAudit as $k => $aRec) {
         $idx = 12 - $k;
         $this->assertEqual($aRec['upgrade_action_id'], $idx + 1, '');
         $this->assertEqual($aRec['confbackup'], $idx . '_old.www.mysite.net.conf.php');
         $this->assertTrue(file_exists(MAX_PATH . '/var/' . $aRec['logfile']));
         @unlink(MAX_PATH . '/var/' . $aRec['logfile']);
         if ($k > 0) {
             $this->assertEqual($aRec['upgrade_name'], $aPackageList[$idx], 'package mismatch: ' . $aRec['upgrade_name'] . ' and ' . $aPackageList[$idx]);
         } else {
             $this->assertEqual($aRec['upgrade_name'], 'openads_version_stamp_' . VERSION, 'wrong package name for version stamp');
         }
     }
     // the application variable should match the code version stamp
     $this->assertEqual($oUpgrade->versionInitialApplication, VERSION, 'wrong initial application version: ' . $oUpgrade->versionInitialApplication);
     //        $this->_deleteTestAppVarRecordAllNames('oa_version');
     $oUpgrade->oConfiguration->tally();
     $oUpgrade->oIntegrity->tally();
     TestEnv::restoreConfig();
 }