Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / storage / PhabricatorRepositoryCommitHint.php
blob0a8e259dfe6e804a41452fe5ef13b65e19e6a077
1 <?php
3 final class PhabricatorRepositoryCommitHint
4 extends PhabricatorRepositoryDAO
5 implements PhabricatorPolicyInterface {
7 protected $repositoryPHID;
8 protected $oldCommitIdentifier;
9 protected $newCommitIdentifier;
10 protected $hintType;
12 const HINT_NONE = 'none';
13 const HINT_REWRITTEN = 'rewritten';
14 const HINT_UNREADABLE = 'unreadable';
16 protected function getConfiguration() {
17 return array(
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(
25 'key_old' => array(
26 'columns' => array('repositoryPHID', 'oldCommitIdentifier'),
27 'unique' => true,
30 ) + parent::getConfiguration();
33 public static function getAllHintTypes() {
34 return array(
35 self::HINT_NONE,
36 self::HINT_REWRITTEN,
37 self::HINT_UNREADABLE,
41 public static function updateHint($repository_phid, $old, $new, $type) {
42 switch ($type) {
43 case self::HINT_NONE:
44 break;
45 case self::HINT_REWRITTEN:
46 if (!$new) {
47 throw new Exception(
48 pht(
49 'When hinting a commit ("%s") as rewritten, you must provide '.
50 'the commit it was rewritten into.',
51 $old));
53 break;
54 case self::HINT_UNREADABLE:
55 if ($new) {
56 throw new Exception(
57 pht(
58 'When hinting a commit ("%s") as unreadable, you must not '.
59 'provide a new commit ("%s").',
60 $old,
61 $new));
63 break;
64 default:
65 $all_types = self::getAllHintTypes();
66 throw new Exception(
67 pht(
68 'Hint type ("%s") for commit ("%s") is not valid. Valid hints '.
69 'are: %s.',
70 $type,
71 $old,
72 implode(', ', $all_types)));
75 $table = new self();
76 $table_name = $table->getTableName();
77 $conn = $table->establishConnection('w');
79 if ($type == self::HINT_NONE) {
80 queryfx(
81 $conn,
82 'DELETE FROM %T WHERE repositoryPHID = %s AND oldCommitIdentifier = %s',
83 $table_name,
84 $repository_phid,
85 $old);
86 } else {
87 queryfx(
88 $conn,
89 'INSERT INTO %T
90 (repositoryPHID, oldCommitIdentifier, newCommitIdentifier, hintType)
91 VALUES (%s, %s, %ns, %s)
92 ON DUPLICATE KEY UPDATE
93 newCommitIdentifier = VALUES(newCommitIdentifier),
94 hintType = VALUES(hintType)',
95 $table_name,
96 $repository_phid,
97 $old,
98 $new,
99 $type);
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() {
117 return array(
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) {
130 return false;