/**
  * 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 testCanUpgradeOrInstall()
 {
     // run once upgrade or install
     $oUpgrade = new OA_Upgrade();
     $firstResult = $oUpgrade->canUpgradeOrInstall();
     $existing_installation_status = $oUpgrade->existing_installation_status;
     $aPackageList = $oUpgrade->aPackageList;
     $aMessages = $oUpgrade->getMessages();
     $oUpgrade->oLogger->logClear();
     $oUpgrade->aPackageList = array();
     $oUpgrade->existing_installation_status = 235234;
     // run another one and check values
     $this->assertEqual($oUpgrade->canUpgradeOrInstall(), $firstResult);
     $this->assertEqual($oUpgrade->existing_installation_status, $existing_installation_status);
     $this->assertEqual($oUpgrade->aPackageList, $aPackageList);
     $this->assertEqual($oUpgrade->getMessages(), $aMessages);
 }
 /**
  * Checks if upgrader discovered schema which is old and stores stats
  * in server time rather than UTC.
  *
  * @param OA_Upgrade $oUpgrader
  */
 public static function hasZoneError($oUpgrader)
 {
     $tzoneErr = false;
     if ($oUpgrader->canUpgradeOrInstall()) {
         // Timezone support check
         if ($oUpgrader->existing_installation_status != OA_STATUS_NOT_INSTALLED) {
             if ($oUpgrader->versionInitialSchema['tables_core'] < 538) {
                 // Non TZ-enabled database
                 $tzoneErr = true;
             }
         }
     }
     return $tzoneErr;
 }
 /**
  * Look for existing installations (phpAdsNew, MMM, Openads)
  * retrieve details and check for errors
  * Allows to limit calls to canUpgradeInit in one thread by storing it's results
  *
  * @param boolean $forceCheck should canUpgradeInit be called anyway
  * @return boolean true if can install or upgrade application, false if can't upgrade or it's current installation
  */
 public function canUpgradeOrInstall($forceCheck = false)
 {
     if ($forceCheck || !isset(self::$canUpgradeOrInstall)) {
         $result = $this->canUpgradeInit();
         self::$canUpgradeOrInstall = array('result' => $result, 'existing_installation_status' => $this->existing_installation_status, 'versionInitialApplication' => isset($this->versionInitialApplication) ? $this->versionInitialApplication : null, 'tables_core' => isset($this->versionInitialSchema['tables_core']) ? $this->versionInitialSchema['tables_core'] : null, 'package0' => isset($this->aPackageList[0]) ? $this->aPackageList[0] : null, 'aDsn-database' => $this->aDsn['database'], 'aDsn-table' => $this->aDsn['table'], 'upgrading_from_milestone_version' => $this->upgrading_from_milestone_version, 'globals-database' => $GLOBALS['_MAX']['CONF']['database'], 'globals-table' => $GLOBALS['_MAX']['CONF']['table'], 'oLogger' => clone $this->oLogger);
     } else {
         // restore results from self::$canUpgradeOrInstall
         $aResult = self::$canUpgradeOrInstall;
         $this->existing_installation_status = $aResult['existing_installation_status'];
         if (isset($aResult['versionInitialApplication'])) {
             $this->versionInitialApplication = $aResult['versionInitialApplication'];
         }
         if (isset($aResult['tables_core'])) {
             $this->versionInitialSchema['tables_core'] = $aResult['tables_core'];
         }
         if (isset($aResult['package0'])) {
             $this->aPackageList[0] = $aResult['package0'];
         }
         $this->aDsn['database'] = $aResult['aDsn-database'];
         $this->aDsn['table'] = $aResult['aDsn-table'];
         $this->upgrading_from_milestone_version = $aResult['upgrading_from_milestone_version'];
         $GLOBALS['_MAX']['CONF']['database'] = $aResult['globals-database'];
         $GLOBALS['_MAX']['CONF']['table'] = $aResult['globals-table'];
         $this->oLogger = $aResult['oLogger'];
     }
     return self::$canUpgradeOrInstall['result'];
 }