|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * Copyright 2012 Facebook, Inc. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +/** |
| 20 | + * @group conduit |
| 21 | + */ |
| 22 | +final class ConduitAPI_differential_close_Method |
| 23 | + extends ConduitAPIMethod { |
| 24 | + |
| 25 | + public function getMethodDescription() { |
| 26 | + return "Close a Differential revision."; |
| 27 | + } |
| 28 | + |
| 29 | + public function defineParamTypes() { |
| 30 | + return array( |
| 31 | + 'revisionID' => 'required int', |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | + public function defineReturnType() { |
| 36 | + return 'void'; |
| 37 | + } |
| 38 | + |
| 39 | + public function defineErrorTypes() { |
| 40 | + return array( |
| 41 | + 'ERR_NOT_FOUND' => 'Revision was not found.', |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + protected function execute(ConduitAPIRequest $request) { |
| 46 | + $id = $request->getValue('revisionID'); |
| 47 | + |
| 48 | + $revision = id(new DifferentialRevision())->load($id); |
| 49 | + if (!$revision) { |
| 50 | + throw new ConduitException('ERR_NOT_FOUND'); |
| 51 | + } |
| 52 | + |
| 53 | + if ($revision->getStatus() == ArcanistDifferentialRevisionStatus::CLOSED) { |
| 54 | + // This can occur if someone runs 'close-revision' and hits a race, or |
| 55 | + // they have a remote hook installed but don't have the |
| 56 | + // 'remote_hook_installed' flag set, or similar. In any case, just treat |
| 57 | + // it as a no-op rather than adding another "X closed this revision" |
| 58 | + // message to the revision comments. |
| 59 | + return; |
| 60 | + } |
| 61 | + |
| 62 | + $revision->loadRelationships(); |
| 63 | + |
| 64 | + $editor = new DifferentialCommentEditor( |
| 65 | + $revision, |
| 66 | + $request->getUser()->getPHID(), |
| 67 | + DifferentialAction::ACTION_CLOSE); |
| 68 | + $editor->save(); |
| 69 | + |
| 70 | + $revision->setStatus(ArcanistDifferentialRevisionStatus::CLOSED); |
| 71 | + $revision->setDateCommitted(time()); |
| 72 | + $revision->save(); |
| 73 | + |
| 74 | + return; |
| 75 | + } |
| 76 | + |
| 77 | +} |
0 commit comments