Permalink
Browse files

If background command is not available, simply rerun the Request obje…

…ct with correct parameters & attributes.
  • Loading branch information...
1 parent 8900824 commit fb1f8af1db8aba088d46359995918500f3c682e7 @cdujeu cdujeu committed May 23, 2016
@@ -691,14 +691,14 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
case "compress" :
+ $taskId = $request->getAttribute("pydio-task-id");
if($request->getAttribute("pydio-task-id") === null){
$task = TaskService::actionAsTask($action, $httpVars);
$task->setFlags(Task::FLAG_STOPPABLE);
- TaskService::getInstance()->enqueueTask($task);
+ TaskService::getInstance()->enqueueTask($task, $request, $response);
return;
}
- $taskId = $request->getAttribute("pydio-task-id");
if($taskId !== null){
TaskService::getInstance()->updateTaskStatus($taskId, Task::STATUS_RUNNING, "Starting compression in background");
}
@@ -829,7 +829,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
if($taskId === null && (!$selection->isUnique() || !is_file($selection->getUniqueNode()->getUrl()))){
$task = TaskService::actionAsTask($action, $httpVars);
$task->setFlags(Task::FLAG_STOPPABLE);
- TaskService::getInstance()->enqueueTask($task);
+ TaskService::getInstance()->enqueueTask($task, $request, $response);
return;
}
if(!empty($taskId)){
@@ -140,11 +140,11 @@ public function uploadActions(ServerRequestInterface &$request, ResponseInterfac
$x = new SerializableResponseStream();
$response = $response->withBody($x);
if ($nextFile!='') {
- $x->addChunk(new BgActionTrigger("next_to_remote", array(), "Copying file ".TextEncoder::toUTF8($nextFile)." to remote server"));
+ //$x->addChunk(new BgActionTrigger("next_to_remote", array(), "Copying file ".TextEncoder::toUTF8($nextFile)." to remote server"));
$newTask = TaskService::actionAsTask("next_to_remote", []);
- TaskService::getInstance()->enqueueTask($newTask);
+ TaskService::getInstance()->enqueueTask($newTask, $request, $response);
} else {
- $x->addChunk(new BgActionTrigger("reload_node", array(), "Upload done, reloading client."));
+ //$x->addChunk(new BgActionTrigger("reload_node", array(), "Upload done, reloading client."));
TaskService::getInstance()->updateTaskStatus($taskId, Task::STATUS_COMPLETE, "");
}
break;
@@ -241,7 +241,7 @@ public function uploadActions(ServerRequestInterface &$request, ResponseInterfac
$this->writeUploadSuccess($request, ["PREVENT_NOTIF" => true]);
$task = TaskService::actionAsTask("next_to_remote", []);
- TaskService::getInstance()->enqueueTask($task);
+ TaskService::getInstance()->enqueueTask($task, $request, $response);
} catch (\Exception $e) {
$errorCode = $e->getCode();
@@ -103,7 +103,7 @@ public function receiveAction(\Psr\Http\Message\ServerRequestInterface &$request
$task = TaskService::actionAsTask("compression", $httpVars, $repository->getId(), "", [], Task::FLAG_STOPPABLE | Task::FLAG_HAS_PROGRESS);
$task->setLabel($messages["compression.5"]);
file_put_contents($progressCompressionFileName, $messages["compression.5"]);
- TaskService::getInstance()->enqueueTask($task);
+ TaskService::getInstance()->enqueueTask($task, $requestInterface, $responseInterface);
return;
}
@@ -262,7 +262,7 @@ public function receiveAction(\Psr\Http\Message\ServerRequestInterface &$request
$task = TaskService::actionAsTask("extraction", $httpVars, $repository->getId(), "", [], Task::FLAG_STOPPABLE | Task::FLAG_HAS_PROGRESS);
$task->setLabel($messages["compression.12"]);
file_put_contents($progressExtractFileName, $messages["compression.12"]);
- TaskService::getInstance()->enqueueTask($task);
+ TaskService::getInstance()->enqueueTask($task, $requestInterface, $responseInterface);
return;
}
$task = TaskService::getInstance()->getTaskById($taskId);
@@ -95,7 +95,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
if($taskId === null){
$task = TaskService::actionAsTask($request->getAttribute("action"), $httpVars);
$task->setFlags(Task::FLAG_STOPPABLE | Task::FLAG_HAS_PROGRESS);
- TaskService::getInstance()->enqueueTask($task);
+ TaskService::getInstance()->enqueueTask($task, $request, $response);
return;
}
@@ -130,7 +130,7 @@ public function crossRepositoryCopy(ServerRequestInterface &$requestInterface, R
$taskId = $requestInterface->getAttribute("pydio-task-id");
if(empty($taskId)){
$task = TaskService::actionAsTask("cross_copy", $httpVars);
- TaskService::getInstance()->enqueueTask($task);
+ TaskService::getInstance()->enqueueTask($task, $requestInterface, $responseInterface);
return;
}
@@ -67,7 +67,7 @@ public function applyAction(\Psr\Http\Message\ServerRequestInterface $requestInt
if (ConfService::backgroundActionsSupported() && !ConfService::currentContextIsCommandLine()) {
$task = TaskService::actionAsTask("index", $httpVars, "", "", [$nodes[0]->getUrl()], Task::FLAG_STOPPABLE | Task::FLAG_RESUMABLE);
- TaskService::getInstance()->enqueueTask($task);
+ TaskService::getInstance()->enqueueTask($task, $requestInterface, $responseInterface);
$responseInterface = new \Zend\Diactoros\Response\EmptyResponse();
return null;
}
@@ -20,6 +20,8 @@
*/
namespace Pydio\Tasks;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Model\NodesDiff;
use Pydio\Access\Core\Model\Repository;
@@ -59,12 +61,18 @@ public static function getInstance(){
}
- public function enqueueTask(Task $task){
+ public function enqueueTask(Task $task, ServerRequestInterface $request, ResponseInterface &$response){
if(ConfService::backgroundActionsSupported()){
Controller::applyTaskInBackground($task);
}else{
- // TODO: Should Run now?
- // $task->run();
+ $params = $task->getParameters();
+ $action = $task->getAction();
+ $id = $task->getId();
+ $request = $request
+ ->withAttribute("action", $action)
+ ->withAttribute("pydio-task-id", $id)
+ ->withParsedBody($params);
+ Controller::run($request);
}
}
@@ -75,7 +75,7 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $request,
$taskId = $request->getAttribute("pydio-task-id");
if(empty($taskId)){
$task = TaskService::actionAsTask("external_download", $httpVars, "", "", [], Task::FLAG_HAS_PROGRESS | Task::FLAG_STOPPABLE);
- TaskService::getInstance()->enqueueTask($task);
+ TaskService::getInstance()->enqueueTask($task, $request, $response);
break;
}
/*

0 comments on commit fb1f8af

Please sign in to comment.