3 final class PhabricatorFileDetachController
4 extends PhabricatorFileController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $viewer = $request->getViewer();
9 $object_phid = $request->getURIData('objectPHID');
10 $file_phid = $request->getURIData('filePHID');
12 $object = id(new PhabricatorObjectQuery())
14 ->withPHIDs(array($object_phid))
17 return new Aphront404Response();
20 $handles = $viewer->loadHandles(
26 $object_handle = $handles[$object_phid];
27 $file_handle = $handles[$file_phid];
28 $cancel_uri = $file_handle->getURI();
30 $dialog = $this->newDialog()
32 ->setTitle(pht('Detach File'))
33 ->addCancelButton($cancel_uri, pht('Close'));
35 $file_link = phutil_tag('strong', array(), $file_handle->renderLink());
36 $object_link = phutil_tag('strong', array(), $object_handle->renderLink());
38 $attachment = id(new PhabricatorFileAttachmentQuery())
40 ->withObjectPHIDs(array($object->getPHID()))
41 ->withFilePHIDs(array($file_phid))
43 ->withVisibleFiles(true)
47 'The file %s is not attached to the object %s.',
51 return $dialog->appendParagraph($body);
54 $mode_reference = PhabricatorFileAttachment
::MODE_REFERENCE
;
55 if ($attachment->getAttachmentMode() === $mode_reference) {
57 'The file %s is referenced by the object %s, but not attached to '.
58 'it, so it can not be detached.',
62 return $dialog->appendParagraph($body);
65 if (!$attachment->canDetach()) {
67 'The file %s can not be detached from the object %s.',
71 return $dialog->appendParagraph($body);
74 if (!$request->isDialogFormPost()) {
75 $dialog->appendParagraph(
77 'Detach the file %s from the object %s?',
81 $dialog->addSubmitButton(pht('Detach File'));
86 if (!($object instanceof PhabricatorApplicationTransactionInterface
)) {
87 $dialog->appendParagraph(
89 'This object (of class "%s") does not implement the required '.
90 'interface ("%s"), so files can not be manually detached from it.',
92 'PhabricatorApplicationTransactionInterface'));
97 $editor = $object->getApplicationTransactionEditor()
99 ->setContentSourceFromRequest($request)
100 ->setContinueOnNoEffect(true)
101 ->setContinueOnMissingFields(true);
103 $template = $object->getApplicationTransactionTemplate();
107 $xactions[] = id(clone $template)
108 ->setTransactionType(PhabricatorTransactions
::TYPE_FILE
)
111 $file_phid => PhabricatorFileAttachment
::MODE_DETACH
,
114 $editor->applyTransactions($object, $xactions);
116 return $this->newRedirect()
117 ->setURI($cancel_uri);