improve update notice: timeout, config
The updater in the dashboard needed a timeout to not kill the backend if github is not reachable Also, this makes the check configurable
This commit is contained in:
parent
2ae6bcc5dd
commit
631bc150ac
@ -23,6 +23,12 @@ switch($serendipity['POST']['adminAction']) {
|
||||
$data['error_publish'] = $success;
|
||||
}
|
||||
break;
|
||||
case 'updateCheckDisable':
|
||||
if ( !serendipity_checkFormToken() || !serendipity_checkPermission('blogConfiguration') ) {
|
||||
break;
|
||||
}
|
||||
serendipity_set_config_var('updateCheck', false);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@ -40,6 +46,7 @@ $data['backend_frontpage_display'] = $output['more'];
|
||||
|
||||
$data['curVersion'] = serendipity_getCurrentVersion();
|
||||
$data['usedVersion'] = $serendipity['version'];
|
||||
$data['updateCheck'] = $serendipity['updateCheck'];
|
||||
$data['update'] = version_compare($data['usedVersion'], $data['curVersion'], '<');
|
||||
|
||||
|
||||
|
@ -1196,21 +1196,44 @@ function serendipity_verifyFTPChecksums() {
|
||||
return $badsums;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check https://raw.github.com/s9y/Serendipity/master/docs/RELEASE for the newest available version
|
||||
*
|
||||
* If the file is not fetch- or parseable (behind a proxy, malformed by Garvin), this will return -1
|
||||
* */
|
||||
function serendipity_getCurrentVersion() {
|
||||
$updateURL = 'https://raw.github.com/s9y/Serendipity/master/docs/RELEASE';
|
||||
|
||||
$file = fopen($updateURL, 'r');
|
||||
if (!$file) {
|
||||
return;
|
||||
global $serendipity;
|
||||
if ($serendipity['updateCheck'] != "stable" && $serendipity['updateCheck'] != "beta") {
|
||||
return -1;
|
||||
}
|
||||
$updateURL = 'https://raw.github.com/s9y/Serendipity/master/docs/RELEASE';
|
||||
$context = stream_context_create( array('http'=>array('timeout' => 5.0)) );
|
||||
|
||||
while (!feof($file)) {
|
||||
$line = fgets($file);
|
||||
$file = @file_get_contents($updateURL, false, $context);
|
||||
|
||||
if (preg_match('/stable:(.+$)/', $line, $match)) {
|
||||
return $match[1];
|
||||
if ( ! $file) {
|
||||
if (function_exists('curl_init')) {
|
||||
$ch = curl_init($updateURL);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, "5");
|
||||
$file = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
}
|
||||
}
|
||||
|
||||
if ($file) {
|
||||
if ($serendipity['updateCheck'] == "stable") {
|
||||
if (preg_match('/^stable:(.+)\b/', $file, $match)) {
|
||||
return $match[1];
|
||||
}
|
||||
} else {
|
||||
if (preg_match('/^beta:(.+)\b/', $file, $match)) {
|
||||
return $match[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* vim: set sts=4 ts=4 sw=4 expandtab : */
|
||||
|
@ -398,6 +398,12 @@
|
||||
'type' => 'bool',
|
||||
'default' => false,
|
||||
'permission' => 'blogConfiguration'),
|
||||
array('var' => 'updateCheck',
|
||||
'title' => UPDATE_NOTIFICATION,
|
||||
'description' => "Show the update notification in the Dashboard, and for which channel?", # i18n
|
||||
'type' => 'list',
|
||||
'default' => array('stable' => 'stable', 'beta' => 'beta', 'false' => NO ), # i18n
|
||||
'permission' => 'blogConfiguration'),
|
||||
));
|
||||
|
||||
$res['display'] =
|
||||
|
@ -11,12 +11,25 @@
|
||||
<span class="msg_error"><span class="icon-attention-circled"></span> {$CONST.PUBLISH_ERROR}: {$error_publish}</span>
|
||||
{/if}
|
||||
|
||||
{if $update}
|
||||
<section id="dashboard_update">
|
||||
<h3>{$CONST.UPDATE_NOTIFICATION}</h3>
|
||||
{if $updateCheck == "stable" || $updateCheck == "beta" }
|
||||
{if $curVersion == -1}
|
||||
<section id="dashboard_update">
|
||||
<h3>{$CONST.UPDATE_NOTIFICATION}</h3>
|
||||
|
||||
<span class="msg_notice"><span class="icon-info-circled"></span> {$CONST.NEW_VERSION_AVAILABLE} {$curVersion}</span>
|
||||
</section>
|
||||
<span class="msg_notice"><span class="icon-info-circled"></span> Check for new Serendipity version failed</span> {* i18n *}
|
||||
<form id="updateCheckDisable" method="POST">
|
||||
<input type="hidden" name="serendipity[adminAction]" value="updateCheckDisable" />
|
||||
{$token}
|
||||
<button type="submit">Disable update check</button> {* i18n *}
|
||||
</form>
|
||||
</section>
|
||||
{else if $update}
|
||||
<section id="dashboard_update">
|
||||
<h3>{$CONST.UPDATE_NOTIFICATION}</h3>
|
||||
|
||||
<span class="msg_notice"><span class="icon-info-circled"></span> {$CONST.NEW_VERSION_AVAILABLE} {$curVersion}</span>
|
||||
</section>
|
||||
{/if}
|
||||
{/if}
|
||||
<section id="dashboard_comments" class="odd equal_heights quick_list">
|
||||
<h3>{if 'adminComments'|checkPermission}<a href="serendipity_admin.php?serendipity[adminModule]=comments">{/if}{$CONST.COMMENTS}{if 'adminComments'|checkPermission}</a>{/if}</h3>
|
||||
|
Loading…
x
Reference in New Issue
Block a user