Path: blob/master/src/applications/files/controller/PhabricatorFileDetachController.php
12242 views
<?php12final class PhabricatorFileDetachController3extends PhabricatorFileController {45public function handleRequest(AphrontRequest $request) {6$viewer = $request->getViewer();78$object_phid = $request->getURIData('objectPHID');9$file_phid = $request->getURIData('filePHID');1011$object = id(new PhabricatorObjectQuery())12->setViewer($viewer)13->withPHIDs(array($object_phid))14->executeOne();15if (!$object) {16return new Aphront404Response();17}1819$handles = $viewer->loadHandles(20array(21$object_phid,22$file_phid,23));2425$object_handle = $handles[$object_phid];26$file_handle = $handles[$file_phid];27$cancel_uri = $file_handle->getURI();2829$dialog = $this->newDialog()30->setViewer($viewer)31->setTitle(pht('Detach File'))32->addCancelButton($cancel_uri, pht('Close'));3334$file_link = phutil_tag('strong', array(), $file_handle->renderLink());35$object_link = phutil_tag('strong', array(), $object_handle->renderLink());3637$attachment = id(new PhabricatorFileAttachmentQuery())38->setViewer($viewer)39->withObjectPHIDs(array($object->getPHID()))40->withFilePHIDs(array($file_phid))41->needFiles(true)42->withVisibleFiles(true)43->executeOne();44if (!$attachment) {45$body = pht(46'The file %s is not attached to the object %s.',47$file_link,48$object_link);4950return $dialog->appendParagraph($body);51}5253$mode_reference = PhabricatorFileAttachment::MODE_REFERENCE;54if ($attachment->getAttachmentMode() === $mode_reference) {55$body = pht(56'The file %s is referenced by the object %s, but not attached to '.57'it, so it can not be detached.',58$file_link,59$object_link);6061return $dialog->appendParagraph($body);62}6364if (!$attachment->canDetach()) {65$body = pht(66'The file %s can not be detached from the object %s.',67$file_link,68$object_link);6970return $dialog->appendParagraph($body);71}7273if (!$request->isDialogFormPost()) {74$dialog->appendParagraph(75pht(76'Detach the file %s from the object %s?',77$file_link,78$object_link));7980$dialog->addSubmitButton(pht('Detach File'));8182return $dialog;83}8485if (!($object instanceof PhabricatorApplicationTransactionInterface)) {86$dialog->appendParagraph(87pht(88'This object (of class "%s") does not implement the required '.89'interface ("%s"), so files can not be manually detached from it.',90get_class($object),91'PhabricatorApplicationTransactionInterface'));9293return $dialog;94}9596$editor = $object->getApplicationTransactionEditor()97->setActor($viewer)98->setContentSourceFromRequest($request)99->setContinueOnNoEffect(true)100->setContinueOnMissingFields(true);101102$template = $object->getApplicationTransactionTemplate();103104$xactions = array();105106$xactions[] = id(clone $template)107->setTransactionType(PhabricatorTransactions::TYPE_FILE)108->setNewValue(109array(110$file_phid => PhabricatorFileAttachment::MODE_DETACH,111));112113$editor->applyTransactions($object, $xactions);114115return $this->newRedirect()116->setURI($cancel_uri);117}118119}120121122