Permalink
Browse files

Merge pull request #946 from makss/patch-6

Check prerelease updates.
  • Loading branch information...
philwareham committed Oct 9, 2017
2 parents aadf112 + 45be4f0 commit cf2d78b6000c7fb2bb588cc373a9c935e8d1ce86
Showing with 28 additions and 14 deletions.
  1. +28 −14 textpattern/include/txp_diag.php
@@ -201,17 +201,16 @@ function doDiagnostics()
$lastCheck = json_decode(get_pref('last_update_check', ''), true);
if ($now > (@(int)$lastCheck['when'] + (60 * 60 * 24))) {
$updates = checkUpdates();
$lastCheck = array(
'when' => $now,
'msg' => (empty($updates) ? '' : gTxt($updates['msg'], array('{version}' => $updates['version']))),
);
set_pref('last_update_check', json_encode($lastCheck, TEXTPATTERN_JSON), 'publish', PREF_HIDDEN, 'text_input');
$lastCheck = checkUpdates();
}
if (!empty($lastCheck['msg'])) {
$fail['textpattern_version_update'] = diag_msg_wrap($lastCheck['msg'], 'information');
}
if (!empty($lastCheck['msg2'])) {
$fail['textpattern_version_update_beta'] = diag_msg_wrap($lastCheck['msg2'], 'information');
}
}
if (!is_callable('version_compare') || version_compare(PHP_VERSION, REQUIRED_PHP_VERSION, '<')) {
@@ -550,9 +549,8 @@ function doDiagnostics()
if ($step == 'high') {
$lastCheck = json_decode(get_pref('last_update_check', ''), true);
if (!empty($lastCheck['msg'])) {
$out[] = 'Last update check: '.strftime('%Y-%m-%d %H:%M:%S', $lastCheck['when']).', '.strip_tags($lastCheck['msg']).n;
if (!empty($lastCheck['msg']) || !empty($lastCheck['msg2'])) {
$out[] = 'Last update check: '.strftime('%Y-%m-%d %H:%M:%S', $lastCheck['when']).', '.strip_tags($lastCheck['msg']).' '.strip_tags($lastCheck['msg2']).n;
}
$out[] = n.'Charset (default/config)'.cs.$DB->default_charset.'/'.$DB->charset.n;
@@ -662,12 +660,28 @@ function checkUpdates()
{
$response = @json_decode(file_get_contents('https://textpattern.io/version.json'), true);
$release = @$response['textpattern-version']['release'];
$prerelease = @$response['textpattern-version']['prerelease'];
$version = get_pref('version');
if (empty($release)) {
return array('version' => 0, 'msg' => 'problem_connecting_rpc_server');
} elseif (version_compare($version, $release) < 0) {
return array('version' => $release, 'msg' => 'textpattern_update_available');
$lastCheck = array(
'when' => time(),
'msg' => '',
'msg2' => '',
);
if (!empty($release)) {
if (version_compare($version, $release) < 0) {
$lastCheck['msg'] = gTxt('textpattern_update_available', array('{version}' => $release));
}
if (version_compare($version, $prerelease) < 0) {
$lastCheck['msg2'] = gTxt('textpattern_update_available_beta', array('{version}' => $prerelease));
}
} else {
$lastCheck['msg'] = gTxt('problem_connecting_rpc_server');
}
return array();
set_pref('last_update_check', json_encode($lastCheck, TEXTPATTERN_JSON), 'publish', PREF_HIDDEN, 'text_input');
return $lastCheck;
}

0 comments on commit cf2d78b

Please sign in to comment.