3 final class PhabricatorPackagesPublisher
4 extends PhabricatorPackagesDAO
6 PhabricatorPolicyInterface
,
7 PhabricatorApplicationTransactionInterface
,
8 PhabricatorDestructibleInterface
,
9 PhabricatorSubscribableInterface
,
10 PhabricatorProjectInterface
,
11 PhabricatorConduitResultInterface
,
12 PhabricatorNgramsInterface
{
15 protected $publisherKey;
16 protected $editPolicy;
18 public static function initializeNewPublisher(PhabricatorUser
$actor) {
19 $packages_application = id(new PhabricatorApplicationQuery())
21 ->withClasses(array('PhabricatorPackagesApplication'))
24 $edit_policy = $packages_application->getPolicy(
25 PhabricatorPackagesPublisherDefaultEditCapability
::CAPABILITY
);
28 ->setEditPolicy($edit_policy);
31 protected function getConfiguration() {
33 self
::CONFIG_AUX_PHID
=> true,
34 self
::CONFIG_COLUMN_SCHEMA
=> array(
36 'publisherKey' => 'sort64',
38 self
::CONFIG_KEY_SCHEMA
=> array(
39 'key_publisher' => array(
40 'columns' => array('publisherKey'),
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);
62 'Publisher name "%s" is not valid: publisher names are required.',
67 if ($length > $max_length) {
70 'Publisher name "%s" is not valid: publisher names must not be '.
71 'more than %s characters long.',
73 new PhutilNumber($max_length)));
77 public static function assertValidPublisherKey($value) {
78 $length = phutil_utf8_strlen($value);
82 'Publisher key "%s" is not valid: publisher keys are required.',
87 if ($length > $max_length) {
90 'Publisher key "%s" is not valid: publisher keys must not be '.
91 'more than %s characters long.',
93 new PhutilNumber($max_length)));
96 if (!preg_match('/^[a-z]+\z/', $value)) {
99 'Publisher key "%s" is not valid: publisher keys may only contain '.
100 'lowercase latin letters.',
106 /* -( PhabricatorSubscribableInterface )----------------------------------- */
109 public function isAutomaticallySubscribed($phid) {
114 /* -( Policy Interface )--------------------------------------------------- */
117 public function getCapabilities() {
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) {
138 /* -( PhabricatorDestructibleInterface )----------------------------------- */
141 public function destroyObjectPermanently(
142 PhabricatorDestructionEngine
$engine) {
143 $viewer = $engine->getViewer();
145 $this->openTransaction();
147 $packages = id(new PhabricatorPackagesPackageQuery())
149 ->withPublisherPHIDs(array($this->getPHID()))
151 foreach ($packages as $package) {
152 $engine->destroyObject($package);
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() {
178 id(new PhabricatorPackagesPublisherNameNgrams())
179 ->setValue($this->getName()),
184 /* -( PhabricatorConduitResultInterface )---------------------------------- */
187 public function getFieldSpecificationsForConduit() {
189 id(new PhabricatorConduitSearchFieldSpecification())
192 ->setDescription(pht('The name of the publisher.')),
193 id(new PhabricatorConduitSearchFieldSpecification())
194 ->setKey('publisherKey')
196 ->setDescription(pht('The unique key of the publisher.')),
200 public function getFieldValuesForConduit() {
202 'name' => $this->getName(),
203 'publisherKey' => $this->getPublisherKey(),
207 public function getConduitSearchAttachments() {