diff options
author | VirtualTam <virtualtam@flibidi.net> | 2015-11-30 02:03:32 +0100 |
---|---|---|
committer | VirtualTam <virtualtam@flibidi.net> | 2015-11-30 02:03:32 +0100 |
commit | 05f21ea82130dca0bf49a16630105d1c5649e6c6 (patch) | |
tree | 0604f1af0688325fc8871161a650a7a4ee22fe34 | |
parent | 1b740e3de39172975d0e755d9a089d2e9a44279d (diff) | |
parent | 4407b45fd3b09257ea79edba8d4f50db350f8fa9 (diff) | |
download | Shaarli-05f21ea82130dca0bf49a16630105d1c5649e6c6.tar.gz Shaarli-05f21ea82130dca0bf49a16630105d1c5649e6c6.tar.zst Shaarli-05f21ea82130dca0bf49a16630105d1c5649e6c6.zip |
Merge pull request #394 from virtualtam/app-utils/check-update/stable-branch
application: default to the "stable" branch for update checks
-rw-r--r-- | application/ApplicationUtils.php | 18 | ||||
-rw-r--r-- | index.php | 32 | ||||
-rw-r--r-- | tests/ApplicationUtilsTest.php | 14 | ||||
-rw-r--r-- | tpl/page.footer.html | 12 |
4 files changed, 55 insertions, 21 deletions
diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php index c7414b77..6d878110 100644 --- a/application/ApplicationUtils.php +++ b/application/ApplicationUtils.php | |||
@@ -5,7 +5,7 @@ | |||
5 | class ApplicationUtils | 5 | class ApplicationUtils |
6 | { | 6 | { |
7 | private static $GIT_URL = 'https://raw.githubusercontent.com/shaarli/Shaarli'; | 7 | private static $GIT_URL = 'https://raw.githubusercontent.com/shaarli/Shaarli'; |
8 | private static $GIT_BRANCH = 'master'; | 8 | private static $GIT_BRANCHES = array('master', 'stable'); |
9 | private static $VERSION_FILE = 'shaarli_version.php'; | 9 | private static $VERSION_FILE = 'shaarli_version.php'; |
10 | private static $VERSION_START_TAG = '<?php /* '; | 10 | private static $VERSION_START_TAG = '<?php /* '; |
11 | private static $VERSION_END_TAG = ' */ ?>'; | 11 | private static $VERSION_END_TAG = ' */ ?>'; |
@@ -52,8 +52,12 @@ class ApplicationUtils | |||
52 | * | 52 | * |
53 | * @return mixed the new version code if available and greater, else 'false' | 53 | * @return mixed the new version code if available and greater, else 'false' |
54 | */ | 54 | */ |
55 | public static function checkUpdate( | 55 | public static function checkUpdate($currentVersion, |
56 | $currentVersion, $updateFile, $checkInterval, $enableCheck, $isLoggedIn) | 56 | $updateFile, |
57 | $checkInterval, | ||
58 | $enableCheck, | ||
59 | $isLoggedIn, | ||
60 | $branch='stable') | ||
57 | { | 61 | { |
58 | if (! $isLoggedIn) { | 62 | if (! $isLoggedIn) { |
59 | // Do not check versions for visitors | 63 | // Do not check versions for visitors |
@@ -75,10 +79,16 @@ class ApplicationUtils | |||
75 | return false; | 79 | return false; |
76 | } | 80 | } |
77 | 81 | ||
82 | if (! in_array($branch, self::$GIT_BRANCHES)) { | ||
83 | throw new Exception( | ||
84 | 'Invalid branch selected for updates: "' . $branch . '"' | ||
85 | ); | ||
86 | } | ||
87 | |||
78 | // Late Static Binding allows overriding within tests | 88 | // Late Static Binding allows overriding within tests |
79 | // See http://php.net/manual/en/language.oop5.late-static-bindings.php | 89 | // See http://php.net/manual/en/language.oop5.late-static-bindings.php |
80 | $latestVersion = static::getLatestGitVersionCode( | 90 | $latestVersion = static::getLatestGitVersionCode( |
81 | self::$GIT_URL . '/' . self::$GIT_BRANCH . '/' . self::$VERSION_FILE | 91 | self::$GIT_URL . '/' . $branch . '/' . self::$VERSION_FILE |
82 | ); | 92 | ); |
83 | 93 | ||
84 | if (! $latestVersion) { | 94 | if (! $latestVersion) { |
@@ -92,7 +92,8 @@ $GLOBALS['config']['ENABLE_THUMBNAILS'] = true; | |||
92 | $GLOBALS['config']['ENABLE_LOCALCACHE'] = true; | 92 | $GLOBALS['config']['ENABLE_LOCALCACHE'] = true; |
93 | 93 | ||
94 | // Update check frequency for Shaarli. 86400 seconds=24 hours | 94 | // Update check frequency for Shaarli. 86400 seconds=24 hours |
95 | $GLOBALS['config']['UPDATECHECK_INTERVAL'] = 86400 ; | 95 | $GLOBALS['config']['UPDATECHECK_BRANCH'] = 'stable'; |
96 | $GLOBALS['config']['UPDATECHECK_INTERVAL'] = 86400; | ||
96 | 97 | ||
97 | 98 | ||
98 | /* | 99 | /* |
@@ -631,18 +632,23 @@ class pageBuilder | |||
631 | private function initialize() | 632 | private function initialize() |
632 | { | 633 | { |
633 | $this->tpl = new RainTPL; | 634 | $this->tpl = new RainTPL; |
634 | $this->tpl->assign( | 635 | |
635 | 'newversion', | 636 | try { |
636 | escape( | 637 | $version = ApplicationUtils::checkUpdate( |
637 | ApplicationUtils::checkUpdate( | 638 | shaarli_version, |
638 | shaarli_version, | 639 | $GLOBALS['config']['UPDATECHECK_FILENAME'], |
639 | $GLOBALS['config']['UPDATECHECK_FILENAME'], | 640 | $GLOBALS['config']['UPDATECHECK_INTERVAL'], |
640 | $GLOBALS['config']['UPDATECHECK_INTERVAL'], | 641 | $GLOBALS['config']['ENABLE_UPDATECHECK'], |
641 | $GLOBALS['config']['ENABLE_UPDATECHECK'], | 642 | isLoggedIn(), |
642 | isLoggedIn() | 643 | $GLOBALS['config']['UPDATECHECK_BRANCH'] |
643 | ) | 644 | ); |
644 | ) | 645 | $this->tpl->assign('newVersion', escape($version)); |
645 | ); | 646 | |
647 | } catch (Exception $exc) { | ||
648 | logm($exc->getMessage()); | ||
649 | $this->tpl->assign('versionError', escape($exc->getMessage())); | ||
650 | } | ||
651 | |||
646 | $this->tpl->assign('feedurl', escape(index_url($_SERVER))); | 652 | $this->tpl->assign('feedurl', escape(index_url($_SERVER))); |
647 | $searchcrits = ''; // Search criteria | 653 | $searchcrits = ''; // Search criteria |
648 | if (!empty($_GET['searchtags'])) { | 654 | if (!empty($_GET['searchtags'])) { |
diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php index 437c21fd..6064357d 100644 --- a/tests/ApplicationUtilsTest.php +++ b/tests/ApplicationUtilsTest.php | |||
@@ -75,7 +75,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase | |||
75 | public function testGetLatestGitVersionCodeInvalidUrl() | 75 | public function testGetLatestGitVersionCodeInvalidUrl() |
76 | { | 76 | { |
77 | $this->assertFalse( | 77 | $this->assertFalse( |
78 | ApplicationUtils::getLatestGitVersionCode('htttp://null.io', 0) | 78 | ApplicationUtils::getLatestGitVersionCode('htttp://null.io', 1) |
79 | ); | 79 | ); |
80 | } | 80 | } |
81 | 81 | ||
@@ -102,7 +102,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase | |||
102 | /** | 102 | /** |
103 | * A newer version is available | 103 | * A newer version is available |
104 | */ | 104 | */ |
105 | public function testCheckUpdateNewVersionNew() | 105 | public function testCheckUpdateNewVersionAvailable() |
106 | { | 106 | { |
107 | $newVersion = '1.8.3'; | 107 | $newVersion = '1.8.3'; |
108 | FakeApplicationUtils::$VERSION_CODE = $newVersion; | 108 | FakeApplicationUtils::$VERSION_CODE = $newVersion; |
@@ -135,6 +135,16 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase | |||
135 | } | 135 | } |
136 | 136 | ||
137 | /** | 137 | /** |
138 | * Test update checks - invalid Git branch | ||
139 | * @expectedException Exception | ||
140 | * @expectedExceptionMessageRegExp /Invalid branch selected for updates/ | ||
141 | */ | ||
142 | public function testCheckUpdateInvalidGitBranch() | ||
143 | { | ||
144 | ApplicationUtils::checkUpdate('', 'null', 0, true, true, 'unstable'); | ||
145 | } | ||
146 | |||
147 | /** | ||
138 | * Shaarli is up-to-date | 148 | * Shaarli is up-to-date |
139 | */ | 149 | */ |
140 | public function testCheckUpdateNewVersionUpToDate() | 150 | public function testCheckUpdateNewVersionUpToDate() |
diff --git a/tpl/page.footer.html b/tpl/page.footer.html index 6c29850f..b20aae54 100644 --- a/tpl/page.footer.html +++ b/tpl/page.footer.html | |||
@@ -4,8 +4,16 @@ | |||
4 | {$value} | 4 | {$value} |
5 | {/loop} | 5 | {/loop} |
6 | </div> | 6 | </div> |
7 | {if="$newversion"} | 7 | {if="$newVersion"} |
8 | <div id="newversion"><span id="version_id">●</span> Shaarli {$newversion} is <a href="https://github.com/shaarli/Shaarli/releases">available</a>.</div> | 8 | <div id="newversion"> |
9 | <span id="version_id">●</span> Shaarli {$newVersion} is | ||
10 | <a href="https://github.com/shaarli/Shaarli/releases">available</a>. | ||
11 | </div> | ||
12 | {/if} | ||
13 | {if="$versionError"} | ||
14 | <div id="newversion"> | ||
15 | Error: {$versionError} | ||
16 | </div> | ||
9 | {/if} | 17 | {/if} |
10 | {if="isLoggedIn()"} | 18 | {if="isLoggedIn()"} |
11 | <script>function confirmDeleteLink() { var agree=confirm("Are you sure you want to delete this link ?"); if (agree) return true ; else return false ; }</script> | 19 | <script>function confirmDeleteLink() { var agree=confirm("Are you sure you want to delete this link ?"); if (agree) return true ; else return false ; }</script> |