Commit d3af6bc0 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge "Bug 1844838: Show more versioning info on site info block"

parents 68facdda 22a6111e
......@@ -323,8 +323,11 @@ $string['statsmaxquotaused1'] = 'Has used about %s of disk quota<br>(<a href="%s
$string['groupcountsbytype'] = 'Number of groups by group type';
$string['groupcountsbyjointype'] = 'Number of groups by access type';
$string['blockcountsbytype'] = 'Most frequently used blocks in portfolio pages';
$string['uptodate'] = 'up to date';
$string['latestversionis'] = 'latest version is <a href="%s">%s</a>';
$string['uptodate'] = 'Your local codebase is up to date with Mahara core.';
$string['latestversionis'] = 'Most recent major release: <a href="%s">%s</a>';
$string['latestbranchversionis'] = 'Latest minor version of this release: <a href="%s">%s</a>';
$string['versionnotinsupport'] = '%s is out of support.';
$string['versionnotinsupportdev'] = 'Development version not in support';
$string['viewsbytype'] = 'Pages by type';
$string['institutionloginstabletitle'] = 'Active institutions';
$string['institutionloginstablesubtitle'] = 'For %s - %s';
......
......@@ -4426,38 +4426,45 @@ function cron_clean_internal_activity_notifications() {
* Cronjob to check Launchpad for the latest Mahara version
*/
function cron_check_for_updates() {
$url = 'https://mahara.org/local/versions.php';
$request = array(
CURLOPT_URL => 'https://launchpad.net/mahara/+download',
CURLOPT_URL => $url,
);
$result = mahara_http_request($request);
if (!empty($result->errno)) {
log_debug('Could not retrieve launchpad download page');
if (!empty($result->errno) || $result->info['http_code'] != '200') {
log_debug('Could not access Mahara.org for versioning information.');
return;
}
$page = new DOMDocument();
libxml_use_internal_errors(true);
$success = $page->loadHTML($result->data);
libxml_use_internal_errors(false);
if (!$success) {
log_debug('Error parsing launchpad download page');
$data = json_decode($result->data);
if ($data->returnCode == 1) {
log_debug('Could not retrieve Mahara versions information file from Mahara.org');
return;
}
$xpath = new DOMXPath($page);
$query = '//div[starts-with(@id,"release-information-")]';
$elements = $xpath->query($query);
$versions = array();
foreach ($elements as $e) {
if (preg_match('/^release-information-(\d+)-(\d+)-(\d+)$/', $e->getAttribute('id'), $match)) {
$versions[] = "$match[1].$match[2].$match[3]";
}
$versions = $data->message->versions;
// Lets record the needed info locally as the cron only fetches the info once a day
$latestmajorversion = max(array_keys((array)$versions));
$latestversion = $latestmajorversion . '.' . $versions->$latestmajorversion->latest;
set_config('latest_version', $latestversion);
if (preg_match('/^(\d+)\.(\d+)\.(\d+).*?$/', get_config('release'), $match)) {
$currentmajorversion = $match[1] . '.' . $match[2];
$latestseriesversion = $currentmajorversion . '.' . $versions->$currentmajorversion->latest;
set_config('latest_branch_version', $latestseriesversion);
}
else {
set_config('latest_branch_version', '');
}
if (!empty($versions)) {
usort($versions, 'strnatcmp');
set_config('latest_version', end($versions));
$supported = array();
foreach ($versions as $k => $v) {
$insupport = filter_var($v->supported, FILTER_VALIDATE_BOOLEAN);
if ($insupport) {
$supported[] = $k;
}
}
set_config('supported_versions', implode(',', $supported));
}
/**
......
......@@ -72,13 +72,30 @@ function site_statistics($full=false) {
if ($latestversion = get_config('latest_version')) {
$data['latest_version'] = $latestversion;
if ($data['release'] == $latestversion) {
$data['strlatestversion'] = get_string('uptodate', 'admin');
$data['uptodate'] = get_string('uptodate', 'admin');
}
else {
$download_page = 'https://launchpad.net/mahara/+download';
$data['strlatestversion'] = get_string('latestversionis', 'admin', $download_page, $latestversion);
}
}
if ($branchlatest = get_config('latest_branch_version')) {
if ($data['release'] != $branchlatest) {
$download_page = 'https://launchpad.net/mahara/+milestone/' . $branchlatest;
$data['strlatestbranchversion'] = get_string('latestbranchversionis', 'admin', $download_page, $branchlatest);
}
}
if ($insupport = get_config('supported_versions')) {
$insupport = explode(',', $insupport);
if (!in_array(get_config('series'), $insupport)) {
if (preg_match('/dev$/', $data['release'])) {
$data['strnotinsupport'] = get_string('versionnotinsupportdev', 'admin');
}
else {
$data['strnotinsupport'] = get_string('versionnotinsupport', 'admin', get_config('series'));
}
}
}
if ($full) {
// Add the other overall graphs here
......
......@@ -380,6 +380,7 @@ function upgrade_core($upgrade) {
set_config('release', $upgrade->torelease);
set_config('series', $upgrade->toseries);
bump_cache_version();
cron_check_for_updates();
if (!empty($upgrade->install)) {
core_postinst();
......
......@@ -43,8 +43,23 @@
{if $showall}
<tr>
<th>{str tag=maharaversion section=admin}</th>
<td>{$institutiondata.release}{if $institutiondata.strlatestversion} ({$institutiondata.strlatestversion|clean_html|safe}){/if}</td>
<td>{$institutiondata.release}</td>
</tr>
{if $institutiondata.strlatestbranchversion || $institutiondata.strnotinsupport || $institutiondata.strlatestversion || $institutiondata.uptodate}
<tr>
<td colspan="2">
{if $institutiondata.uptodate}
{$institutiondata.uptodate}
{else}
<ul>
{if $institutiondata.strlatestbranchversion}<li>{$institutiondata.strlatestbranchversion|clean_html|safe}</li>{/if}
{if $institutiondata.strnotinsupport}<li><span class="text-danger">{$institutiondata.strnotinsupport}</span></li>{/if}
{if $institutiondata.strlatestversion}<li>{$institutiondata.strlatestversion|clean_html|safe}</li>{/if}
</ul>
{/if}
</td>
</tr>
{/if}
<tr>
<th>{str tag=Cron section=admin}</th>
<td>{if $institutiondata.cronrunning}{str tag=runningnormally section=admin}{else}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment