Skip to content

Commit 7ad2eae

Browse files
Bryan Cuccioliepriestley
authored andcommitted
Implement saving queries.
Summary: Enable saved query objects to actually be saved to the database. Test Plan: Insert a call to save() and check that the query is written correctly. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin, AnhNhan Maniphest Tasks: T2625 Differential Revision: https://secure.phabricator.com/D5775 Conflicts: src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
1 parent c7be6f4 commit 7ad2eae

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE TABLE {$NAMESPACE}_search.search_savedquery (
2+
id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
3+
engineClassName VARCHAR(255) NOT NULL COLLATE utf8_bin,
4+
parameters LONGTEXT NOT NULL COLLATE utf8_bin,
5+
dateCreated INT(10) UNSIGNED NOT NULL,
6+
dateModified INT(10) UNSIGNED NOT NULL,
7+
queryKey VARCHAR(12) NOT NULL COLLATE utf8_bin,
8+
PRIMARY KEY(id),
9+
UNIQUE KEY key_queryKey (queryKey)
10+
)
11+
ENGINE=InnoDB, COLLATE utf8_general_ci

src/applications/search/storage/PhabricatorSavedQuery.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
final class PhabricatorSavedQuery extends PhabricatorSearchDAO {
77

88
protected $parameters = array();
9+
protected $queryKey = "";
10+
protected $engineClassName = "PhabricatorPasteSearchEngine";
911

1012
public function getConfiguration() {
1113
return array(
@@ -22,4 +24,15 @@ public function setParameter($key, $value) {
2224
public function getParameter($key, $default = null) {
2325
return idx($this->parameters, $key, $default);
2426
}
27+
28+
public function save() {
29+
if ($this->getEngineClass() === null) {
30+
throw new Exception(pht("Engine class is null."));
31+
}
32+
33+
$serial = $this->getEngineClass().serialize($this->parameters);
34+
$this->queryKey = PhabricatorHash::digestForIndex($serial);
35+
36+
return parent::save();
37+
}
2538
}

src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,10 @@ public function getPatches() {
12541254
'type' => 'sql',
12551255
'name' => $this->getPatchPath('20130423.conpherenceindices.sql'),
12561256
),
1257+
'20130426.search_savedquery.sql' => array(
1258+
'type' => 'sql',
1259+
'name' => $this->getPatchPath('20130426.search_savedquery.sql'),
1260+
),
12571261
);
12581262
}
12591263
}

0 commit comments

Comments
 (0)