-
-
Notifications
You must be signed in to change notification settings - Fork 367
Expand file tree
/
Copy pathCheckUpdate.php
More file actions
89 lines (79 loc) · 2.14 KB
/
CheckUpdate.php
File metadata and controls
89 lines (79 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/
namespace App\Actions\InstallUpdate;
use App\Actions\Diagnostics\Pipes\Checks\MigrationCheck;
use App\Actions\Diagnostics\Pipes\Checks\UpdatableCheck;
use App\Enum\UpdateStatus;
use App\Metadata\Versions\FileVersion;
use App\Metadata\Versions\GitHubVersion;
use App\Metadata\Versions\InstalledVersion;
class CheckUpdate
{
public function __construct(
private GitHubVersion $github_functions,
private InstalledVersion $installed_version,
private FileVersion $file_version,
) {
$this->github_functions->hydrate();
$this->file_version->hydrate();
$this->installed_version = $installed_version;
}
/**
* Check for updates and returns the update state.
*
* The return codes have the following semantics:
* - `0` - Not on master branch
* - `1` - Up-to-date
* - `2` - Not up-to-date.
* - `3` - Require migration.
*
* @return UpdateStatus the update state between 0..3
*/
public function getCode(): UpdateStatus
{
if ($this->installed_version->isRelease()) {
// @codeCoverageIgnoreStart
return match (false) {
MigrationCheck::isUpToDate() => UpdateStatus::REQUIRE_MIGRATION,
$this->file_version->isUpToDate() => UpdateStatus::NOT_UP_TO_DATE,
default => UpdateStatus::UP_TO_DATE,
};
// @codeCoverageIgnoreEnd
}
try {
UpdatableCheck::assertUpdatability();
// @codeCoverageIgnoreStart
if (!$this->github_functions->isUpToDate()) {
return UpdateStatus::NOT_UP_TO_DATE;
}
return UpdateStatus::UP_TO_DATE;
// @codeCoverageIgnoreEnd
// @codeCoverageIgnoreStart
} catch (\Exception $e) {
return UpdateStatus::NOT_MASTER;
}
// @codeCoverageIgnoreEnd
}
/**
* Return the latest known release version from the remote update feed.
*
* @codeCoverageIgnore
*/
public function getLatestVersion(): ?string
{
return $this->file_version->remote_version?->toString();
}
/**
* Return the current installed file version.
*
* @codeCoverageIgnore
*/
public function getCurrentVersion(): string
{
return $this->file_version->getVersion()->toString();
}
}