[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class PhabricatorDashboardCopyController
   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        ->needPanels(true)
  20        ->executeOne();
  21      if (!$dashboard) {
  22        return new Aphront404Response();
  23      }
  24  
  25      $manage_uri = $this->getApplicationURI('manage/'.$dashboard->getID().'/');
  26  
  27      if ($request->isFormPost()) {
  28  
  29        $copy = PhabricatorDashboard::initializeNewDashboard($viewer);
  30        $copy = PhabricatorDashboard::copyDashboard($copy, $dashboard);
  31  
  32        $copy->setName(pht('Copy of %s', $copy->getName()));
  33  
  34        // Set up all the edges for the new dashboard.
  35  
  36        $xactions = array();
  37        $xactions[] = id(new PhabricatorDashboardTransaction())
  38          ->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
  39          ->setMetadataValue(
  40            'edge:type',
  41            PhabricatorEdgeConfig::TYPE_DASHBOARD_HAS_PANEL)
  42          ->setNewValue(
  43            array(
  44              '=' => array_fuse($dashboard->getPanelPHIDs()),
  45            ));
  46  
  47        $editor = id(new PhabricatorDashboardTransactionEditor())
  48          ->setActor($viewer)
  49          ->setContentSourceFromRequest($request)
  50          ->setContinueOnMissingFields(true)
  51          ->setContinueOnNoEffect(true)
  52          ->applyTransactions($copy, $xactions);
  53  
  54        $manage_uri = $this->getApplicationURI('edit/'.$copy->getID().'/');
  55        return id(new AphrontRedirectResponse())->setURI($manage_uri);
  56      }
  57  
  58      return $this->newDialog()
  59        ->setTitle(pht('Copy Dashboard'))
  60        ->appendParagraph(
  61          pht(
  62            'Create a copy of the dashboard "%s"?',
  63            phutil_tag('strong', array(), $dashboard->getName())))
  64        ->addCancelButton($manage_uri)
  65        ->addSubmitButton(pht('Create Copy'));
  66    }
  67  
  68  }


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