Path: blob/master/src/applications/packages/storage/PhabricatorPackagesPublisher.php
13458 views
<?php12final class PhabricatorPackagesPublisher3extends PhabricatorPackagesDAO4implements5PhabricatorPolicyInterface,6PhabricatorApplicationTransactionInterface,7PhabricatorDestructibleInterface,8PhabricatorSubscribableInterface,9PhabricatorProjectInterface,10PhabricatorConduitResultInterface,11PhabricatorNgramsInterface {1213protected $name;14protected $publisherKey;15protected $editPolicy;1617public static function initializeNewPublisher(PhabricatorUser $actor) {18$packages_application = id(new PhabricatorApplicationQuery())19->setViewer($actor)20->withClasses(array('PhabricatorPackagesApplication'))21->executeOne();2223$edit_policy = $packages_application->getPolicy(24PhabricatorPackagesPublisherDefaultEditCapability::CAPABILITY);2526return id(new self())27->setEditPolicy($edit_policy);28}2930protected function getConfiguration() {31return array(32self::CONFIG_AUX_PHID => true,33self::CONFIG_COLUMN_SCHEMA => array(34'name' => 'sort64',35'publisherKey' => 'sort64',36),37self::CONFIG_KEY_SCHEMA => array(38'key_publisher' => array(39'columns' => array('publisherKey'),40'unique' => true,41),42),43) + parent::getConfiguration();44}4546public function generatePHID() {47return PhabricatorPHID::generateNewPHID(48PhabricatorPackagesPublisherPHIDType::TYPECONST);49}5051public function getURI() {52$publisher_key = $this->getPublisherKey();53return "/package/{$publisher_key}/";54}5556public static function assertValidPublisherName($value) {57$length = phutil_utf8_strlen($value);58if (!$length) {59throw new Exception(60pht(61'Publisher name "%s" is not valid: publisher names are required.',62$value));63}6465$max_length = 64;66if ($length > $max_length) {67throw new Exception(68pht(69'Publisher name "%s" is not valid: publisher names must not be '.70'more than %s characters long.',71$value,72new PhutilNumber($max_length)));73}74}7576public static function assertValidPublisherKey($value) {77$length = phutil_utf8_strlen($value);78if (!$length) {79throw new Exception(80pht(81'Publisher key "%s" is not valid: publisher keys are required.',82$value));83}8485$max_length = 64;86if ($length > $max_length) {87throw new Exception(88pht(89'Publisher key "%s" is not valid: publisher keys must not be '.90'more than %s characters long.',91$value,92new PhutilNumber($max_length)));93}9495if (!preg_match('/^[a-z]+\z/', $value)) {96throw new Exception(97pht(98'Publisher key "%s" is not valid: publisher keys may only contain '.99'lowercase latin letters.',100$value));101}102}103104105/* -( PhabricatorSubscribableInterface )----------------------------------- */106107108public function isAutomaticallySubscribed($phid) {109return false;110}111112113/* -( Policy Interface )--------------------------------------------------- */114115116public function getCapabilities() {117return array(118PhabricatorPolicyCapability::CAN_VIEW,119PhabricatorPolicyCapability::CAN_EDIT,120);121}122123public function getPolicy($capability) {124switch ($capability) {125case PhabricatorPolicyCapability::CAN_VIEW:126return PhabricatorPolicies::getMostOpenPolicy();127case PhabricatorPolicyCapability::CAN_EDIT:128return $this->getEditPolicy();129}130}131132public function hasAutomaticCapability($capability, PhabricatorUser $user) {133return false;134}135136137/* -( PhabricatorDestructibleInterface )----------------------------------- */138139140public function destroyObjectPermanently(141PhabricatorDestructionEngine $engine) {142$viewer = $engine->getViewer();143144$this->openTransaction();145146$packages = id(new PhabricatorPackagesPackageQuery())147->setViewer($viewer)148->withPublisherPHIDs(array($this->getPHID()))149->execute();150foreach ($packages as $package) {151$engine->destroyObject($package);152}153154$this->delete();155156$this->saveTransaction();157}158159160/* -( PhabricatorApplicationTransactionInterface )------------------------- */161162163public function getApplicationTransactionEditor() {164return new PhabricatorPackagesPublisherEditor();165}166167public function getApplicationTransactionTemplate() {168return new PhabricatorPackagesPublisherTransaction();169}170171172/* -( PhabricatorNgramsInterface )----------------------------------------- */173174175public function newNgrams() {176return array(177id(new PhabricatorPackagesPublisherNameNgrams())178->setValue($this->getName()),179);180}181182183/* -( PhabricatorConduitResultInterface )---------------------------------- */184185186public function getFieldSpecificationsForConduit() {187return array(188id(new PhabricatorConduitSearchFieldSpecification())189->setKey('name')190->setType('string')191->setDescription(pht('The name of the publisher.')),192id(new PhabricatorConduitSearchFieldSpecification())193->setKey('publisherKey')194->setType('string')195->setDescription(pht('The unique key of the publisher.')),196);197}198199public function getFieldValuesForConduit() {200return array(201'name' => $this->getName(),202'publisherKey' => $this->getPublisherKey(),203);204}205206public function getConduitSearchAttachments() {207return array();208}209210211}212213214