Differential D10153 Diff 24427 src/applications/project/controller/PhabricatorProjectBoardImportController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/controller/PhabricatorProjectBoardImportController.php
- This file was added.
<?php | |||||
final class PhabricatorProjectBoardImportController | |||||
extends PhabricatorProjectBoardController { | |||||
private $projectID; | |||||
public function willProcessRequest(array $data) { | |||||
$this->projectID = $data['projectID']; | |||||
} | |||||
public function processRequest() { | |||||
$request = $this->getRequest(); | |||||
$viewer = $request->getUser(); | |||||
$project = id(new PhabricatorProjectQuery()) | |||||
->setViewer($viewer) | |||||
->requireCapabilities( | |||||
array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
)) | |||||
->withIDs(array($this->projectID)) | |||||
->executeOne(); | |||||
if (!$project) { | |||||
return new Aphront404Response(); | |||||
} | |||||
$this->setProject($project); | |||||
$columns = id(new PhabricatorProjectColumnQuery()) | |||||
->setViewer($viewer) | |||||
->withProjectPHIDs(array($project->getPHID())) | |||||
->execute(); | |||||
if ($columns) { | |||||
return new Aphront400Response(); | |||||
} | |||||
$project_id = $project->getID(); | |||||
$board_uri = $this->getApplicationURI("board/{$project_id}/"); | |||||
if ($request->isFormPost()) { | |||||
$import_phid = $request->getArr('importProjectPHID'); | |||||
$import_phid = reset($import_phid); | |||||
$import_columns = id(new PhabricatorProjectColumnQuery()) | |||||
->setViewer($viewer) | |||||
->withProjectPHIDs(array($import_phid)) | |||||
->execute(); | |||||
if (!$import_columns) { | |||||
return new Aphront400Response(); | |||||
} | |||||
epriestley: Maybe HTTP 400, but this is pretty nitpicky. | |||||
$table = id(new PhabricatorProjectColumn()) | |||||
->openTransaction(); | |||||
foreach ($import_columns as $import_column) { | |||||
if ($import_column->isHidden()) { | |||||
continue; | |||||
} | |||||
$new_column = PhabricatorProjectColumn::initializeNewColumn($viewer) | |||||
->setSequence($import_column->getSequence()) | |||||
Not Done Inline ActionsOh, this is interesting. I like your behavior. epriestley: Oh, this is interesting. I like your behavior. | |||||
->setProjectPHID($project->getPHID()) | |||||
->setName($import_column->getName()) | |||||
->save(); | |||||
} | |||||
$table->saveTransaction(); | |||||
return id(new AphrontRedirectResponse())->setURI($board_uri); | |||||
} | |||||
$proj_selector = id(new AphrontFormTokenizerControl()) | |||||
->setName('importProjectPHID') | |||||
->setUser($viewer) | |||||
->setDatasource(id(new PhabricatorProjectDatasource()) | |||||
->setParameters(array('mustHaveColumns' => true)) | |||||
->setLimit(1)); | |||||
return $this->newDialog() | |||||
->setTitle(pht('Import Columns')) | |||||
Not Done Inline ActionsYou shouldn't need to edit a project to copy its columns -- being able to view it is good enough. epriestley: You shouldn't need to edit a project to copy its columns -- being able to view it is good… | |||||
->setWidth(AphrontDialogView::WIDTH_FORM) | |||||
->appendParagraph(pht('Choose a project to import columns from:')) | |||||
->appendChild($proj_selector) | |||||
->addCancelButton($board_uri) | |||||
->addSubmitButton(pht('Import')); | |||||
} | |||||
} | |||||
Not Done Inline ActionsWe should move all of this to a typeahead. You can either copy the PhabricatorProjectDatasource, or (probably more cleanly) do something like: $datasource = id(new PhabricatorProjectDatasource()) ->setParameters(array('mustHaveColumns' => true)); Then, in the datasource, use getParameter() to choose whether the results are filtered down to just projects with columns or not. epriestley: We should move all of this to a typeahead. You can either copy the… |
Maybe HTTP 400, but this is pretty nitpicky.