Skip to content

Commit

Permalink
Builds: sort list by branch ASC and time DESC
Browse files Browse the repository at this point in the history
Previously, the list was sorted by SHA, which would cause the latest
version's download links to be displayed in an unpredictable order.
  • Loading branch information
dregad committed Jan 12, 2017
1 parent 081c06d commit 2e0fcb9
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions builds.php
Expand Up @@ -17,7 +17,9 @@ public function __construct( Traversable $iterator, $callback ) {
}

/**
* Retrieves the list of builds from the specified path
* Retrieves the list of builds from the specified path.
* List will be sorted by branch name ASC and time DESC, (using the zip file's
* timestamp as reference).
* @param string $p_path
* @param array $p_builds
* @param SplFileInfo $p_logfile
Expand Down Expand Up @@ -76,11 +78,33 @@ function get_builds_list( $p_path, &$p_builds, &$p_logfile ) {
if( isset( $t_match[5] ) ) {
$p_builds[$t_sha][$t_ext]['digests'] = $t_file_url;
} else {
$t_time = $t_file->getMTime();
$p_builds[$t_sha][$t_ext]['file'] = $t_file_url;
$p_builds[$t_sha][$t_ext]['time'] = $t_file->getMTime();
$p_builds[$t_sha][$t_ext]['time'] = $t_time;

# Build reference time is the Zip file's timestamp
if( $t_ext == 'zip') {
$p_builds[$t_sha]['time'] = $t_time;
}
}
}
}

# Sort list by branch ASC, timestamp DESC
uasort( $p_builds, function( $a, $b ) {
$t_result = strcmp( $a['branch'], $b['branch'] );
if( $t_result == 0 ) {
if( $a['time'] == $b['time'] ) {
$t_result = 0;
} elseif( $a['time'] > $b['time'] ) {
$t_result = -1;
} else {
$t_result = +1;
}
}
return $t_result;
});

return true;
}

Expand Down

0 comments on commit 2e0fcb9

Please sign in to comment.