@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorPackagesVersion
4 extends PhabricatorPackagesDAO
5 implements
6 PhabricatorPolicyInterface,
7 PhabricatorExtendedPolicyInterface,
8 PhabricatorApplicationTransactionInterface,
9 PhabricatorDestructibleInterface,
10 PhabricatorSubscribableInterface,
11 PhabricatorProjectInterface,
12 PhabricatorConduitResultInterface,
13 PhabricatorNgramsInterface {
14
15 protected $name;
16 protected $packagePHID;
17
18 private $package = self::ATTACHABLE;
19
20 public static function initializeNewVersion(PhabricatorUser $actor) {
21 return id(new self());
22 }
23
24 protected function getConfiguration() {
25 return array(
26 self::CONFIG_AUX_PHID => true,
27 self::CONFIG_COLUMN_SCHEMA => array(
28 'name' => 'sort64',
29 ),
30 self::CONFIG_KEY_SCHEMA => array(
31 'key_package' => array(
32 'columns' => array('packagePHID', 'name'),
33 'unique' => true,
34 ),
35 ),
36 ) + parent::getConfiguration();
37 }
38
39 public function generatePHID() {
40 return PhabricatorPHID::generateNewPHID(
41 PhabricatorPackagesVersionPHIDType::TYPECONST);
42 }
43
44 public function getURI() {
45 $package = $this->getPackage();
46 $full_key = $package->getFullKey();
47 $name = $this->getName();
48
49 return "/package/{$full_key}/{$name}/";
50 }
51
52 public function attachPackage(PhabricatorPackagesPackage $package) {
53 $this->package = $package;
54 return $this;
55 }
56
57 public function getPackage() {
58 return $this->assertAttached($this->package);
59 }
60
61 public static function assertValidVersionName($value) {
62 $length = phutil_utf8_strlen($value);
63 if (!$length) {
64 throw new Exception(
65 pht(
66 'Version name "%s" is not valid: version names are required.',
67 $value));
68 }
69
70 $max_length = 64;
71 if ($length > $max_length) {
72 throw new Exception(
73 pht(
74 'Version name "%s" is not valid: version names must not be '.
75 'more than %s characters long.',
76 $value,
77 new PhutilNumber($max_length)));
78 }
79
80 if (!preg_match('/^[A-Za-z0-9.-]+\z/', $value)) {
81 throw new Exception(
82 pht(
83 'Version name "%s" is not valid: version names may only contain '.
84 'latin letters, digits, periods, and hyphens.',
85 $value));
86 }
87
88 if (preg_match('/^[.-]|[.-]$/', $value)) {
89 throw new Exception(
90 pht(
91 'Version name "%s" is not valid: version names may not start or '.
92 'end with a period or hyphen.',
93 $value));
94 }
95 }
96
97
98/* -( PhabricatorSubscribableInterface )----------------------------------- */
99
100
101 public function isAutomaticallySubscribed($phid) {
102 return false;
103 }
104
105
106/* -( Policy Interface )--------------------------------------------------- */
107
108
109 public function getCapabilities() {
110 return array(
111 PhabricatorPolicyCapability::CAN_VIEW,
112 PhabricatorPolicyCapability::CAN_EDIT,
113 );
114 }
115
116 public function getPolicy($capability) {
117 switch ($capability) {
118 case PhabricatorPolicyCapability::CAN_VIEW:
119 return PhabricatorPolicies::getMostOpenPolicy();
120 case PhabricatorPolicyCapability::CAN_EDIT:
121 return PhabricatorPolicies::POLICY_USER;
122 }
123 }
124
125 public function hasAutomaticCapability($capability, PhabricatorUser $user) {
126 return false;
127 }
128
129
130/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
131
132
133 public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
134 return array(
135 array(
136 $this->getPackage(),
137 $capability,
138 ),
139 );
140 }
141
142
143/* -( PhabricatorDestructibleInterface )----------------------------------- */
144
145
146 public function destroyObjectPermanently(
147 PhabricatorDestructionEngine $engine) {
148 $this->delete();
149 }
150
151
152/* -( PhabricatorApplicationTransactionInterface )------------------------- */
153
154
155 public function getApplicationTransactionEditor() {
156 return new PhabricatorPackagesVersionEditor();
157 }
158
159 public function getApplicationTransactionTemplate() {
160 return new PhabricatorPackagesVersionTransaction();
161 }
162
163
164/* -( PhabricatorNgramsInterface )----------------------------------------- */
165
166
167 public function newNgrams() {
168 return array(
169 id(new PhabricatorPackagesVersionNameNgrams())
170 ->setValue($this->getName()),
171 );
172 }
173
174
175/* -( PhabricatorConduitResultInterface )---------------------------------- */
176
177
178 public function getFieldSpecificationsForConduit() {
179 return array(
180 id(new PhabricatorConduitSearchFieldSpecification())
181 ->setKey('name')
182 ->setType('string')
183 ->setDescription(pht('The name of the version.')),
184 );
185 }
186
187 public function getFieldValuesForConduit() {
188 return array(
189 'name' => $this->getName(),
190 );
191 }
192
193 public function getConduitSearchAttachments() {
194 return array();
195 }
196
197
198}