2013-04-14 06:53:20 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group search
|
|
|
|
*/
|
2013-05-27 13:41:20 -07:00
|
|
|
final class PhabricatorSavedQuery extends PhabricatorSearchDAO
|
|
|
|
implements PhabricatorPolicyInterface {
|
2013-04-14 06:53:20 -07:00
|
|
|
|
|
|
|
protected $parameters = array();
|
2013-04-30 10:47:10 -07:00
|
|
|
protected $queryKey = "";
|
|
|
|
protected $engineClassName = "PhabricatorPasteSearchEngine";
|
2013-04-14 06:53:20 -07:00
|
|
|
|
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_SERIALIZATION => array(
|
|
|
|
'parameters' => self::SERIALIZATION_JSON), )
|
|
|
|
+ parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
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 10:47:10 -07:00
|
|
|
|
|
|
|
public function save() {
|
2013-05-06 07:28:49 -07:00
|
|
|
if ($this->getEngineClassName() === null) {
|
2013-04-30 10:47:10 -07:00
|
|
|
throw new Exception(pht("Engine class is null."));
|
|
|
|
}
|
|
|
|
|
2013-05-27 13:41:39 -07:00
|
|
|
// Instantiate the engine to make sure it's valid.
|
|
|
|
$this->newEngine();
|
|
|
|
|
2013-05-06 07:28:49 -07:00
|
|
|
$serial = $this->getEngineClassName().serialize($this->parameters);
|
2013-04-30 10:47:10 -07:00
|
|
|
$this->queryKey = PhabricatorHash::digestForIndex($serial);
|
|
|
|
|
|
|
|
return parent::save();
|
|
|
|
}
|
2013-05-27 13:41:20 -07:00
|
|
|
|
2013-05-27 13:41:39 -07:00
|
|
|
public function newEngine() {
|
|
|
|
return newv($this->getEngineClassName(), array());
|
|
|
|
}
|
|
|
|
|
2013-05-27 13:41:20 -07: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 06:53:20 -07:00
|
|
|
}
|