2012-12-15 00:42:58 +01:00
|
|
|
<?php
|
|
|
|
|
2013-12-26 21:30:36 +01:00
|
|
|
final class DrydockLeaseReleaseController extends DrydockLeaseController {
|
2012-12-15 00:42:58 +01:00
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2013-12-26 19:41:36 +01:00
|
|
|
$lease = id(new DrydockLeaseQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->executeOne();
|
2012-12-15 00:42:58 +01:00
|
|
|
if (!$lease) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$lease_uri = '/lease/'.$lease->getID().'/';
|
|
|
|
$lease_uri = $this->getApplicationURI($lease_uri);
|
|
|
|
|
|
|
|
if ($lease->getStatus() != DrydockLeaseStatus::STATUS_ACTIVE) {
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($user)
|
|
|
|
->setTitle(pht('Lease Not Active'))
|
2013-02-13 23:50:15 +01:00
|
|
|
->appendChild(phutil_tag('p', array(), pht(
|
|
|
|
'You can only release "active" leases.')))
|
2012-12-15 00:42:58 +01:00
|
|
|
->addCancelButton($lease_uri);
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$request->isDialogFormPost()) {
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($user)
|
|
|
|
->setTitle(pht('Really release lease?'))
|
2013-02-13 23:50:15 +01:00
|
|
|
->appendChild(phutil_tag('p', array(), pht(
|
|
|
|
'Releasing a lease may cause trouble for the lease holder and '.
|
|
|
|
'trigger cleanup of the underlying resource. It can not be '.
|
|
|
|
'undone. Continue?')))
|
2012-12-15 00:42:58 +01:00
|
|
|
->addSubmitButton(pht('Release Lease'))
|
|
|
|
->addCancelButton($lease_uri);
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
2013-12-26 19:41:36 +01:00
|
|
|
$resource = $lease->getResource();
|
2012-12-15 00:42:58 +01:00
|
|
|
$blueprint = $resource->getBlueprint();
|
|
|
|
$blueprint->releaseLease($resource, $lease);
|
|
|
|
|
|
|
|
return id(new AphrontReloadResponse())->setURI($lease_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|