2011-06-13 01:06:17 +02:00
|
|
|
<?php
|
|
|
|
|
2013-05-23 15:47:54 +02:00
|
|
|
/**
|
|
|
|
* @group countdown
|
|
|
|
*/
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorCountdownDeleteController
|
2011-06-13 01:06:17 +02:00
|
|
|
extends PhabricatorCountdownController {
|
|
|
|
|
2012-10-04 23:33:50 +02:00
|
|
|
private $id;
|
|
|
|
|
2011-06-13 01:06:17 +02:00
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2013-05-23 15:47:54 +02:00
|
|
|
$countdown = id(new CountdownQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
if (!$countdown) {
|
2011-06-13 01:06:17 +02:00
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2013-05-23 15:47:54 +02:00
|
|
|
if (($countdown->getAuthorPHID() !== $user->getPHID())
|
2011-06-13 01:06:17 +02:00
|
|
|
&& $user->getIsAdmin() === false) {
|
2012-01-15 10:07:56 +01:00
|
|
|
return new Aphront403Response();
|
2011-06-13 01:06:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
2013-05-23 15:47:54 +02:00
|
|
|
$countdown->delete();
|
2011-06-13 01:06:17 +02:00
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI('/countdown/');
|
|
|
|
}
|
|
|
|
|
2013-02-25 21:48:55 +01:00
|
|
|
$inst = pht('Are you sure you want to delete the countdown %s?',
|
2013-05-23 15:47:54 +02:00
|
|
|
$countdown->getTitle());
|
2013-02-25 21:48:55 +01:00
|
|
|
|
2011-06-13 01:06:17 +02:00
|
|
|
$dialog = new AphrontDialogView();
|
|
|
|
$dialog->setUser($request->getUser());
|
2013-02-25 21:48:55 +01:00
|
|
|
$dialog->setTitle(pht('Really delete this countdown?'));
|
|
|
|
$dialog->appendChild(hsprintf('<p>%s</p>', $inst));
|
|
|
|
$dialog->addSubmitButton(pht('Delete'));
|
2011-06-13 01:06:17 +02:00
|
|
|
$dialog->addCancelButton('/countdown/');
|
|
|
|
$dialog->setSubmitURI($request->getPath());
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|