svn: /web/php-bugs/trunk/include/ functions.php php_versions.php
| From: | Ferenc Kovacs | Date: | Mon, 18 Jul 2011 00:09:29 +0000 |
| Subject: | svn: /web/php-bugs/trunk/include/ functions.php php_versions.php | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-11685@lists.php.net to get a copy of this message | ||
tyrael Mon, 18 Jul 2011 00:09:29 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=313350
Log:
use the http://qa.php.net/api.php and the http://www.php.net/releases/index.php to
dynamically fetch the supported versions
I think I handled all the corner cases(having an EOLed branch, having an active branch without
alpha/beta/rc releases, etc.), but patches welcome. :)
btw. got a funny bug: I had to change the while+list to a foreach in include/functions.php else it
wouldn't work for the $versions array coming from the apc, will look into this tomorrow.
Changed paths:
U web/php-bugs/trunk/include/functions.php
U web/php-bugs/trunk/include/php_versions.php
Modified: web/php-bugs/trunk/include/functions.php
===================================================================
--- web/php-bugs/trunk/include/functions.php 2011-07-17 23:51:14 UTC (rev 313349)
+++ web/php-bugs/trunk/include/functions.php 2011-07-18 00:09:29 UTC (rev 313350)
@@ -610,7 +610,7 @@
echo '<option value="">--Please Select--</option>' ,
"\n";
require_once "{$ROOT_DIR}/include/php_versions.php";
- while (list(,$v) = each($versions)) {
+ foreach($versions as $v) {
echo '<option';
if ($current == $v) {
echo ' selected="selected"';
Modified: web/php-bugs/trunk/include/php_versions.php
===================================================================
--- web/php-bugs/trunk/include/php_versions.php 2011-07-17 23:51:14 UTC (rev 313349)
+++ web/php-bugs/trunk/include/php_versions.php 2011-07-18 00:09:29 UTC (rev 313350)
@@ -1,26 +1,101 @@
<?php
- $date = date('Y-m-d');
- $versions = array(
- "5.4SVN-{$date} (snap)",
- "5.4SVN-{$date} (SVN)",
- '5.4.0alpha1',
- '5.4.0alpha2',
- '5.3.6',
- "5.3SVN-{$date} (snap)",
- "5.3SVN-{$date} (SVN)",
- '5.2.17',
- "5.2SVN-{$date} (snap)",
- "5.2SVN-{$date} (SVN)",
- "trunk-SVN-{$date} (snap)",
- "trunk-SVN-{$date} (SVN)",
- );
-/*
- This needs a bit tuning to get latest releases of each active branch.
+ /*
+ The versions are pulled from the http://qa.php.net/api.php
+ if you want to add a new version, add it there at include/release-qa.php
+ the result is cached for an hour, you can force it to refresh, if you delete the
'bugs.versions' item from apc
+ the versions are weighted by the following:
+ - major+minor version desc (6>5.4>5.3>trunk)
+ - between a minor version we order by the micro if available: first the qa releases:
alpha/beta/rc, then the stable, then the svn versions(snaps, svn)
+ */
- $foo = unserialize(file_get_contents('http://www.php.net/releases/index.php?serialize=1&max=-1'));
-
- foreach ($foo as $f)
- echo $f['version'], "\n";
+ if (!$versions = apc_fetch('bugs.versions') && false) {
+ $versions = buildVersions();
+ if ($versions) {
+ apc_store('bugs.versions', $versions, 3600);
+ }
+ }
-*/
+ function buildVersions() {
+ $dev_versions = json_decode(file_get_contents('http://qa.php.net/api.php?type=qa-releases&format=json&only=dev_versions'));
+
+ $versions = array();
+
+ $date = date('Y-m-d');
+ $default_versions = array(
+ "SVN-{$date} (snap)",
+ "SVN-{$date} (SVN)",
+ );
+
+ foreach ($dev_versions as $dev_version) {
+ $dev_version_parts = parseVersion($dev_version);
+
+ // if it is a dev version, then add that branch, add the minor-1 version, if it's
appropriate
+ if ($dev_version_parts['type'] == 'dev') {
+ if
(!isset($versions[$dev_version_parts['major']][$dev_version_parts['minor']])) {
+ $versions[$dev_version_parts['major']][$dev_version_parts['minor']] =
array();
+ }
+ }
+ // then it is a qa version (alpha|beta|rc)
+ else {
+ $versions[$dev_version_parts['major']][$dev_version_parts['minor']][$dev_version_parts['micro']]
= $dev_version_parts;
+ ksort($versions[$dev_version_parts['major']][$dev_version_parts['minor']]);
+ }
+ }
+
+ // add the latest stable for the active branches
+ foreach ($versions as $major_number => $major) {
+ $stable_releases = unserialize(file_get_contents('http://www.php.net/releases/index.php?serialize=1&max=20&version='.$major_number));
+ foreach ($major as $minor_number => $minor) {
+ foreach ($stable_releases as $stable_release_number => $stable_release) {
+ if (strpos($stable_release_number, $major_number.'.'.$minor_number) === 0) {
+ $dev_version_parts = parseVersion($stable_release_number);
+ $versions[$dev_version_parts['major']][$dev_version_parts['minor']][$dev_version_parts['micro']]
= $dev_version_parts;
+ ksort($versions[$dev_version_parts['major']][$dev_version_parts['minor']]);
+ break;
+ }
+ }
+ }
+ }
+
+ $flat_versions = array();
+
+ // add trunk to the end of the list
+ foreach ($default_versions as $default_version) {
+ $flat_versions[] = 'trunk-'.$default_version;
+ }
+
+ // add the fetched versions to the list
+ foreach ($versions as $major_number => $major) {
+ foreach ($major as $minor_number => $minor) {
+ // add the default versions to ever minor branch
+ foreach ($default_versions as $default_version) {
+ $flat_versions[] = $major_number.'.'.$minor_number.$default_version;
+ }
+ foreach ($minor as $micro_number => $micro) {
+ $flat_versions[] = $micro['original_version'];
+ }
+ }
+ }
+
+ // reverse the order, this makes it descending
+ $flat_versions = array_reverse($flat_versions);
+
+ return $flat_versions;
+ }
+
+
+ function parseVersion($version){
+ $version_parts = array();
+ $raw_parts = array();
+ preg_match('#(?P<major>\d)\.(?P<minor>\d).(?P<micro>\d)[-]?(?P<type>RC|alpha|beta|dev)?(?P<number>[\d]?).*#ui',
$version, $raw_parts);
+ $version_parts = array(
+ 'major' => $raw_parts['major'],
+ 'minor' => $raw_parts['minor'],
+ 'micro' => $raw_parts['micro'],
+ 'type' =>
strtolower($raw_parts['type']?$raw_parts['type']:'stable'),
+ 'number' => $raw_parts['number'],
+ 'original_version' => $version,
+ );
+ return $version_parts;
+ }
\ No newline at end of file