Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / packages / storage / PhabricatorPackagesVersion.php
blobcd5e2648f83fc4f5946b0e8743710b6493abf10e
1 <?php
3 final class PhabricatorPackagesVersion
4 extends PhabricatorPackagesDAO
5 implements
6 PhabricatorPolicyInterface,
7 PhabricatorExtendedPolicyInterface,
8 PhabricatorApplicationTransactionInterface,
9 PhabricatorDestructibleInterface,
10 PhabricatorSubscribableInterface,
11 PhabricatorProjectInterface,
12 PhabricatorConduitResultInterface,
13 PhabricatorNgramsInterface {
15 protected $name;
16 protected $packagePHID;
18 private $package;
20 public static function initializeNewVersion(PhabricatorUser $actor) {
21 return id(new self());
24 protected function getConfiguration() {
25 return array(
26 self::CONFIG_AUX_PHID => true,
27 self::CONFIG_COLUMN_SCHEMA => array(
28 'name' => 'sort64',
30 self::CONFIG_KEY_SCHEMA => array(
31 'key_package' => array(
32 'columns' => array('packagePHID', 'name'),
33 'unique' => true,
36 ) + parent::getConfiguration();
39 public function generatePHID() {
40 return PhabricatorPHID::generateNewPHID(
41 PhabricatorPackagesVersionPHIDType::TYPECONST);
44 public function getURI() {
45 $package = $this->getPackage();
46 $full_key = $package->getFullKey();
47 $name = $this->getName();
49 return "/package/{$full_key}/{$name}/";
52 public function attachPackage(PhabricatorPackagesPackage $package) {
53 $this->package = $package;
54 return $this;
57 public function getPackage() {
58 return $this->assertAttached($this->package);
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));
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)));
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));
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));
98 /* -( PhabricatorSubscribableInterface )----------------------------------- */
101 public function isAutomaticallySubscribed($phid) {
102 return false;
106 /* -( Policy Interface )--------------------------------------------------- */
109 public function getCapabilities() {
110 return array(
111 PhabricatorPolicyCapability::CAN_VIEW,
112 PhabricatorPolicyCapability::CAN_EDIT,
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;
125 public function hasAutomaticCapability($capability, PhabricatorUser $user) {
126 return false;
130 /* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
133 public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
134 return array(
135 array(
136 $this->getPackage(),
137 $capability,
143 /* -( PhabricatorDestructibleInterface )----------------------------------- */
146 public function destroyObjectPermanently(
147 PhabricatorDestructionEngine $engine) {
148 $this->delete();
152 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
155 public function getApplicationTransactionEditor() {
156 return new PhabricatorPackagesVersionEditor();
159 public function getApplicationTransactionTemplate() {
160 return new PhabricatorPackagesVersionTransaction();
164 /* -( PhabricatorNgramsInterface )----------------------------------------- */
167 public function newNgrams() {
168 return array(
169 id(new PhabricatorPackagesVersionNameNgrams())
170 ->setValue($this->getName()),
175 /* -( PhabricatorConduitResultInterface )---------------------------------- */
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.')),
187 public function getFieldValuesForConduit() {
188 return array(
189 'name' => $this->getName(),
193 public function getConduitSearchAttachments() {
194 return array();