mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-13 18:32:41 +01:00
6dda35897a
Summary: I introduced this helper at some point, clean up all the code duplication around content sources. Test Plan: Grepped; hit edit interfaces for most/all of these. Reviewers: btrahan, chad, edward Reviewed By: chad CC: aran Differential Revision: https://secure.phabricator.com/D6030
59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
|
|
final class PhabricatorMacroDisableController
|
|
extends PhabricatorMacroController {
|
|
|
|
private $id;
|
|
|
|
public function willProcessRequest(array $data) {
|
|
$this->id = $data['id'];
|
|
}
|
|
|
|
public function processRequest() {
|
|
$request = $this->getRequest();
|
|
$user = $request->getUser();
|
|
|
|
$macro = id(new PhabricatorMacroQuery())
|
|
->setViewer($user)
|
|
->requireCapabilities(
|
|
array(
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
))
|
|
->withIDs(array($this->id))
|
|
->executeOne();
|
|
if (!$macro) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$view_uri = $this->getApplicationURI('/view/'.$this->id.'/');
|
|
|
|
if ($request->isDialogFormPost() || $macro->getIsDisabled()) {
|
|
$xaction = id(new PhabricatorMacroTransaction())
|
|
->setTransactionType(PhabricatorMacroTransactionType::TYPE_DISABLED)
|
|
->setNewValue($macro->getIsDisabled() ? 0 : 1);
|
|
|
|
$editor = id(new PhabricatorMacroEditor())
|
|
->setActor($user)
|
|
->setContentSourceFromRequest($request);
|
|
|
|
$xactions = $editor->applyTransactions($macro, array($xaction));
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($view_uri);
|
|
}
|
|
|
|
$dialog = new AphrontDialogView();
|
|
$dialog
|
|
->setUser($request->getUser())
|
|
->setTitle(pht('Really disable macro?'))
|
|
->appendChild(phutil_tag('p', array(), pht(
|
|
'Really disable the much-beloved image macro %s? '.
|
|
'It will be sorely missed.',
|
|
$macro->getName())))
|
|
->setSubmitURI($this->getApplicationURI('/disable/'.$this->id.'/'))
|
|
->addSubmitButton(pht('Disable'))
|
|
->addCancelButton($view_uri);
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
}
|
|
}
|