UpdateManager.php
2.93 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
namespace Dcat\Admin\Extend;
use Dcat\Admin\Exception\AdminException;
use Illuminate\Support\Facades\Artisan;
/**
* Class UpdateManager.
*
* @see https://github.com/octobercms/october/blob/develop/modules/system/classes/UpdateManager.php
*/
class UpdateManager
{
use Note;
/**
* @var Manager
*/
protected $manager;
/**
* @var VersionManager
*/
protected $versionManager;
public function __construct(Manager $manager)
{
$this->manager = $manager;
$this->versionManager = $manager->versionManager();
}
public function install($extension)
{
return $this->update($extension);
}
public function uninstall($extension)
{
return $this->rollback($extension);
}
public function rollback($name, ?string $stopOnVersion = null)
{
if (
! ($extension = $this->manager->get($name))
&& $this->versionManager->purge($name)
) {
$this->note('<info>Purged from database:</info> '.$name);
return $this;
}
if ($stopOnVersion === null) {
$extension->uninstall();
}
if ($stopOnVersion && ! $this->versionManager->hasDatabaseVersion($extension, $stopOnVersion)) {
throw new AdminException('Extension version not found');
}
if ($this->versionManager->remove($extension, $stopOnVersion, true)) {
$this->note('<info>Rolled back:</info> '.$name);
if ($currentVersion = $this->versionManager->getCurrentVersion($extension)) {
$this->note('<info>Current Version:</info> '.$currentVersion.' ('.$this->versionManager->getCurrentVersionNote($extension).')');
}
return $this;
}
$this->note('<error>Unable to find:</error> '.$name);
return $this;
}
public function update($name, ?string $stopOnVersion = null)
{
$name = $this->manager->getName($name);
if (! ($extension = $this->manager->get($name))) {
$this->note('<error>Unable to find:</error> '.$name);
return;
}
$this->note($name);
$this->versionUpdate($extension, $stopOnVersion);
$this->publish($name);
return $this;
}
/**
* 发布扩展资源.
*
* @param string $name
*/
public function publish($name)
{
$name = $this->manager->getName($name);
$this->manager->get($name)->publishable();
Artisan::call('vendor:publish', ['--force' => true, '--tag' => $name]);
}
protected function versionUpdate($extension, $stopOnVersion)
{
$this->versionManager->notes = [];
$this->versionManager->output = $this->output;
if ($this->versionManager->update($extension, $stopOnVersion) !== false) {
foreach ($this->versionManager->notes as $note) {
$this->note($note);
}
}
}
}