forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorRepositoryCommitHint.php
133 lines (115 loc) · 3.36 KB
/
PhabricatorRepositoryCommitHint.php
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
122
123
124
125
126
127
128
129
130
131
132
133
<?php
final class PhabricatorRepositoryCommitHint
extends PhabricatorRepositoryDAO
implements PhabricatorPolicyInterface {
protected $repositoryPHID;
protected $oldCommitIdentifier;
protected $newCommitIdentifier;
protected $hintType;
const HINT_NONE = 'none';
const HINT_REWRITTEN = 'rewritten';
const HINT_UNREADABLE = 'unreadable';
protected function getConfiguration() {
return array(
self::CONFIG_TIMESTAMPS => false,
self::CONFIG_COLUMN_SCHEMA => array(
'oldCommitIdentifier' => 'text40',
'newCommitIdentifier' => 'text40?',
'hintType' => 'text32',
),
self::CONFIG_KEY_SCHEMA => array(
'key_old' => array(
'columns' => array('repositoryPHID', 'oldCommitIdentifier'),
'unique' => true,
),
),
) + parent::getConfiguration();
}
public static function getAllHintTypes() {
return array(
self::HINT_NONE,
self::HINT_REWRITTEN,
self::HINT_UNREADABLE,
);
}
public static function updateHint($repository_phid, $old, $new, $type) {
switch ($type) {
case self::HINT_NONE:
break;
case self::HINT_REWRITTEN:
if (!$new) {
throw new Exception(
pht(
'When hinting a commit ("%s") as rewritten, you must provide '.
'the commit it was rewritten into.',
$old));
}
break;
case self::HINT_UNREADABLE:
if ($new) {
throw new Exception(
pht(
'When hinting a commit ("%s") as unreadable, you must not '.
'provide a new commit ("%s").',
$old,
$new));
}
break;
default:
$all_types = self::getAllHintTypes();
throw new Exception(
pht(
'Hint type ("%s") for commit ("%s") is not valid. Valid hints '.
'are: %s.',
$type,
$old,
implode(', ', $all_types)));
}
$table = new self();
$table_name = $table->getTableName();
$conn = $table->establishConnection('w');
if ($type == self::HINT_NONE) {
queryfx(
$conn,
'DELETE FROM %T WHERE repositoryPHID = %s AND oldCommitIdentifier = %s',
$table_name,
$repository_phid,
$old);
} else {
queryfx(
$conn,
'INSERT INTO %T
(repositoryPHID, oldCommitIdentifier, newCommitIdentifier, hintType)
VALUES (%s, %s, %ns, %s)
ON DUPLICATE KEY UPDATE
newCommitIdentifier = VALUES(newCommitIdentifier),
hintType = VALUES(hintType)',
$table_name,
$repository_phid,
$old,
$new,
$type);
}
}
public function isUnreadable() {
return ($this->getHintType() == self::HINT_UNREADABLE);
}
public function isRewritten() {
return ($this->getHintType() == self::HINT_REWRITTEN);
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
);
}
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return PhabricatorPolicies::getMostOpenPolicy();
}
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
}