Merge pull request #394 from virtualtam/app-utils/check-update/stable-branch
application: default to the "stable" branch for update checks
This commit is contained in:
commit
05f21ea821
4 changed files with 55 additions and 21 deletions
|
@ -5,7 +5,7 @@
|
||||||
class ApplicationUtils
|
class ApplicationUtils
|
||||||
{
|
{
|
||||||
private static $GIT_URL = 'https://raw.githubusercontent.com/shaarli/Shaarli';
|
private static $GIT_URL = 'https://raw.githubusercontent.com/shaarli/Shaarli';
|
||||||
private static $GIT_BRANCH = 'master';
|
private static $GIT_BRANCHES = array('master', 'stable');
|
||||||
private static $VERSION_FILE = 'shaarli_version.php';
|
private static $VERSION_FILE = 'shaarli_version.php';
|
||||||
private static $VERSION_START_TAG = '<?php /* ';
|
private static $VERSION_START_TAG = '<?php /* ';
|
||||||
private static $VERSION_END_TAG = ' */ ?>';
|
private static $VERSION_END_TAG = ' */ ?>';
|
||||||
|
@ -52,8 +52,12 @@ public static function getLatestGitVersionCode($url, $timeout=2)
|
||||||
*
|
*
|
||||||
* @return mixed the new version code if available and greater, else 'false'
|
* @return mixed the new version code if available and greater, else 'false'
|
||||||
*/
|
*/
|
||||||
public static function checkUpdate(
|
public static function checkUpdate($currentVersion,
|
||||||
$currentVersion, $updateFile, $checkInterval, $enableCheck, $isLoggedIn)
|
$updateFile,
|
||||||
|
$checkInterval,
|
||||||
|
$enableCheck,
|
||||||
|
$isLoggedIn,
|
||||||
|
$branch='stable')
|
||||||
{
|
{
|
||||||
if (! $isLoggedIn) {
|
if (! $isLoggedIn) {
|
||||||
// Do not check versions for visitors
|
// Do not check versions for visitors
|
||||||
|
@ -75,10 +79,16 @@ public static function checkUpdate(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! in_array($branch, self::$GIT_BRANCHES)) {
|
||||||
|
throw new Exception(
|
||||||
|
'Invalid branch selected for updates: "' . $branch . '"'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Late Static Binding allows overriding within tests
|
// Late Static Binding allows overriding within tests
|
||||||
// See http://php.net/manual/en/language.oop5.late-static-bindings.php
|
// See http://php.net/manual/en/language.oop5.late-static-bindings.php
|
||||||
$latestVersion = static::getLatestGitVersionCode(
|
$latestVersion = static::getLatestGitVersionCode(
|
||||||
self::$GIT_URL . '/' . self::$GIT_BRANCH . '/' . self::$VERSION_FILE
|
self::$GIT_URL . '/' . $branch . '/' . self::$VERSION_FILE
|
||||||
);
|
);
|
||||||
|
|
||||||
if (! $latestVersion) {
|
if (! $latestVersion) {
|
||||||
|
|
20
index.php
20
index.php
|
@ -92,6 +92,7 @@
|
||||||
$GLOBALS['config']['ENABLE_LOCALCACHE'] = true;
|
$GLOBALS['config']['ENABLE_LOCALCACHE'] = true;
|
||||||
|
|
||||||
// Update check frequency for Shaarli. 86400 seconds=24 hours
|
// Update check frequency for Shaarli. 86400 seconds=24 hours
|
||||||
|
$GLOBALS['config']['UPDATECHECK_BRANCH'] = 'stable';
|
||||||
$GLOBALS['config']['UPDATECHECK_INTERVAL'] = 86400;
|
$GLOBALS['config']['UPDATECHECK_INTERVAL'] = 86400;
|
||||||
|
|
||||||
|
|
||||||
|
@ -631,18 +632,23 @@ function __construct()
|
||||||
private function initialize()
|
private function initialize()
|
||||||
{
|
{
|
||||||
$this->tpl = new RainTPL;
|
$this->tpl = new RainTPL;
|
||||||
$this->tpl->assign(
|
|
||||||
'newversion',
|
try {
|
||||||
escape(
|
$version = ApplicationUtils::checkUpdate(
|
||||||
ApplicationUtils::checkUpdate(
|
|
||||||
shaarli_version,
|
shaarli_version,
|
||||||
$GLOBALS['config']['UPDATECHECK_FILENAME'],
|
$GLOBALS['config']['UPDATECHECK_FILENAME'],
|
||||||
$GLOBALS['config']['UPDATECHECK_INTERVAL'],
|
$GLOBALS['config']['UPDATECHECK_INTERVAL'],
|
||||||
$GLOBALS['config']['ENABLE_UPDATECHECK'],
|
$GLOBALS['config']['ENABLE_UPDATECHECK'],
|
||||||
isLoggedIn()
|
isLoggedIn(),
|
||||||
)
|
$GLOBALS['config']['UPDATECHECK_BRANCH']
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
$this->tpl->assign('newVersion', escape($version));
|
||||||
|
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
logm($exc->getMessage());
|
||||||
|
$this->tpl->assign('versionError', escape($exc->getMessage()));
|
||||||
|
}
|
||||||
|
|
||||||
$this->tpl->assign('feedurl', escape(index_url($_SERVER)));
|
$this->tpl->assign('feedurl', escape(index_url($_SERVER)));
|
||||||
$searchcrits = ''; // Search criteria
|
$searchcrits = ''; // Search criteria
|
||||||
if (!empty($_GET['searchtags'])) {
|
if (!empty($_GET['searchtags'])) {
|
||||||
|
|
|
@ -75,7 +75,7 @@ public function testGetLatestGitVersionCode()
|
||||||
public function testGetLatestGitVersionCodeInvalidUrl()
|
public function testGetLatestGitVersionCodeInvalidUrl()
|
||||||
{
|
{
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
ApplicationUtils::getLatestGitVersionCode('htttp://null.io', 0)
|
ApplicationUtils::getLatestGitVersionCode('htttp://null.io', 1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ public function testCheckUpdateUserDisabled()
|
||||||
/**
|
/**
|
||||||
* A newer version is available
|
* A newer version is available
|
||||||
*/
|
*/
|
||||||
public function testCheckUpdateNewVersionNew()
|
public function testCheckUpdateNewVersionAvailable()
|
||||||
{
|
{
|
||||||
$newVersion = '1.8.3';
|
$newVersion = '1.8.3';
|
||||||
FakeApplicationUtils::$VERSION_CODE = $newVersion;
|
FakeApplicationUtils::$VERSION_CODE = $newVersion;
|
||||||
|
@ -134,6 +134,16 @@ public function testCheckUpdateNewVersionUnavailable()
|
||||||
$this->assertFalse($version);
|
$this->assertFalse($version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test update checks - invalid Git branch
|
||||||
|
* @expectedException Exception
|
||||||
|
* @expectedExceptionMessageRegExp /Invalid branch selected for updates/
|
||||||
|
*/
|
||||||
|
public function testCheckUpdateInvalidGitBranch()
|
||||||
|
{
|
||||||
|
ApplicationUtils::checkUpdate('', 'null', 0, true, true, 'unstable');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shaarli is up-to-date
|
* Shaarli is up-to-date
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -4,8 +4,16 @@
|
||||||
{$value}
|
{$value}
|
||||||
{/loop}
|
{/loop}
|
||||||
</div>
|
</div>
|
||||||
{if="$newversion"}
|
{if="$newVersion"}
|
||||||
<div id="newversion"><span id="version_id">●</span> Shaarli {$newversion} is <a href="https://github.com/shaarli/Shaarli/releases">available</a>.</div>
|
<div id="newversion">
|
||||||
|
<span id="version_id">●</span> Shaarli {$newVersion} is
|
||||||
|
<a href="https://github.com/shaarli/Shaarli/releases">available</a>.
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{if="$versionError"}
|
||||||
|
<div id="newversion">
|
||||||
|
Error: {$versionError}
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{if="isLoggedIn()"}
|
{if="isLoggedIn()"}
|
||||||
<script>function confirmDeleteLink() { var agree=confirm("Are you sure you want to delete this link ?"); if (agree) return true ; else return false ; }</script>
|
<script>function confirmDeleteLink() { var agree=confirm("Are you sure you want to delete this link ?"); if (agree) return true ; else return false ; }</script>
|
||||||
|
|
Loading…
Reference in a new issue