Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/meta/xactions/PhabricatorApplicationUninstallTransaction.php
12256 views
1
<?php
2
3
final class PhabricatorApplicationUninstallTransaction
4
extends PhabricatorApplicationTransactionType {
5
6
const TRANSACTIONTYPE = 'application.uninstall';
7
8
public function generateOldValue($object) {
9
$key = 'phabricator.uninstalled-applications';
10
$config_entry = PhabricatorConfigEntry::loadConfigEntry($key);
11
$list = $config_entry->getValue();
12
$uninstalled = PhabricatorEnv::getEnvConfig($key);
13
14
if (isset($uninstalled[get_class($object)])) {
15
return 'uninstalled';
16
} else {
17
return 'installed';
18
}
19
}
20
21
public function generateNewValue($object, $value) {
22
if ($value === 'uninstall') {
23
return 'uninstalled';
24
} else {
25
return 'installed';
26
}
27
}
28
29
public function applyExternalEffects($object, $value) {
30
$application = $object;
31
$user = $this->getActor();
32
33
$key = 'phabricator.uninstalled-applications';
34
$config_entry = PhabricatorConfigEntry::loadConfigEntry($key);
35
$list = $config_entry->getValue();
36
$uninstalled = PhabricatorEnv::getEnvConfig($key);
37
38
if (isset($uninstalled[get_class($application)])) {
39
unset($list[get_class($application)]);
40
} else {
41
$list[get_class($application)] = true;
42
}
43
44
$editor = $this->getEditor();
45
$content_source = $editor->getContentSource();
46
47
// Today, changing config requires "Administrator", but "Can Edit" on
48
// applications to let you uninstall them may be granted to any user.
49
PhabricatorConfigEditor::storeNewValue(
50
PhabricatorUser::getOmnipotentUser(),
51
$config_entry,
52
$list,
53
$content_source,
54
$user->getPHID());
55
}
56
57
public function getTitle() {
58
if ($this->getNewValue() === 'uninstalled') {
59
return pht(
60
'%s uninstalled this application.',
61
$this->renderAuthor());
62
} else {
63
return pht(
64
'%s installed this application.',
65
$this->renderAuthor());
66
}
67
}
68
69
public function getTitleForFeed() {
70
if ($this->getNewValue() === 'uninstalled') {
71
return pht(
72
'%s uninstalled %s.',
73
$this->renderAuthor(),
74
$this->renderObject());
75
} else {
76
return pht(
77
'%s installed %s.',
78
$this->renderAuthor(),
79
$this->renderObject());
80
}
81
}
82
83
}
84
85