Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / nuance / storage / NuanceSource.php
blob5e06a5dc0a6a4b423bf8ed063031bdd788a7e380
1 <?php
3 final class NuanceSource extends NuanceDAO
4 implements
5 PhabricatorApplicationTransactionInterface,
6 PhabricatorPolicyInterface,
7 PhabricatorNgramsInterface {
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;
18 private $definition = self::ATTACHABLE;
20 protected function getConfiguration() {
21 return array(
22 self::CONFIG_AUX_PHID => true,
23 self::CONFIG_SERIALIZATION => array(
24 'data' => self::SERIALIZATION_JSON,
26 self::CONFIG_COLUMN_SCHEMA => array(
27 'name' => 'sort255',
28 'type' => 'text32',
29 'mailKey' => 'bytes20',
30 'isDisabled' => 'bool',
32 self::CONFIG_KEY_SCHEMA => array(
33 'key_type' => array(
34 'columns' => array('type', 'dateModified'),
37 ) + parent::getConfiguration();
40 public function generatePHID() {
41 return PhabricatorPHID::generateNewPHID(NuanceSourcePHIDType::TYPECONST);
44 public function save() {
45 if (!$this->getMailKey()) {
46 $this->setMailKey(Filesystem::readRandomCharacters(20));
48 return parent::save();
51 public function getURI() {
52 return '/nuance/source/view/'.$this->getID().'/';
55 public static function initializeNewSource(
56 PhabricatorUser $actor,
57 NuanceSourceDefinition $definition) {
58 $app = id(new PhabricatorApplicationQuery())
59 ->setViewer($actor)
60 ->withClasses(array('PhabricatorNuanceApplication'))
61 ->executeOne();
63 $view_policy = $app->getPolicy(
64 NuanceSourceDefaultViewCapability::CAPABILITY);
65 $edit_policy = $app->getPolicy(
66 NuanceSourceDefaultEditCapability::CAPABILITY);
68 return id(new NuanceSource())
69 ->setViewPolicy($view_policy)
70 ->setEditPolicy($edit_policy)
71 ->setType($definition->getSourceTypeConstant())
72 ->attachDefinition($definition)
73 ->setIsDisabled(0);
76 public function getDefinition() {
77 return $this->assertAttached($this->definition);
80 public function attachDefinition(NuanceSourceDefinition $definition) {
81 $this->definition = $definition;
82 return $this;
85 public function getSourceProperty($key, $default = null) {
86 return idx($this->data, $key, $default);
89 public function setSourceProperty($key, $value) {
90 $this->data[$key] = $value;
91 return $this;
95 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
98 public function getApplicationTransactionEditor() {
99 return new NuanceSourceEditor();
102 public function getApplicationTransactionTemplate() {
103 return new NuanceSourceTransaction();
107 /* -( PhabricatorPolicyInterface )----------------------------------------- */
110 public function getCapabilities() {
111 return array(
112 PhabricatorPolicyCapability::CAN_VIEW,
113 PhabricatorPolicyCapability::CAN_EDIT,
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();
126 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
127 return false;
131 /* -( PhabricatorNgramsInterface )----------------------------------------- */
134 public function newNgrams() {
135 return array(
136 id(new NuanceSourceNameNgrams())
137 ->setValue($this->getName()),