3 final class PhabricatorRepositoryCommitHint
4 extends PhabricatorRepositoryDAO
5 implements PhabricatorPolicyInterface
{
7 protected $repositoryPHID;
8 protected $oldCommitIdentifier;
9 protected $newCommitIdentifier;
12 const HINT_NONE
= 'none';
13 const HINT_REWRITTEN
= 'rewritten';
14 const HINT_UNREADABLE
= 'unreadable';
16 protected function getConfiguration() {
18 self
::CONFIG_TIMESTAMPS
=> false,
19 self
::CONFIG_COLUMN_SCHEMA
=> array(
20 'oldCommitIdentifier' => 'text40',
21 'newCommitIdentifier' => 'text40?',
22 'hintType' => 'text32',
24 self
::CONFIG_KEY_SCHEMA
=> array(
26 'columns' => array('repositoryPHID', 'oldCommitIdentifier'),
30 ) + parent
::getConfiguration();
33 public static function getAllHintTypes() {
37 self
::HINT_UNREADABLE
,
41 public static function updateHint($repository_phid, $old, $new, $type) {
45 case self
::HINT_REWRITTEN
:
49 'When hinting a commit ("%s") as rewritten, you must provide '.
50 'the commit it was rewritten into.',
54 case self
::HINT_UNREADABLE
:
58 'When hinting a commit ("%s") as unreadable, you must not '.
59 'provide a new commit ("%s").',
65 $all_types = self
::getAllHintTypes();
68 'Hint type ("%s") for commit ("%s") is not valid. Valid hints '.
72 implode(', ', $all_types)));
76 $table_name = $table->getTableName();
77 $conn = $table->establishConnection('w');
79 if ($type == self
::HINT_NONE
) {
82 'DELETE FROM %T WHERE repositoryPHID = %s AND oldCommitIdentifier = %s',
90 (repositoryPHID, oldCommitIdentifier, newCommitIdentifier, hintType)
91 VALUES (%s, %s, %ns, %s)
92 ON DUPLICATE KEY UPDATE
93 newCommitIdentifier = VALUES(newCommitIdentifier),
94 hintType = VALUES(hintType)',
104 public function isUnreadable() {
105 return ($this->getHintType() == self
::HINT_UNREADABLE
);
108 public function isRewritten() {
109 return ($this->getHintType() == self
::HINT_REWRITTEN
);
113 /* -( PhabricatorPolicyInterface )----------------------------------------- */
116 public function getCapabilities() {
118 PhabricatorPolicyCapability
::CAN_VIEW
,
122 public function getPolicy($capability) {
123 switch ($capability) {
124 case PhabricatorPolicyCapability
::CAN_VIEW
:
125 return PhabricatorPolicies
::getMostOpenPolicy();
129 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {