/** * Returns phpAdsNew style config version. * * The OpenX version "number" is converted to an int using the following table: * * 'beta-rc' => 0.1 * 'beta' => 0.2 * 'rc' => 0.3 * '' => 0.4 * * i.e. * v0.3.29-beta-rc10 becomes: * 0 * 1000 + * 3 * 100 + * 29 * 1 + // Cannot exceed 100 patch releases! * 0.1 + * 10 / 1000 = * ------------- * 3293.1 */ function getConfigVersion($version) { $a = array('dev' => -0.001, 'beta-rc' => 0.1, 'beta' => 0.2, 'rc' => 0.3, 'stable' => 0.4); $version = RV::stripVersion(strtolower($version), array('dev', 'stable')); if (preg_match('/^v/', $version)) { $v = preg_split('/[.-]/', substr($version, 1)); } else { $v = preg_split('/[.-]/', $version); } if (count($v) < 3) { return false; } // Prepare value from the first 3 items $returnValue = $v[0] * 1000 + $v[1] * 100 + $v[2]; // How many items were there? if (count($v) == 5) { // Check that it is a beta-rc release if (!$v[3] == 'beta' || !preg_match('/^rc(\\d+)/', $v[4], $aMatches)) { return false; } // Add the beta-rc $returnValue += $a['beta-rc'] + $aMatches[1] / 1000; return $returnValue; } else { if (count($v) == 4) { // Check that it is a tag or rc numer if (isset($a[$v[3]])) { // Add the beta $returnValue += $a[$v[3]]; return $returnValue; } else { if (preg_match('/^rc(\\d+)/', $v[3], $aMatches)) { // Add the rc $returnValue += $a['rc'] + $aMatches[1] / 1000; return $returnValue; } } return false; } } // Stable release $returnValue += $a['stable']; return $returnValue; }
/** * walk an array of version information to build a list of required upgrades * they must be in the RIGHT order!!! * hence the weird sorting of keys etc.. */ function getUpgradePackageList($verPrev, $aVersions = null) { $verPrev = RV::stripVersion($verPrev); $aFiles = array(); if (is_array($aVersions)) { ksort($aVersions, SORT_NUMERIC); foreach ($aVersions as $release => $aMajor) { ksort($aMajor, SORT_NUMERIC); foreach ($aMajor as $major => $aMinor) { ksort($aMinor, SORT_NUMERIC); foreach ($aMinor as $minor => $aStatus) { if (array_key_exists('-beta-rc', $aStatus)) { $aKeys = array_keys($aStatus['-beta-rc']); sort($aKeys, SORT_NUMERIC); foreach ($aKeys as $k => $v) { $version = $release . '.' . $major . '.' . $minor . '-beta-rc' . $v; if (version_compare($verPrev, $version) < 0) { $aFiles[] = $aStatus['-beta-rc'][$v]['file']; } } } if (array_key_exists('-beta', $aStatus)) { $aBeta = $aStatus['-beta']; foreach ($aBeta as $key => $file) { $version = $release . '.' . $major . '.' . $minor . '-beta'; if (version_compare($verPrev, $version) < 0) { $aFiles[] = $file; } } } if (array_key_exists('-dev', $aStatus)) { $aDev = $aStatus['-dev']; foreach ($aDev as $key => $file) { $version = $release . '.' . $major . '.' . $minor . '-dev'; if (version_compare($verPrev, $version) < 0) { $aFiles[] = $file; } } } if (array_key_exists('-rc', $aStatus)) { $aKeys = array_keys($aStatus['-rc']); sort($aKeys, SORT_NUMERIC); foreach ($aKeys as $k => $v) { $version = $release . '.' . $major . '.' . $minor . '-rc' . $v; if (version_compare($verPrev, $version) < 0) { $aFiles[] = $aStatus['-rc'][$v]['file']; } } } if (array_key_exists('-RC', $aStatus)) { $aKeys = array_keys($aStatus['-RC']); sort($aKeys, SORT_NUMERIC); foreach ($aKeys as $k => $v) { $version = $release . '.' . $major . '.' . $minor . '-RC' . $v; if (version_compare($verPrev, $version) < 0) { $aFiles[] = $aStatus['-RC'][$v]['file']; } } } if (array_key_exists('file', $aStatus)) { $version = $release . '.' . $major . '.' . $minor; if (version_compare($verPrev, $version) < 0) { $aFiles[] = $aStatus['file']; } } } } } } return $aFiles; }