2013-04-14 15:53:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group search
|
|
|
|
*/
|
2013-05-27 22:41:20 +02:00
|
|
|
final class PhabricatorSavedQuery extends PhabricatorSearchDAO
|
|
|
|
implements PhabricatorPolicyInterface {
|
2013-04-14 15:53:20 +02:00
|
|
|
|
|
|
|
protected $parameters = array();
|
2013-05-30 23:09:37 +02:00
|
|
|
protected $queryKey;
|
|
|
|
protected $engineClassName;
|
2013-04-14 15:53:20 +02:00
|
|
|
|
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_SERIALIZATION => array(
|
2013-05-30 23:09:37 +02:00
|
|
|
'parameters' => self::SERIALIZATION_JSON,
|
|
|
|
),
|
|
|
|
) + parent::getConfiguration();
|
2013-04-14 15:53:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setParameter($key, $value) {
|
|
|
|
$this->parameters[$key] = $value;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getParameter($key, $default = null) {
|
|
|
|
return idx($this->parameters, $key, $default);
|
|
|
|
}
|
2013-04-30 19:47:10 +02:00
|
|
|
|
|
|
|
public function save() {
|
2013-05-06 16:28:49 +02:00
|
|
|
if ($this->getEngineClassName() === null) {
|
2013-04-30 19:47:10 +02:00
|
|
|
throw new Exception(pht("Engine class is null."));
|
|
|
|
}
|
|
|
|
|
2013-05-27 22:41:39 +02:00
|
|
|
// Instantiate the engine to make sure it's valid.
|
|
|
|
$this->newEngine();
|
|
|
|
|
2013-05-06 16:28:49 +02:00
|
|
|
$serial = $this->getEngineClassName().serialize($this->parameters);
|
2013-04-30 19:47:10 +02:00
|
|
|
$this->queryKey = PhabricatorHash::digestForIndex($serial);
|
|
|
|
|
|
|
|
return parent::save();
|
|
|
|
}
|
2013-05-27 22:41:20 +02:00
|
|
|
|
2013-05-27 22:41:39 +02:00
|
|
|
public function newEngine() {
|
|
|
|
return newv($this->getEngineClassName(), array());
|
|
|
|
}
|
|
|
|
|
2013-05-27 22:41:20 +02:00
|
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
|
|
|
return PhabricatorPolicies::POLICY_PUBLIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-14 15:53:20 +02:00
|
|
|
}
|