@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at upstream/main 121 lines 3.6 kB view raw
1<?php 2 3final class NuanceItemActionController extends NuanceController { 4 5 public function handleRequest(AphrontRequest $request) { 6 $viewer = $this->getViewer(); 7 $id = $request->getURIData('id'); 8 9 if (!$request->validateCSRF()) { 10 return new Aphront400Response(); 11 } 12 13 // NOTE: This controller can be reached from an individual item (usually 14 // by a user) or while working through a queue (usually by staff). When 15 // a command originates from a queue, the URI will have a queue ID. 16 17 $item = id(new NuanceItemQuery()) 18 ->setViewer($viewer) 19 ->withIDs(array($id)) 20 ->executeOne(); 21 if (!$item) { 22 return new Aphront404Response(); 23 } 24 25 $cancel_uri = $item->getURI(); 26 27 $queue_id = $request->getURIData('queueID'); 28 $queue = null; 29 if ($queue_id) { 30 $queue = id(new NuanceQueueQuery()) 31 ->setViewer($viewer) 32 ->withIDs(array($queue_id)) 33 ->executeOne(); 34 if (!$queue) { 35 return new Aphront404Response(); 36 } 37 38 $item_queue = $item->getQueue(); 39 if (!$item_queue || ($item_queue->getPHID() != $queue->getPHID())) { 40 return $this->newDialog() 41 ->setTitle(pht('Wrong Queue')) 42 ->appendParagraph( 43 pht( 44 'You are trying to act on this item from the wrong queue: it '. 45 'is currently in a different queue.')) 46 ->addCancelButton($cancel_uri); 47 } 48 } 49 50 $action = $request->getURIData('action'); 51 52 $impl = $item->getImplementation(); 53 $impl->setViewer($viewer); 54 $impl->setController($this); 55 56 $executors = NuanceCommandImplementation::getAllCommands(); 57 $executor = idx($executors, $action); 58 if (!$executor) { 59 return new Aphront404Response(); 60 } 61 62 $executor = id(clone $executor) 63 ->setActor($viewer); 64 65 if (!$executor->canApplyToItem($item)) { 66 return $this->newDialog() 67 ->setTitle(pht('Command Not Supported')) 68 ->appendParagraph( 69 pht( 70 'This item does not support the specified command ("%s").', 71 $action)) 72 ->addCancelButton($cancel_uri); 73 } 74 75 $command = NuanceItemCommand::initializeNewCommand() 76 ->setItemPHID($item->getPHID()) 77 ->setAuthorPHID($viewer->getPHID()) 78 ->setCommand($action); 79 80 if ($queue) { 81 $command->setQueuePHID($queue->getPHID()); 82 } 83 84 $command->save(); 85 86 // If this command can be applied immediately, try to apply it now. 87 88 // In most cases, local commands (like closing an item) can be applied 89 // immediately. 90 91 // Commands that require making a call to a remote system (for example, 92 // to reply to a tweet or close a remote object) are usually done in the 93 // background so the user doesn't have to wait for the operation to 94 // complete before they can continue work. 95 96 $did_apply = false; 97 $immediate = $executor->canApplyImmediately($item, $command); 98 if ($immediate) { 99 // TODO: Move this stuff to a new Engine, and have the controller and 100 // worker both call into the Engine. 101 $worker = new NuanceItemUpdateWorker(array()); 102 $did_apply = $worker->executeCommands($item, array($command)); 103 } 104 105 // If this can't be applied immediately or we were unable to get a lock 106 // fast enough, do the update in the background instead. 107 if (!$did_apply) { 108 $item->scheduleUpdate(); 109 } 110 111 if ($queue) { 112 $done_uri = $queue->getWorkURI(); 113 } else { 114 $done_uri = $item->getURI(); 115 } 116 117 return id(new AphrontRedirectResponse()) 118 ->setURI($done_uri); 119 } 120 121}