@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

at upstream/main 141 lines 3.6 kB view raw
1<?php 2 3final class NuanceSource extends NuanceDAO 4 implements 5 PhabricatorApplicationTransactionInterface, 6 PhabricatorPolicyInterface, 7 PhabricatorNgramsInterface { 8 9 protected $name; 10 protected $type; 11 protected $data = array(); 12 protected $mailKey; 13 protected $viewPolicy; 14 protected $editPolicy; 15 protected $defaultQueuePHID; 16 protected $isDisabled; 17 18 private $definition = self::ATTACHABLE; 19 20 protected function getConfiguration() { 21 return array( 22 self::CONFIG_AUX_PHID => true, 23 self::CONFIG_SERIALIZATION => array( 24 'data' => self::SERIALIZATION_JSON, 25 ), 26 self::CONFIG_COLUMN_SCHEMA => array( 27 'name' => 'sort255', 28 'type' => 'text32', 29 'mailKey' => 'bytes20', 30 'isDisabled' => 'bool', 31 ), 32 self::CONFIG_KEY_SCHEMA => array( 33 'key_type' => array( 34 'columns' => array('type', 'dateModified'), 35 ), 36 ), 37 ) + parent::getConfiguration(); 38 } 39 40 public function generatePHID() { 41 return PhabricatorPHID::generateNewPHID(NuanceSourcePHIDType::TYPECONST); 42 } 43 44 public function save() { 45 if (!$this->getMailKey()) { 46 $this->setMailKey(Filesystem::readRandomCharacters(20)); 47 } 48 return parent::save(); 49 } 50 51 public function getURI() { 52 return '/nuance/source/view/'.$this->getID().'/'; 53 } 54 55 public static function initializeNewSource( 56 PhabricatorUser $actor, 57 NuanceSourceDefinition $definition) { 58 $app = id(new PhabricatorApplicationQuery()) 59 ->setViewer($actor) 60 ->withClasses(array(PhabricatorNuanceApplication::class)) 61 ->executeOne(); 62 63 $view_policy = $app->getPolicy( 64 NuanceSourceDefaultViewCapability::CAPABILITY); 65 $edit_policy = $app->getPolicy( 66 NuanceSourceDefaultEditCapability::CAPABILITY); 67 68 return id(new NuanceSource()) 69 ->setViewPolicy($view_policy) 70 ->setEditPolicy($edit_policy) 71 ->setType($definition->getSourceTypeConstant()) 72 ->attachDefinition($definition) 73 ->setIsDisabled(0); 74 } 75 76 public function getDefinition() { 77 return $this->assertAttached($this->definition); 78 } 79 80 public function attachDefinition(NuanceSourceDefinition $definition) { 81 $this->definition = $definition; 82 return $this; 83 } 84 85 public function getSourceProperty($key, $default = null) { 86 return idx($this->data, $key, $default); 87 } 88 89 public function setSourceProperty($key, $value) { 90 $this->data[$key] = $value; 91 return $this; 92 } 93 94 95/* -( PhabricatorApplicationTransactionInterface )------------------------- */ 96 97 98 public function getApplicationTransactionEditor() { 99 return new NuanceSourceEditor(); 100 } 101 102 public function getApplicationTransactionTemplate() { 103 return new NuanceSourceTransaction(); 104 } 105 106 107/* -( PhabricatorPolicyInterface )----------------------------------------- */ 108 109 110 public function getCapabilities() { 111 return array( 112 PhabricatorPolicyCapability::CAN_VIEW, 113 PhabricatorPolicyCapability::CAN_EDIT, 114 ); 115 } 116 117 public function getPolicy($capability) { 118 switch ($capability) { 119 case PhabricatorPolicyCapability::CAN_VIEW: 120 return $this->getViewPolicy(); 121 case PhabricatorPolicyCapability::CAN_EDIT: 122 return $this->getEditPolicy(); 123 } 124 } 125 126 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 127 return false; 128 } 129 130 131/* -( PhabricatorNgramsInterface )----------------------------------------- */ 132 133 134 public function newNgrams() { 135 return array( 136 id(new NuanceSourceNameNgrams()) 137 ->setValue($this->getName()), 138 ); 139 } 140 141}