Commit ff98e459 authored by Evan Goldenberg's avatar Evan Goldenberg
Browse files

scrape latest version off the launchpad project page



A cron job is added to check daily for an update. Version state (up to
date or upgrade available) is displayed with the site stats.
Signed-off-by: default avatarEvan Goldenberg <evang@catalyst.net.nz>
parent 4d1d07fb
......@@ -174,6 +174,8 @@ $string['groupcountsbyjointype'] = 'Number of groups by Access Type';
$string['blockcountsbytype'] = 'Most frequently used blocks in Portfolio Views:';
$string['Rank'] = 'Rank';
$string['rankingsupdated'] = 'Rankings last updated: %s';
$string['uptodate'] = 'up to date';
$string['latestversionis'] = 'latest version is <a href="%s">%s</a>';
// Site options
$string['adminsonly'] = 'Administrators only';
......
......@@ -1391,6 +1391,18 @@ function xmldb_core_upgrade($oldversion=0) {
create_table($table);
}
if ($oldversion < 2010031700) {
// Insert a cron job to check for new versions of Mahara
$cron = new StdClass;
$cron->callfunction = 'cron_check_for_updates';
$cron->minute = rand(0, 59);
$cron->hour = rand(0, 23);
$cron->day = '*';
$cron->month = '*';
$cron->dayofweek = '*';
insert_record('cron', $cron);
}
return $status;
}
......
......@@ -2264,6 +2264,26 @@ function recalculate_quota() {
}
}
/**
* Cronjob to check Launchpad for the latest Mahara version
*/
function cron_check_for_updates() {
$request = array(
CURLOPT_URL => 'https://launchpad.net/mahara',
);
$result = mahara_http_request($request);
$page = new DOMDocument();
$page->loadHTML($result->data);
$xpath = new DOMXPath($page);
$query = '//div[@class="version"]';
$elements = $xpath->query($query);
preg_match('/[0-9]+.[0-9]+.[a-zA-Z0-9]+/', $elements->item(0)->nodeValue, $match);
set_config('latest_version', $match[0]);
}
/**
* Cronjob to send an update of site statistics to mahara.org
*/
......
......@@ -251,11 +251,19 @@ function site_statistics($full=false) {
$data['name'] = get_config('sitename');
$data['release'] = get_config('release');
$data['version'] = get_config('version');
$data['latest_version'] = get_config('latest_version');
$data['installdate'] = format_date(strtotime(get_config('installation_time')), 'strftimedate');
$data['dbsize'] = db_total_size();
$data['diskusage'] = get_field('site_data', 'value', 'type', 'disk-usage');
$data['cronrunning'] = !record_exists_select('cron', 'nextrun < CURRENT_DATE');
if ($data['release'] == $data['latest_version']) {
$data['strlatestversion'] = get_string('uptodate', 'admin');
}
else {
$download_page = 'https://launchpad.net/mahara/+download';
$data['strlatestversion'] = get_string('latestversionis', 'admin', $download_page, $data['latest_version']);
}
$data['strrankingsupdated'] = get_string('rankingsupdated', 'admin', date('Y-m-d H:i', get_config('registration_lastsent')));
......
......@@ -28,7 +28,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2010020500;
$config->version = 2010031700;
$config->release = '1.3.0dev';
$config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';
......
......@@ -29,7 +29,7 @@ addLoadEvent(function () {literal}{{/literal}
{if $sitedata.diskusage}
<p><strong>{str tag=diskusage section=admin}:</strong> {$sitedata.diskusage|display_size}</p>
{/if}
<p><strong>{str tag=maharaversion section=admin}:</strong> {$sitedata.release}</p>
<p><strong>{str tag=maharaversion section=admin}:</strong> {$sitedata.release} ({$sitedata.strlatestversion})</p>
<p><strong>{str tag=Cron section=admin}:</strong> {if $sitedata.cronrunning}{str tag=runningnormally section=admin}{else}{str tag=cronnotrunning section=admin}{/if}</p>
</div>
<div class="cb"></div>
......
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