Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/xaction/DifferentialRevisionRepositoryTransaction.php
12256 views
1
<?php
2
3
final class DifferentialRevisionRepositoryTransaction
4
extends DifferentialRevisionTransactionType {
5
6
const TRANSACTIONTYPE = 'differential.revision.repository';
7
8
public function generateOldValue($object) {
9
return $object->getRepositoryPHID();
10
}
11
12
public function applyInternalEffects($object, $value) {
13
$object->setRepositoryPHID($value);
14
}
15
16
public function getTitle() {
17
$old = $this->getOldValue();
18
$new = $this->getNewValue();
19
if ($old && $new) {
20
return pht(
21
'%s changed the repository for this revision from %s to %s.',
22
$this->renderAuthor(),
23
$this->renderHandle($old),
24
$this->renderHandle($new));
25
} else if ($new) {
26
return pht(
27
'%s set the repository for this revision to %s.',
28
$this->renderAuthor(),
29
$this->renderHandle($new));
30
} else {
31
return pht(
32
'%s removed %s as the repository for this revision.',
33
$this->renderAuthor(),
34
$this->renderHandle($old));
35
}
36
}
37
38
public function getTitleForFeed() {
39
$old = $this->getOldValue();
40
$new = $this->getNewValue();
41
if ($old && $new) {
42
return pht(
43
'%s changed the repository for %s from %s to %s.',
44
$this->renderAuthor(),
45
$this->renderObject(),
46
$this->renderHandle($old),
47
$this->renderHandle($new));
48
} else if ($new) {
49
return pht(
50
'%s set the repository for %s to %s.',
51
$this->renderAuthor(),
52
$this->renderObject(),
53
$this->renderHandle($new));
54
} else {
55
return pht(
56
'%s removed %s as the repository for %s.',
57
$this->renderAuthor(),
58
$this->renderHandle($old),
59
$this->renderObject());
60
}
61
}
62
63
public function validateTransactions($object, array $xactions) {
64
$actor = $this->getActor();
65
66
$errors = array();
67
68
$old_value = $object->getRepositoryPHID();
69
foreach ($xactions as $xaction) {
70
$new_value = $xaction->getNewValue();
71
if (!$new_value) {
72
continue;
73
}
74
75
if ($new_value == $old_value) {
76
continue;
77
}
78
79
$repository = id(new PhabricatorRepositoryQuery())
80
->setViewer($actor)
81
->withPHIDs(array($new_value))
82
->executeOne();
83
if (!$repository) {
84
$errors[] = $this->newInvalidError(
85
pht(
86
'Repository "%s" is not a valid repository, or you do not have '.
87
'permission to view it.',
88
$new_value),
89
$xaction);
90
}
91
}
92
93
return $errors;
94
}
95
96
}
97
98