Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / search / storage / PhabricatorSavedQuery.php
blob837f4fde4259eecfda2cd886a9075898c9893022
1 <?php
3 final class PhabricatorSavedQuery extends PhabricatorSearchDAO
4 implements PhabricatorPolicyInterface {
6 protected $parameters = array();
7 protected $queryKey;
8 protected $engineClassName;
10 private $parameterMap = self::ATTACHABLE;
12 protected function getConfiguration() {
13 return array(
14 self::CONFIG_SERIALIZATION => array(
15 'parameters' => self::SERIALIZATION_JSON,
17 self::CONFIG_COLUMN_SCHEMA => array(
18 'engineClassName' => 'text255',
19 'queryKey' => 'text12',
21 self::CONFIG_KEY_SCHEMA => array(
22 'key_queryKey' => array(
23 'columns' => array('queryKey'),
24 'unique' => true,
27 ) + parent::getConfiguration();
30 public function setParameter($key, $value) {
31 $this->parameters[$key] = $value;
32 return $this;
35 public function getParameter($key, $default = null) {
36 return idx($this->parameters, $key, $default);
39 public function save() {
40 if ($this->getEngineClassName() === null) {
41 throw new Exception(pht('Engine class is null.'));
44 // Instantiate the engine to make sure it's valid.
45 $this->newEngine();
47 $serial = $this->getEngineClassName().serialize($this->parameters);
48 $this->queryKey = PhabricatorHash::digestForIndex($serial);
50 return parent::save();
53 public function newEngine() {
54 return newv($this->getEngineClassName(), array());
57 public function attachParameterMap(array $map) {
58 $this->parameterMap = $map;
59 return $this;
62 public function getEvaluatedParameter($key) {
63 return $this->assertAttachedKey($this->parameterMap, $key);
66 public function newCopy() {
67 return id(new self())
68 ->setParameters($this->getParameters())
69 ->setQueryKey(null)
70 ->setEngineClassName($this->getEngineClassName());
74 /* -( PhabricatorPolicyInterface )----------------------------------------- */
77 public function getCapabilities() {
78 return array(
79 PhabricatorPolicyCapability::CAN_VIEW,
83 public function getPolicy($capability) {
84 return PhabricatorPolicies::POLICY_PUBLIC;
87 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
88 return false;