Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/paste/controller/PhabricatorPasteArchiveController.php
12242 views
1
<?php
2
3
final class PhabricatorPasteArchiveController
4
extends PhabricatorPasteController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $request->getViewer();
8
$id = $request->getURIData('id');
9
10
$paste = id(new PhabricatorPasteQuery())
11
->setViewer($viewer)
12
->withIDs(array($id))
13
->requireCapabilities(
14
array(
15
PhabricatorPolicyCapability::CAN_VIEW,
16
PhabricatorPolicyCapability::CAN_EDIT,
17
))
18
->executeOne();
19
if (!$paste) {
20
return new Aphront404Response();
21
}
22
23
$view_uri = $paste->getURI();
24
25
if ($request->isFormPost()) {
26
if ($paste->isArchived()) {
27
$new_status = PhabricatorPaste::STATUS_ACTIVE;
28
} else {
29
$new_status = PhabricatorPaste::STATUS_ARCHIVED;
30
}
31
32
$xactions = array();
33
34
$xactions[] = id(new PhabricatorPasteTransaction())
35
->setTransactionType(PhabricatorPasteStatusTransaction::TRANSACTIONTYPE)
36
->setNewValue($new_status);
37
38
id(new PhabricatorPasteEditor())
39
->setActor($viewer)
40
->setContentSourceFromRequest($request)
41
->setContinueOnNoEffect(true)
42
->setContinueOnMissingFields(true)
43
->applyTransactions($paste, $xactions);
44
45
return id(new AphrontRedirectResponse())->setURI($view_uri);
46
}
47
48
if ($paste->isArchived()) {
49
$title = pht('Activate Paste');
50
$body = pht('This paste will become consumable again.');
51
$button = pht('Activate Paste');
52
} else {
53
$title = pht('Archive Paste');
54
$body = pht('This paste will be marked as expired.');
55
$button = pht('Archive Paste');
56
}
57
58
return $this->newDialog()
59
->setTitle($title)
60
->appendChild($body)
61
->addCancelButton($view_uri)
62
->addSubmitButton($button);
63
}
64
65
}
66
67