|
| 1 | +<?php |
| 2 | + |
| 3 | +final class PhabricatorProjectBoardImportController |
| 4 | + extends PhabricatorProjectBoardController { |
| 5 | + |
| 6 | + private $projectID; |
| 7 | + |
| 8 | + public function willProcessRequest(array $data) { |
| 9 | + $this->projectID = $data['projectID']; |
| 10 | + } |
| 11 | + |
| 12 | + public function processRequest() { |
| 13 | + $request = $this->getRequest(); |
| 14 | + $viewer = $request->getUser(); |
| 15 | + |
| 16 | + $project = id(new PhabricatorProjectQuery()) |
| 17 | + ->setViewer($viewer) |
| 18 | + ->requireCapabilities( |
| 19 | + array( |
| 20 | + PhabricatorPolicyCapability::CAN_VIEW, |
| 21 | + PhabricatorPolicyCapability::CAN_EDIT, |
| 22 | + )) |
| 23 | + ->withIDs(array($this->projectID)) |
| 24 | + ->executeOne(); |
| 25 | + if (!$project) { |
| 26 | + return new Aphront404Response(); |
| 27 | + } |
| 28 | + $this->setProject($project); |
| 29 | + |
| 30 | + $columns = id(new PhabricatorProjectColumnQuery()) |
| 31 | + ->setViewer($viewer) |
| 32 | + ->withProjectPHIDs(array($project->getPHID())) |
| 33 | + ->execute(); |
| 34 | + if ($columns) { |
| 35 | + return new Aphront400Response(); |
| 36 | + } |
| 37 | + |
| 38 | + $project_id = $project->getID(); |
| 39 | + $board_uri = $this->getApplicationURI("board/{$project_id}/"); |
| 40 | + |
| 41 | + if ($request->isFormPost()) { |
| 42 | + $import_phid = $request->getArr('importProjectPHID'); |
| 43 | + $import_phid = reset($import_phid); |
| 44 | + |
| 45 | + $import_columns = id(new PhabricatorProjectColumnQuery()) |
| 46 | + ->setViewer($viewer) |
| 47 | + ->withProjectPHIDs(array($import_phid)) |
| 48 | + ->execute(); |
| 49 | + if (!$import_columns) { |
| 50 | + return new Aphront400Response(); |
| 51 | + } |
| 52 | + |
| 53 | + $table = id(new PhabricatorProjectColumn()) |
| 54 | + ->openTransaction(); |
| 55 | + foreach ($import_columns as $import_column) { |
| 56 | + if ($import_column->isHidden()) { |
| 57 | + continue; |
| 58 | + } |
| 59 | + $new_column = PhabricatorProjectColumn::initializeNewColumn($viewer) |
| 60 | + ->setSequence($import_column->getSequence()) |
| 61 | + ->setProjectPHID($project->getPHID()) |
| 62 | + ->setName($import_column->getName()) |
| 63 | + ->save(); |
| 64 | + } |
| 65 | + $table->saveTransaction(); |
| 66 | + |
| 67 | + return id(new AphrontRedirectResponse())->setURI($board_uri); |
| 68 | + } |
| 69 | + |
| 70 | + $proj_selector = id(new AphrontFormTokenizerControl()) |
| 71 | + ->setName('importProjectPHID') |
| 72 | + ->setUser($viewer) |
| 73 | + ->setDatasource(id(new PhabricatorProjectDatasource()) |
| 74 | + ->setParameters(array('mustHaveColumns' => true)) |
| 75 | + ->setLimit(1)); |
| 76 | + return $this->newDialog() |
| 77 | + ->setTitle(pht('Import Columns')) |
| 78 | + ->setWidth(AphrontDialogView::WIDTH_FORM) |
| 79 | + ->appendParagraph(pht('Choose a project to import columns from:')) |
| 80 | + ->appendChild($proj_selector) |
| 81 | + ->addCancelButton($board_uri) |
| 82 | + ->addSubmitButton(pht('Import')); |
| 83 | + } |
| 84 | + |
| 85 | +} |
0 commit comments