2013-06-06 01:22:27 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorSearchOrderController
|
|
|
|
extends PhabricatorSearchBaseController {
|
|
|
|
|
2015-10-20 18:02:55 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$engine_class = $request->getURIData('engine');
|
2013-06-06 01:22:27 +02:00
|
|
|
|
|
|
|
$request->validateCSRF();
|
|
|
|
|
|
|
|
$base_class = 'PhabricatorApplicationSearchEngine';
|
2015-10-20 18:02:55 +02:00
|
|
|
if (!is_subclass_of($engine_class, $base_class)) {
|
2013-06-06 01:22:27 +02:00
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
2015-10-20 18:02:55 +02:00
|
|
|
$engine = newv($engine_class, array());
|
|
|
|
$engine->setViewer($viewer);
|
2013-06-06 01:22:27 +02:00
|
|
|
|
|
|
|
$queries = $engine->loadAllNamedQueries();
|
|
|
|
$queries = mpull($queries, null, 'getQueryKey');
|
|
|
|
|
|
|
|
$order = $request->getStrList('order');
|
|
|
|
$queries = array_select_keys($queries, $order) + $queries;
|
|
|
|
|
|
|
|
$sequence = 1;
|
|
|
|
foreach ($queries as $query) {
|
|
|
|
$query->setSequence($sequence++);
|
|
|
|
$query->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
return id(new AphrontAjaxResponse());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|