[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/search/controller/ -> PhabricatorSearchDeleteController.php (source)

   1  <?php
   2  
   3  final class PhabricatorSearchDeleteController
   4    extends PhabricatorSearchBaseController {
   5  
   6    private $queryKey;
   7    private $engineClass;
   8  
   9    public function willProcessRequest(array $data) {
  10      $this->queryKey = idx($data, 'queryKey');
  11      $this->engineClass = idx($data, 'engine');
  12    }
  13  
  14    public function processRequest() {
  15      $request = $this->getRequest();
  16      $user = $request->getUser();
  17  
  18      $key = $this->queryKey;
  19  
  20      $base_class = 'PhabricatorApplicationSearchEngine';
  21      if (!is_subclass_of($this->engineClass, $base_class)) {
  22        return new Aphront400Response();
  23      }
  24  
  25      $engine = newv($this->engineClass, array());
  26      $engine->setViewer($user);
  27  
  28      $named_query = id(new PhabricatorNamedQueryQuery())
  29        ->setViewer($user)
  30        ->withEngineClassNames(array($this->engineClass))
  31        ->withQueryKeys(array($key))
  32        ->withUserPHIDs(array($user->getPHID()))
  33        ->executeOne();
  34  
  35      if (!$named_query && $engine->isBuiltinQuery($key)) {
  36        $named_query = $engine->getBuiltinQuery($key);
  37      }
  38  
  39      if (!$named_query) {
  40        return new Aphront404Response();
  41      }
  42  
  43      $builtin = null;
  44      if ($engine->isBuiltinQuery($key)) {
  45        $builtin = $engine->getBuiltinQuery($key);
  46      }
  47  
  48      $return_uri = $engine->getQueryManagementURI();
  49  
  50      if ($request->isDialogFormPost()) {
  51        if ($named_query->getIsBuiltin()) {
  52          $named_query->setIsDisabled((int)(!$named_query->getIsDisabled()));
  53          $named_query->save();
  54        } else {
  55          $named_query->delete();
  56        }
  57  
  58        return id(new AphrontRedirectResponse())->setURI($return_uri);
  59      }
  60  
  61      if ($named_query->getIsBuiltin()) {
  62        if ($named_query->getIsDisabled()) {
  63          $title = pht('Enable Query?');
  64          $desc = pht(
  65            'Enable the built-in query "%s"? It will appear in your menu again.',
  66            $builtin->getQueryName());
  67          $button = pht('Enable Query');
  68        } else {
  69          $title = pht('Disable Query?');
  70          $desc = pht(
  71            'This built-in query can not be deleted, but you can disable it so '.
  72            'it does not appear in your query menu. You can enable it again '.
  73            'later. Disable built-in query "%s"?',
  74            $builtin->getQueryName());
  75          $button = pht('Disable Query');
  76        }
  77      } else {
  78        $title = pht('Really Delete Query?');
  79        $desc = pht(
  80          'Really delete the query "%s"? You can not undo this. Remember '.
  81          'all the great times you had filtering results together?',
  82          $named_query->getQueryName());
  83        $button = pht('Delete Query');
  84      }
  85  
  86      $dialog = id(new AphrontDialogView())
  87        ->setUser($user)
  88        ->setTitle($title)
  89        ->appendChild($desc)
  90        ->addCancelButton($return_uri)
  91        ->addSubmitButton($button);
  92  
  93      return id(new AphrontDialogResponse())->setDialog($dialog);
  94    }
  95  
  96  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1