Changeset View
Changeset View
Standalone View
Standalone View
src/applications/nuance/controller/NuanceItemActionController.php
| Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | public function handleRequest(AphrontRequest $request) { | ||||
| } | } | ||||
| $action = $request->getURIData('action'); | $action = $request->getURIData('action'); | ||||
| $impl = $item->getImplementation(); | $impl = $item->getImplementation(); | ||||
| $impl->setViewer($viewer); | $impl->setViewer($viewer); | ||||
| $impl->setController($this); | $impl->setController($this); | ||||
| $executors = NuanceCommandImplementation::getAllCommands(); | |||||
| $executor = idx($executors, $action); | |||||
| if (!$executor) { | |||||
| return new Aphront404Response(); | |||||
| } | |||||
| $executor = id(clone $executor) | |||||
| ->setActor($viewer); | |||||
| if (!$executor->canApplyToItem($item)) { | |||||
| return $this->newDialog() | |||||
| ->setTitle(pht('Command Not Supported')) | |||||
| ->appendParagraph( | |||||
| pht( | |||||
| 'This item does not support the specified command ("%s").', | |||||
| $action)) | |||||
| ->addCancelButton($cancel_uri); | |||||
| } | |||||
| $command = NuanceItemCommand::initializeNewCommand() | $command = NuanceItemCommand::initializeNewCommand() | ||||
| ->setItemPHID($item->getPHID()) | ->setItemPHID($item->getPHID()) | ||||
| ->setAuthorPHID($viewer->getPHID()) | ->setAuthorPHID($viewer->getPHID()) | ||||
| ->setCommand($action); | ->setCommand($action); | ||||
| if ($queue) { | if ($queue) { | ||||
| $command->setQueuePHID($queue->getPHID()); | $command->setQueuePHID($queue->getPHID()); | ||||
| } | } | ||||
| $command->save(); | $command->save(); | ||||
| // TODO: Here, we should check if the command should be tried immediately, | // If this command can be applied immediately, try to apply it now. | ||||
| // and just defer it to the daemons if not. If we're going to try to apply | |||||
| // the command directly, we should first acquire the worker lock. If we | // In most cases, local commands (like closing an item) can be applied | ||||
| // can not, we should defer the command even if it's an immediate command. | // immediately. | ||||
| // For the moment, skip all this stuff by deferring unconditionally. | |||||
| $should_defer = true; | // Commands that require making a call to a remote system (for example, | ||||
| if ($should_defer) { | // to reply to a tweet or close a remote object) are usually done in the | ||||
| // background so the user doesn't have to wait for the operation to | |||||
| // complete before they can continue work. | |||||
| $did_apply = false; | |||||
| $immediate = $executor->canApplyImmediately($item, $command); | |||||
| if ($immediate) { | |||||
| // TODO: Move this stuff to a new Engine, and have the controller and | |||||
| // worker both call into the Engine. | |||||
| $worker = new NuanceItemUpdateWorker(array()); | |||||
| $did_apply = $worker->executeCommands($item, array($command)); | |||||
| } | |||||
| // If this can't be applied immediately or we were unable to get a lock | |||||
| // fast enough, do the update in the background instead. | |||||
| if (!$did_apply) { | |||||
| $item->scheduleUpdate(); | $item->scheduleUpdate(); | ||||
| } else { | |||||
| // ... | |||||
| } | } | ||||
| if ($queue) { | if ($queue) { | ||||
| $done_uri = $queue->getWorkURI(); | $done_uri = $queue->getWorkURI(); | ||||
| } else { | } else { | ||||
| $done_uri = $item->getURI(); | $done_uri = $item->getURI(); | ||||
| } | } | ||||
| return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
| ->setURI($done_uri); | ->setURI($done_uri); | ||||
| } | } | ||||
| } | } | ||||