Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / search / storage / PhabricatorNamedQuery.php
blob44d7a403b1a8df07c5d8f822935e1f95fc23a93b
1 <?php
3 final class PhabricatorNamedQuery extends PhabricatorSearchDAO
4 implements PhabricatorPolicyInterface {
6 protected $queryKey;
7 protected $queryName;
8 protected $userPHID;
9 protected $engineClassName;
11 protected $isBuiltin = 0;
12 protected $isDisabled = 0;
13 protected $sequence = 0;
15 const SCOPE_GLOBAL = 'scope.global';
17 protected function getConfiguration() {
18 return array(
19 self::CONFIG_COLUMN_SCHEMA => array(
20 'engineClassName' => 'text128',
21 'queryName' => 'text255',
22 'queryKey' => 'text12',
23 'isBuiltin' => 'bool',
24 'isDisabled' => 'bool',
25 'sequence' => 'uint32',
27 self::CONFIG_KEY_SCHEMA => array(
28 'key_userquery' => array(
29 'columns' => array('userPHID', 'engineClassName', 'queryKey'),
30 'unique' => true,
33 ) + parent::getConfiguration();
36 public function isGlobal() {
37 if ($this->getIsBuiltin()) {
38 return true;
41 if ($this->getUserPHID() === self::SCOPE_GLOBAL) {
42 return true;
45 return false;
48 public function getNamedQuerySortVector() {
49 if (!$this->isGlobal()) {
50 $phase = 0;
51 } else {
52 $phase = 1;
55 return id(new PhutilSortVector())
56 ->addInt($phase)
57 ->addInt($this->sequence)
58 ->addInt($this->getID());
61 /* -( PhabricatorPolicyInterface )----------------------------------------- */
64 public function getCapabilities() {
65 return array(
66 PhabricatorPolicyCapability::CAN_VIEW,
67 PhabricatorPolicyCapability::CAN_EDIT,
71 public function getPolicy($capability) {
72 return PhabricatorPolicies::POLICY_NOONE;
75 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
76 if ($viewer->getPHID() == $this->getUserPHID()) {
77 return true;
80 if ($this->isGlobal()) {
81 switch ($capability) {
82 case PhabricatorPolicyCapability::CAN_VIEW:
83 return true;
84 case PhabricatorPolicyCapability::CAN_EDIT:
85 return $viewer->getIsAdmin();
89 return false;
92 public function describeAutomaticCapability($capability) {
93 return pht(
94 'The queries you have saved are private. Only you can view or edit '.
95 'them.');