diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-03-22 18:50:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-22 18:50:33 +0100 |
commit | 64c34078e4782d8f41e6c7f2beb7682823e99498 (patch) | |
tree | 3ba7a75ebef8b62a1abd7e819a6c14f34091ccb3 /application | |
parent | 36eb71fb48aa3e752a1e32774b8eead18780bf29 (diff) | |
parent | b786c8836f0576d4feb1543471950c5d24bc7939 (diff) | |
download | Shaarli-64c34078e4782d8f41e6c7f2beb7682823e99498.tar.gz Shaarli-64c34078e4782d8f41e6c7f2beb7682823e99498.tar.zst Shaarli-64c34078e4782d8f41e6c7f2beb7682823e99498.zip |
Merge pull request #816 from ArthurHoaro/project/master-version
Use 'dev' version on the master branch
Diffstat (limited to 'application')
-rw-r--r-- | application/ApplicationUtils.php | 45 | ||||
-rw-r--r-- | application/Updater.php | 44 |
2 files changed, 79 insertions, 10 deletions
diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php index a0f482b0..85dcbeeb 100644 --- a/application/ApplicationUtils.php +++ b/application/ApplicationUtils.php | |||
@@ -4,9 +4,13 @@ | |||
4 | */ | 4 | */ |
5 | class ApplicationUtils | 5 | class ApplicationUtils |
6 | { | 6 | { |
7 | /** | ||
8 | * @var string File containing the current version | ||
9 | */ | ||
10 | public static $VERSION_FILE = 'shaarli_version.php'; | ||
11 | |||
7 | private static $GIT_URL = 'https://raw.githubusercontent.com/shaarli/Shaarli'; | 12 | private static $GIT_URL = 'https://raw.githubusercontent.com/shaarli/Shaarli'; |
8 | private static $GIT_BRANCHES = array('master', 'stable'); | 13 | private static $GIT_BRANCHES = array('latest', 'stable'); |
9 | private static $VERSION_FILE = 'shaarli_version.php'; | ||
10 | private static $VERSION_START_TAG = '<?php /* '; | 14 | private static $VERSION_START_TAG = '<?php /* '; |
11 | private static $VERSION_END_TAG = ' */ ?>'; | 15 | private static $VERSION_END_TAG = ' */ ?>'; |
12 | 16 | ||
@@ -29,6 +33,30 @@ class ApplicationUtils | |||
29 | return false; | 33 | return false; |
30 | } | 34 | } |
31 | 35 | ||
36 | return $data; | ||
37 | } | ||
38 | |||
39 | /** | ||
40 | * Retrieve the version from a remote URL or a file. | ||
41 | * | ||
42 | * @param string $remote URL or file to fetch. | ||
43 | * @param int $timeout For URLs fetching. | ||
44 | * | ||
45 | * @return bool|string The version or false if it couldn't be retrieved. | ||
46 | */ | ||
47 | public static function getVersion($remote, $timeout = 2) | ||
48 | { | ||
49 | if (startsWith($remote, 'http')) { | ||
50 | if (($data = static::getLatestGitVersionCode($remote, $timeout)) === false) { | ||
51 | return false; | ||
52 | } | ||
53 | } else { | ||
54 | if (! is_file($remote)) { | ||
55 | return false; | ||
56 | } | ||
57 | $data = file_get_contents($remote); | ||
58 | } | ||
59 | |||
32 | return str_replace( | 60 | return str_replace( |
33 | array(self::$VERSION_START_TAG, self::$VERSION_END_TAG, PHP_EOL), | 61 | array(self::$VERSION_START_TAG, self::$VERSION_END_TAG, PHP_EOL), |
34 | array('', '', ''), | 62 | array('', '', ''), |
@@ -65,13 +93,10 @@ class ApplicationUtils | |||
65 | $isLoggedIn, | 93 | $isLoggedIn, |
66 | $branch='stable') | 94 | $branch='stable') |
67 | { | 95 | { |
68 | if (! $isLoggedIn) { | 96 | // Do not check versions for visitors |
69 | // Do not check versions for visitors | 97 | // Do not check if the user doesn't want to |
70 | return false; | 98 | // Do not check with dev version |
71 | } | 99 | if (! $isLoggedIn || empty($enableCheck) || $currentVersion === 'dev') { |
72 | |||
73 | if (empty($enableCheck)) { | ||
74 | // Do not check if the user doesn't want to | ||
75 | return false; | 100 | return false; |
76 | } | 101 | } |
77 | 102 | ||
@@ -93,7 +118,7 @@ class ApplicationUtils | |||
93 | 118 | ||
94 | // Late Static Binding allows overriding within tests | 119 | // Late Static Binding allows overriding within tests |
95 | // See http://php.net/manual/en/language.oop5.late-static-bindings.php | 120 | // See http://php.net/manual/en/language.oop5.late-static-bindings.php |
96 | $latestVersion = static::getLatestGitVersionCode( | 121 | $latestVersion = static::getVersion( |
97 | self::$GIT_URL . '/' . $branch . '/' . self::$VERSION_FILE | 122 | self::$GIT_URL . '/' . $branch . '/' . self::$VERSION_FILE |
98 | ); | 123 | ); |
99 | 124 | ||
diff --git a/application/Updater.php b/application/Updater.php index efbfc832..0fb68c5a 100644 --- a/application/Updater.php +++ b/application/Updater.php | |||
@@ -396,6 +396,50 @@ class Updater | |||
396 | 396 | ||
397 | return true; | 397 | return true; |
398 | } | 398 | } |
399 | |||
400 | /** | ||
401 | * Update updates.check_updates_branch setting. | ||
402 | * | ||
403 | * If the current major version digit matches the latest branch | ||
404 | * major version digit, we set the branch to `latest`, | ||
405 | * otherwise we'll check updates on the `stable` branch. | ||
406 | * | ||
407 | * No update required for the dev version. | ||
408 | * | ||
409 | * Note: due to hardcoded URL and lack of dependency injection, this is not unit testable. | ||
410 | * | ||
411 | * FIXME! This needs to be removed when we switch to first digit major version | ||
412 | * instead of the second one since the versionning process will change. | ||
413 | */ | ||
414 | public function updateMethodCheckUpdateRemoteBranch() | ||
415 | { | ||
416 | if (shaarli_version === 'dev' || $this->conf->get('updates.check_updates_branch') === 'latest') { | ||
417 | return true; | ||
418 | } | ||
419 | |||
420 | // Get latest branch major version digit | ||
421 | $latestVersion = ApplicationUtils::getLatestGitVersionCode( | ||
422 | 'https://raw.githubusercontent.com/shaarli/Shaarli/latest/shaarli_version.php', | ||
423 | 5 | ||
424 | ); | ||
425 | if (preg_match('/(\d+)\.\d+$/', $latestVersion, $matches) === false) { | ||
426 | return false; | ||
427 | } | ||
428 | $latestMajor = $matches[1]; | ||
429 | |||
430 | // Get current major version digit | ||
431 | preg_match('/(\d+)\.\d+$/', shaarli_version, $matches); | ||
432 | $currentMajor = $matches[1]; | ||
433 | |||
434 | if ($currentMajor === $latestMajor) { | ||
435 | $branch = 'latest'; | ||
436 | } else { | ||
437 | $branch = 'stable'; | ||
438 | } | ||
439 | $this->conf->set('updates.check_updates_branch', $branch); | ||
440 | $this->conf->write($this->isLoggedIn); | ||
441 | return true; | ||
442 | } | ||
399 | } | 443 | } |
400 | 444 | ||
401 | /** | 445 | /** |