diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index a47a427344..4697562d45 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1905,6 +1905,7 @@ phutil_register_library_map(array( 'ReleephPHIDConstants' => 'applications/releeph/ReleephPHIDConstants.php', 'ReleephProject' => 'applications/releeph/storage/ReleephProject.php', 'ReleephProjectActionController' => 'applications/releeph/controller/project/ReleephProjectActionController.php', + 'ReleephProjectController' => 'applications/releeph/controller/ReleephProjectController.php', 'ReleephProjectCreateController' => 'applications/releeph/controller/project/ReleephProjectCreateController.php', 'ReleephProjectEditController' => 'applications/releeph/controller/project/ReleephProjectEditController.php', 'ReleephProjectListController' => 'applications/releeph/controller/project/ReleephProjectListController.php', @@ -3913,15 +3914,15 @@ phutil_register_library_map(array( 'ReleephActiveProjectListView' => 'AphrontView', 'ReleephAuthorFieldSpecification' => 'ReleephFieldSpecification', 'ReleephBranch' => 'ReleephDAO', - 'ReleephBranchAccessController' => 'ReleephController', + 'ReleephBranchAccessController' => 'ReleephProjectController', 'ReleephBranchBoxView' => 'AphrontView', 'ReleephBranchCommitFieldSpecification' => 'ReleephFieldSpecification', - 'ReleephBranchCreateController' => 'ReleephController', - 'ReleephBranchEditController' => 'ReleephController', + 'ReleephBranchCreateController' => 'ReleephProjectController', + 'ReleephBranchEditController' => 'ReleephProjectController', 'ReleephBranchEditor' => 'PhabricatorEditor', 'ReleephBranchNamePreviewController' => 'PhabricatorController', 'ReleephBranchPreviewView' => 'AphrontFormControl', - 'ReleephBranchViewController' => 'ReleephController', + 'ReleephBranchViewController' => 'ReleephProjectController', 'ReleephCommitFinderException' => 'Exception', 'ReleephCommitMessageFieldSpecification' => 'ReleephFieldSpecification', 'ReleephController' => 'PhabricatorController', @@ -3945,23 +3946,24 @@ phutil_register_library_map(array( 0 => 'ReleephDAO', 1 => 'PhabricatorPolicyInterface', ), - 'ReleephProjectActionController' => 'ReleephController', - 'ReleephProjectCreateController' => 'ReleephController', - 'ReleephProjectEditController' => 'ReleephController', + 'ReleephProjectActionController' => 'ReleephProjectController', + 'ReleephProjectController' => 'ReleephController', + 'ReleephProjectCreateController' => 'ReleephProjectController', + 'ReleephProjectEditController' => 'ReleephProjectController', 'ReleephProjectListController' => 'PhabricatorController', 'ReleephProjectQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'ReleephProjectView' => 'AphrontView', - 'ReleephProjectViewController' => 'ReleephController', + 'ReleephProjectViewController' => 'ReleephProjectController', 'ReleephReasonFieldSpecification' => 'ReleephFieldSpecification', 'ReleephRequest' => array( 0 => 'ReleephDAO', 1 => 'PhabricatorPolicyInterface', ), - 'ReleephRequestActionController' => 'ReleephController', - 'ReleephRequestCommentController' => 'ReleephController', - 'ReleephRequestDifferentialCreateController' => 'ReleephController', - 'ReleephRequestEditController' => 'ReleephController', + 'ReleephRequestActionController' => 'ReleephProjectController', + 'ReleephRequestCommentController' => 'ReleephProjectController', + 'ReleephRequestDifferentialCreateController' => 'ReleephProjectController', + 'ReleephRequestEditController' => 'ReleephProjectController', 'ReleephRequestEvent' => 'ReleephDAO', 'ReleephRequestException' => 'Exception', 'ReleephRequestHeaderListView' => 'AphrontView', @@ -3977,7 +3979,7 @@ phutil_register_library_map(array( 'ReleephRequestTransactionalEditor' => 'PhabricatorApplicationTransactionEditor', 'ReleephRequestTypeaheadControl' => 'AphrontFormControl', 'ReleephRequestTypeaheadController' => 'PhabricatorTypeaheadDatasourceController', - 'ReleephRequestViewController' => 'ReleephController', + 'ReleephRequestViewController' => 'ReleephProjectController', 'ReleephRequestorFieldSpecification' => 'ReleephFieldSpecification', 'ReleephRevisionFieldSpecification' => 'ReleephFieldSpecification', 'ReleephRiskFieldSpecification' => 'ReleephFieldSpecification', diff --git a/src/applications/releeph/controller/ReleephController.php b/src/applications/releeph/controller/ReleephController.php index 2cddd83def..66037e92bb 100644 --- a/src/applications/releeph/controller/ReleephController.php +++ b/src/applications/releeph/controller/ReleephController.php @@ -2,110 +2,6 @@ abstract class ReleephController extends PhabricatorController { - private $releephProject; - private $releephBranch; - private $releephRequest; - - /** - * ReleephController will take care of loading any Releeph* objects - * referenced in the URL. - */ - public function willProcessRequest(array $data) { - // Project - $project = null; - $project_id = idx($data, 'projectID'); - $project_name = idx($data, 'projectName'); - if ($project_id) { - $project = id(new ReleephProject())->load($project_id); - if (!$project) { - throw new Exception( - "ReleephProject with id '{$project_id}' not found!"); - } - } elseif ($project_name) { - $project = id(new ReleephProject()) - ->loadOneWhere('name = %s', $project_name); - if (!$project) { - throw new Exception( - "ReleephProject with name '{$project_name}' not found!"); - } - } - - // Branch - $branch = null; - $branch_id = idx($data, 'branchID'); - $branch_name = idx($data, 'branchName'); - if ($branch_id) { - $branch = id(new ReleephBranch())->load($branch_id); - if (!$branch) { - throw new Exception("Branch with id '{$branch_id}' not found!"); - } - } elseif ($branch_name) { - if (!$project) { - throw new Exception( - "You cannot refer to a branch by name without also referring ". - "to a ReleephProject (branch names are only unique in projects)."); - } - $branch = id(new ReleephBranch())->loadOneWhere( - 'basename = %s AND releephProjectID = %d', - $branch_name, - $project->getID()); - if (!$branch) { - throw new Exception( - "ReleephBranch with basename '{$branch_name}' not found ". - "in project '{$project->getName()}'!"); - } - } - - // Request - $request = null; - $request_id = idx($data, 'requestID'); - if ($request_id) { - $request = id(new ReleephRequest())->load($request_id); - if (!$request) { - throw new Exception( - "ReleephRequest with id '{$request_id}' not found!"); - } - } - - // Fill in the gaps - if ($request && !$branch) { - $branch = $request->loadReleephBranch(); - } - - if ($branch && !$project) { - $project = $branch->loadReleephProject(); - } - - // Set! - $this->releephProject = $project; - $this->releephBranch = $branch; - $this->releephRequest = $request; - } - - protected function getReleephProject() { - if (!$this->releephProject) { - throw new Exception( - 'This controller did not load a ReleephProject from the URL $data.'); - } - return $this->releephProject; - } - - protected function getReleephBranch() { - if (!$this->releephBranch) { - throw new Exception( - 'This controller did not load a ReleephBranch from the URL $data.'); - } - return $this->releephBranch; - } - - protected function getReleephRequest() { - if (!$this->releephRequest) { - throw new Exception( - 'This controller did not load a ReleephRequest from the URL $data.'); - } - return $this->releephRequest; - } - public function buildStandardPageResponse($view, array $data) { $page = $this->buildStandardPageView(); diff --git a/src/applications/releeph/controller/ReleephProjectController.php b/src/applications/releeph/controller/ReleephProjectController.php new file mode 100644 index 0000000000..5b93b04172 --- /dev/null +++ b/src/applications/releeph/controller/ReleephProjectController.php @@ -0,0 +1,109 @@ +load($project_id); + if (!$project) { + throw new Exception( + "ReleephProject with id '{$project_id}' not found!"); + } + } elseif ($project_name) { + $project = id(new ReleephProject()) + ->loadOneWhere('name = %s', $project_name); + if (!$project) { + throw new Exception( + "ReleephProject with name '{$project_name}' not found!"); + } + } + + // Branch + $branch = null; + $branch_id = idx($data, 'branchID'); + $branch_name = idx($data, 'branchName'); + if ($branch_id) { + $branch = id(new ReleephBranch())->load($branch_id); + if (!$branch) { + throw new Exception("Branch with id '{$branch_id}' not found!"); + } + } elseif ($branch_name) { + if (!$project) { + throw new Exception( + "You cannot refer to a branch by name without also referring ". + "to a ReleephProject (branch names are only unique in projects)."); + } + $branch = id(new ReleephBranch())->loadOneWhere( + 'basename = %s AND releephProjectID = %d', + $branch_name, + $project->getID()); + if (!$branch) { + throw new Exception( + "ReleephBranch with basename '{$branch_name}' not found ". + "in project '{$project->getName()}'!"); + } + } + + // Request + $request = null; + $request_id = idx($data, 'requestID'); + if ($request_id) { + $request = id(new ReleephRequest())->load($request_id); + if (!$request) { + throw new Exception( + "ReleephRequest with id '{$request_id}' not found!"); + } + } + + // Fill in the gaps + if ($request && !$branch) { + $branch = $request->loadReleephBranch(); + } + + if ($branch && !$project) { + $project = $branch->loadReleephProject(); + } + + // Set! + $this->releephProject = $project; + $this->releephBranch = $branch; + $this->releephRequest = $request; + } + + protected function getReleephProject() { + if (!$this->releephProject) { + throw new Exception( + 'This controller did not load a ReleephProject from the URL $data.'); + } + return $this->releephProject; + } + + protected function getReleephBranch() { + if (!$this->releephBranch) { + throw new Exception( + 'This controller did not load a ReleephBranch from the URL $data.'); + } + return $this->releephBranch; + } + + protected function getReleephRequest() { + if (!$this->releephRequest) { + throw new Exception( + 'This controller did not load a ReleephRequest from the URL $data.'); + } + return $this->releephRequest; + } + +} diff --git a/src/applications/releeph/controller/branch/ReleephBranchAccessController.php b/src/applications/releeph/controller/branch/ReleephBranchAccessController.php index 054af82d84..659fecc649 100644 --- a/src/applications/releeph/controller/branch/ReleephBranchAccessController.php +++ b/src/applications/releeph/controller/branch/ReleephBranchAccessController.php @@ -1,6 +1,6 @@ getReleephProject(); diff --git a/src/applications/releeph/controller/branch/ReleephBranchEditController.php b/src/applications/releeph/controller/branch/ReleephBranchEditController.php index 57cf246149..0d1439c498 100644 --- a/src/applications/releeph/controller/branch/ReleephBranchEditController.php +++ b/src/applications/releeph/controller/branch/ReleephBranchEditController.php @@ -1,6 +1,6 @@ getRequest(); diff --git a/src/applications/releeph/controller/branch/ReleephBranchNamePreviewController.php b/src/applications/releeph/controller/branch/ReleephBranchNamePreviewController.php index 5606542bfc..8d225ea6b8 100644 --- a/src/applications/releeph/controller/branch/ReleephBranchNamePreviewController.php +++ b/src/applications/releeph/controller/branch/ReleephBranchNamePreviewController.php @@ -1,7 +1,7 @@ getRequest(); diff --git a/src/applications/releeph/controller/branch/ReleephBranchViewController.php b/src/applications/releeph/controller/branch/ReleephBranchViewController.php index a48cd84643..449f79d006 100644 --- a/src/applications/releeph/controller/branch/ReleephBranchViewController.php +++ b/src/applications/releeph/controller/branch/ReleephBranchViewController.php @@ -1,6 +1,6 @@ getRequest(); diff --git a/src/applications/releeph/controller/project/ReleephProjectActionController.php b/src/applications/releeph/controller/project/ReleephProjectActionController.php index 55aea937b8..dfe20763f2 100644 --- a/src/applications/releeph/controller/project/ReleephProjectActionController.php +++ b/src/applications/releeph/controller/project/ReleephProjectActionController.php @@ -1,6 +1,6 @@ getRequest(); diff --git a/src/applications/releeph/controller/project/ReleephProjectEditController.php b/src/applications/releeph/controller/project/ReleephProjectEditController.php index 8acedc992e..efd07de47d 100644 --- a/src/applications/releeph/controller/project/ReleephProjectEditController.php +++ b/src/applications/releeph/controller/project/ReleephProjectEditController.php @@ -1,6 +1,6 @@ getRequest(); diff --git a/src/applications/releeph/controller/project/ReleephProjectListController.php b/src/applications/releeph/controller/project/ReleephProjectListController.php index 9f87e69fb9..53071e091a 100644 --- a/src/applications/releeph/controller/project/ReleephProjectListController.php +++ b/src/applications/releeph/controller/project/ReleephProjectListController.php @@ -1,6 +1,6 @@ getRequest(); diff --git a/src/applications/releeph/controller/request/ReleephRequestDifferentialCreateController.php b/src/applications/releeph/controller/request/ReleephRequestDifferentialCreateController.php index 63ba5a9cea..990dbb60e6 100644 --- a/src/applications/releeph/controller/request/ReleephRequestDifferentialCreateController.php +++ b/src/applications/releeph/controller/request/ReleephRequestDifferentialCreateController.php @@ -1,7 +1,7 @@ getRequest();