[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/dashboard/controller/ -> PhabricatorDashboardUninstallController.php (source)

   1  <?php
   2  
   3  final class PhabricatorDashboardUninstallController
   4    extends PhabricatorDashboardController {
   5  
   6    private $id;
   7  
   8    public function willProcessRequest(array $data) {
   9      $this->id = idx($data, 'id');
  10    }
  11  
  12    public function processRequest() {
  13      $request = $this->getRequest();
  14      $viewer = $request->getUser();
  15  
  16      $dashboard = id(new PhabricatorDashboardQuery())
  17        ->setViewer($viewer)
  18        ->withIDs(array($this->id))
  19        ->executeOne();
  20      if (!$dashboard) {
  21        return new Aphront404Response();
  22      }
  23      $dashboard_phid = $dashboard->getPHID();
  24  
  25      $object_phid = $request->getStr('objectPHID', $viewer->getPHID());
  26      $object = id(new PhabricatorObjectQuery())
  27        ->setViewer($viewer)
  28        ->requireCapabilities(
  29          array(
  30            PhabricatorPolicyCapability::CAN_VIEW,
  31            PhabricatorPolicyCapability::CAN_EDIT,
  32          ))
  33        ->withPHIDs(array($object_phid))
  34        ->executeOne();
  35      if (!$object) {
  36        return new Aphront404Response();
  37      }
  38  
  39      $application_class = $request->getStr(
  40        'applicationClass',
  41        'PhabricatorHomeApplication');
  42  
  43      $dashboard_install = id(new PhabricatorDashboardInstall())
  44        ->loadOneWhere(
  45          'objectPHID = %s AND applicationClass = %s',
  46          $object_phid,
  47          $application_class);
  48      if (!$dashboard_install) {
  49        return new Aphront404Response();
  50      }
  51      if ($dashboard_install->getDashboardPHID() != $dashboard_phid) {
  52        return new Aphront404Response();
  53      }
  54  
  55      $installer_phid = $viewer->getPHID();
  56      $handles = $this->loadHandles(array($object_phid, $installer_phid));
  57  
  58      if ($request->isFormPost()) {
  59        $dashboard_install->delete();
  60        return id(new AphrontRedirectResponse())
  61          ->setURI($this->getRedirectURI($application_class, $object_phid));
  62      }
  63  
  64      $body = $this->getBodyContent(
  65        $application_class,
  66        $object_phid,
  67        $installer_phid);
  68  
  69      $form = id(new AphrontFormView())
  70        ->setUser($viewer)
  71        ->appendChild($body);
  72  
  73      return $this->newDialog()
  74        ->setTitle(pht('Uninstall Dashboard'))
  75        ->appendChild($form->buildLayoutView())
  76        ->addCancelButton($this->getCancelURI(
  77          $application_class, $object_phid))
  78        ->addSubmitButton(pht('Uninstall Dashboard'));
  79    }
  80  
  81    private function getBodyContent(
  82      $application_class,
  83      $object_phid,
  84      $installer_phid) {
  85  
  86      $body = array();
  87      switch ($application_class) {
  88        case 'PhabricatorHomeApplication':
  89          if ($installer_phid == $object_phid) {
  90            $body[] = phutil_tag(
  91              'p',
  92              array(),
  93              pht(
  94                'Are you sure you want to uninstall this dashboard as your '.
  95                'home page?'));
  96            $body[] = phutil_tag(
  97              'p',
  98              array(),
  99              pht(
 100                'You will be re-directed to your bland, default home page if '.
 101                'you choose to uninstall this dashboard.'));
 102          } else {
 103            $body[] = phutil_tag(
 104              'p',
 105              array(),
 106              pht(
 107                'Are you sure you want to uninstall this dashboard as the home '.
 108                'page for %s?',
 109                $this->getHandle($object_phid)->getName()));
 110          }
 111          break;
 112      }
 113      return $body;
 114    }
 115  
 116    private function getCancelURI($application_class, $object_phid) {
 117      $uri = null;
 118      switch ($application_class) {
 119        case 'PhabricatorHomeApplication':
 120          $uri = '/dashboard/view/'.$this->id.'/';
 121          break;
 122      }
 123      return $uri;
 124    }
 125  
 126    private function getRedirectURI($application_class, $object_phid) {
 127      $uri = null;
 128      switch ($application_class) {
 129        case 'PhabricatorHomeApplication':
 130          $uri = '/';
 131          break;
 132      }
 133      return $uri;
 134    }
 135  
 136  }


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