Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / packages / storage / PhabricatorPackagesPublisher.php
blob21b586dc1fbef0c346782c667d5a61e00b48dfbb
1 <?php
3 final class PhabricatorPackagesPublisher
4 extends PhabricatorPackagesDAO
5 implements
6 PhabricatorPolicyInterface,
7 PhabricatorApplicationTransactionInterface,
8 PhabricatorDestructibleInterface,
9 PhabricatorSubscribableInterface,
10 PhabricatorProjectInterface,
11 PhabricatorConduitResultInterface,
12 PhabricatorNgramsInterface {
14 protected $name;
15 protected $publisherKey;
16 protected $editPolicy;
18 public static function initializeNewPublisher(PhabricatorUser $actor) {
19 $packages_application = id(new PhabricatorApplicationQuery())
20 ->setViewer($actor)
21 ->withClasses(array('PhabricatorPackagesApplication'))
22 ->executeOne();
24 $edit_policy = $packages_application->getPolicy(
25 PhabricatorPackagesPublisherDefaultEditCapability::CAPABILITY);
27 return id(new self())
28 ->setEditPolicy($edit_policy);
31 protected function getConfiguration() {
32 return array(
33 self::CONFIG_AUX_PHID => true,
34 self::CONFIG_COLUMN_SCHEMA => array(
35 'name' => 'sort64',
36 'publisherKey' => 'sort64',
38 self::CONFIG_KEY_SCHEMA => array(
39 'key_publisher' => array(
40 'columns' => array('publisherKey'),
41 'unique' => true,
44 ) + parent::getConfiguration();
47 public function generatePHID() {
48 return PhabricatorPHID::generateNewPHID(
49 PhabricatorPackagesPublisherPHIDType::TYPECONST);
52 public function getURI() {
53 $publisher_key = $this->getPublisherKey();
54 return "/package/{$publisher_key}/";
57 public static function assertValidPublisherName($value) {
58 $length = phutil_utf8_strlen($value);
59 if (!$length) {
60 throw new Exception(
61 pht(
62 'Publisher name "%s" is not valid: publisher names are required.',
63 $value));
66 $max_length = 64;
67 if ($length > $max_length) {
68 throw new Exception(
69 pht(
70 'Publisher name "%s" is not valid: publisher names must not be '.
71 'more than %s characters long.',
72 $value,
73 new PhutilNumber($max_length)));
77 public static function assertValidPublisherKey($value) {
78 $length = phutil_utf8_strlen($value);
79 if (!$length) {
80 throw new Exception(
81 pht(
82 'Publisher key "%s" is not valid: publisher keys are required.',
83 $value));
86 $max_length = 64;
87 if ($length > $max_length) {
88 throw new Exception(
89 pht(
90 'Publisher key "%s" is not valid: publisher keys must not be '.
91 'more than %s characters long.',
92 $value,
93 new PhutilNumber($max_length)));
96 if (!preg_match('/^[a-z]+\z/', $value)) {
97 throw new Exception(
98 pht(
99 'Publisher key "%s" is not valid: publisher keys may only contain '.
100 'lowercase latin letters.',
101 $value));
106 /* -( PhabricatorSubscribableInterface )----------------------------------- */
109 public function isAutomaticallySubscribed($phid) {
110 return false;
114 /* -( Policy Interface )--------------------------------------------------- */
117 public function getCapabilities() {
118 return array(
119 PhabricatorPolicyCapability::CAN_VIEW,
120 PhabricatorPolicyCapability::CAN_EDIT,
124 public function getPolicy($capability) {
125 switch ($capability) {
126 case PhabricatorPolicyCapability::CAN_VIEW:
127 return PhabricatorPolicies::getMostOpenPolicy();
128 case PhabricatorPolicyCapability::CAN_EDIT:
129 return $this->getEditPolicy();
133 public function hasAutomaticCapability($capability, PhabricatorUser $user) {
134 return false;
138 /* -( PhabricatorDestructibleInterface )----------------------------------- */
141 public function destroyObjectPermanently(
142 PhabricatorDestructionEngine $engine) {
143 $viewer = $engine->getViewer();
145 $this->openTransaction();
147 $packages = id(new PhabricatorPackagesPackageQuery())
148 ->setViewer($viewer)
149 ->withPublisherPHIDs(array($this->getPHID()))
150 ->execute();
151 foreach ($packages as $package) {
152 $engine->destroyObject($package);
155 $this->delete();
157 $this->saveTransaction();
161 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
164 public function getApplicationTransactionEditor() {
165 return new PhabricatorPackagesPublisherEditor();
168 public function getApplicationTransactionTemplate() {
169 return new PhabricatorPackagesPublisherTransaction();
173 /* -( PhabricatorNgramsInterface )----------------------------------------- */
176 public function newNgrams() {
177 return array(
178 id(new PhabricatorPackagesPublisherNameNgrams())
179 ->setValue($this->getName()),
184 /* -( PhabricatorConduitResultInterface )---------------------------------- */
187 public function getFieldSpecificationsForConduit() {
188 return array(
189 id(new PhabricatorConduitSearchFieldSpecification())
190 ->setKey('name')
191 ->setType('string')
192 ->setDescription(pht('The name of the publisher.')),
193 id(new PhabricatorConduitSearchFieldSpecification())
194 ->setKey('publisherKey')
195 ->setType('string')
196 ->setDescription(pht('The unique key of the publisher.')),
200 public function getFieldValuesForConduit() {
201 return array(
202 'name' => $this->getName(),
203 'publisherKey' => $this->getPublisherKey(),
207 public function getConduitSearchAttachments() {
208 return array();