Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Set a correct message when enqueuing tasks in background.
Browse files Browse the repository at this point in the history
Remove legacy JS code for managing background tasks client-side.
  • Loading branch information
cdujeu committed Sep 26, 2016
1 parent 1c8dc98 commit 7310b06
Show file tree
Hide file tree
Showing 60 changed files with 147 additions and 430 deletions.
1 change: 0 additions & 1 deletion core/src/core/src/pydio/Core/Controller/CliRunner.php
Expand Up @@ -105,7 +105,6 @@ public static function applyActionInBackground(ContextInterface $ctx, $actionNam
$cmd .= " --$key=" . escapeshellarg($value);
}
}
error_log($cmd);
$envSet = false;
if ($ctx->getRepository()->getContextOption($ctx, "USE_SESSION_CREDENTIALS")) {
$envSet = MemorySafe::setEnv();
Expand Down
1 change: 0 additions & 1 deletion core/src/core/src/pydio/Core/Controller/Controller.php
Expand Up @@ -387,7 +387,6 @@ private static function handleRequest($callback, ServerRequestInterface &$reques
$request = $request->withParsedBody($httpVars);

if(!empty($result)){
error_log("Action has result " . $request->getAttribute("action").", wrapping in XML Doc");
$response->getBody()->write(XMLWriter::wrapDocument($result));
$response = $response->withHeader("Content-type", "text/xml; charset=UTF-8");
}
Expand Down
37 changes: 0 additions & 37 deletions core/src/core/src/pydio/Core/Controller/XMLWriter.php
Expand Up @@ -392,43 +392,6 @@ public static function requireAuth($print = true)
{
return XMLWriter::write("<require_auth/>", $print);
}
/**
* Triggers a background action client side
* @static
* @param $actionName
* @param $parameters
* @param $messageId
* @param bool $print
* @param int $delay
* @return string
*/
public static function triggerBgAction($actionName, $parameters, $messageId, $print=true, $delay = 0)
{
$messageId = StringHelper::xmlEntities($messageId);
$data = XMLWriter::write("<trigger_bg_action name=\"$actionName\" messageId=\"$messageId\" delay=\"$delay\">", $print);
foreach ($parameters as $paramName=>$paramValue) {
$paramValue = StringHelper::xmlEntities($paramValue);
$data .= XMLWriter::write("<param name=\"$paramName\" value=\"$paramValue\"/>", $print);
}
$data .= XMLWriter::write("</trigger_bg_action>", $print);
return $data;
}

/**
* Send directly JavaScript code to the client
* @param $jsCode
* @param $messageId
* @param bool $print
* @param int $delay
* @return string
*/
public static function triggerBgJSAction($jsCode, $messageId, $print=true, $delay = 0)
{
$data = XMLWriter::write("<trigger_bg_action name=\"javascript_instruction\" messageId=\"$messageId\" delay=\"$delay\">", $print);
$data .= XMLWriter::write("<clientCallback><![CDATA[".$jsCode."]]></clientCallback>", $print);
$data .= XMLWriter::write("</trigger_bg_action>", $print);
return $data;
}

/**
* List all bookmmarks as XML
Expand Down
Expand Up @@ -30,51 +30,29 @@
* An XML response triggering a background action in Pydio UI.
* @package Pydio\Core\Http\Message
*/
class BgActionTrigger implements XMLSerializableResponseChunk
class JsActionTrigger implements XMLSerializableResponseChunk
{
private $actionName;
private $parameters;
private $messageId;
private $delay;

private $javascriptCode;

/**
* @param string $actionName
* @param array $parameters
* @param string $messageId
* @param string $jsCode
* @param int $delay
*/
public function __construct($actionName, $parameters, $messageId, $delay = 0)
public function __construct($jsCode, $delay = 0)
{
$this->actionName = $actionName;
$this->parameters = $parameters;
$this->messageId = $messageId;
$this->javascriptCode = $jsCode;
$this->delay = $delay;
}

/**
* Factory for BgActionTrigger
* @param string $jsCode
* @param string $messageId
* @param int $delay
* @return BgActionTrigger
*/
public static function createForJsAction($jsCode, $messageId, $delay = 0){
$newOne = new BgActionTrigger("javascript_action", [], $messageId, $delay);
$newOne->javascriptCode = $jsCode;
return $newOne;
}

/**
* @return string
*/
public function toXML()
{
if(isSet($this->javascriptCode)){
return XMLWriter::triggerBgJSAction($this->javascriptCode, false, $this->delay);
}else{
return XMLWriter::triggerBgAction($this->actionName, $this->parameters, $this->messageId, false, $this->delay);
}
$data = "<trigger_bg_action name=\"javascript_instruction\" delay=\"".$this->delay."\">";
$data .= "<clientCallback><![CDATA[".$this->javascriptCode."]]></clientCallback>";
$data .= "</trigger_bg_action>";
return $data;
}
}
4 changes: 4 additions & 0 deletions core/src/plugins/access.fs/FsAccessDriver.php
Expand Up @@ -785,6 +785,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
$taskId = $request->getAttribute("pydio-task-id");
if($request->getAttribute("pydio-task-id") === null){
$task = TaskService::actionAsTask($ctx, $action, $httpVars);
$task->setActionLabel($mess, '313');
$task->setFlags(Task::FLAG_STOPPABLE);
$response = TaskService::getInstance()->enqueueTask($task, $request, $response);
break;
Expand Down Expand Up @@ -907,6 +908,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
$taskId = $request->getAttribute("pydio-task-id");
if($taskId === null && ($size === -1 || $size > $bgSizeThreshold)){
$task = TaskService::actionAsTask($ctx, $action, $httpVars);
$task->setActionLabel($mess, '7');
if($size === -1 || $size > $bgWorkerThreshold){
$task->setSchedule(new Schedule(Schedule::TYPE_ONCE_DEFER));
}
Expand All @@ -932,6 +934,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
$taskId = $request->getAttribute("pydio-task-id");
if($taskId === null && !ApplicationState::sapiIsCli()){
$task = TaskService::actionAsTask($ctx, $action, $httpVars);
$task->setActionLabel($mess, '221');
$response = TaskService::getInstance()->enqueueTask($task, $request, $response);
break;
}
Expand Down Expand Up @@ -991,6 +994,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
}
if($taskId === null && ($size === -1 || $size > $bgSizeThreshold)){
$task = TaskService::actionAsTask($ctx, $action, $httpVars);
$task->setActionLabel($mess, $action === 'copy' ? '66' : '70');
$task->setFlags(Task::FLAG_STOPPABLE);
if($size === -1 || $size > $bgWorkerThreshold){
$task->setSchedule(new Schedule(Schedule::TYPE_ONCE_DEFER));
Expand Down
6 changes: 2 additions & 4 deletions core/src/plugins/access.fs/fsActions.xml
Expand Up @@ -146,10 +146,8 @@
}
if(pydio.getController().getActionByName("trigger_remote_copy")){
modal.setCloseAction(function(){
ajaxplorer.fireContextRefresh();
var bgManager = pydio.getController().getBackgroundTasksManager();
bgManager.queueAction("trigger_remote_copy", {}, "Copying files to server");
bgManager.next();
pydio.fireContextRefresh();
PydioApi.getClient().request({get_action:'trigger_remote_copy'});
});
}
if(uploader.dialogOnOpen){
Expand Down
2 changes: 2 additions & 0 deletions core/src/plugins/access.ftp/FtpAccessDriver.php
Expand Up @@ -161,6 +161,7 @@ public function uploadActions(ServerRequestInterface &$request, ResponseInterfac
if ($nextFile!='') {
//$x->addChunk(new BgActionTrigger("next_to_remote", array(), "Copying file ".TextEncoder::toUTF8($nextFile)." to remote server"));
$newTask = TaskService::actionAsTask($ctx, "next_to_remote", []);
$newTask->setLabel("Copying file " . $nextFile . " to remote server");
$response = TaskService::getInstance()->enqueueTask($newTask, $request, $response);
} else {
//$x->addChunk(new BgActionTrigger("reload_node", array(), "Upload done, reloading client."));
Expand Down Expand Up @@ -223,6 +224,7 @@ public function uploadActions(ServerRequestInterface &$request, ResponseInterfac
$this->writeUploadSuccess($request, ["PREVENT_NOTIF" => true]);

$task = TaskService::actionAsTask($ctx, "next_to_remote", []);
$task->setLabel("Copying file to remote server");
TaskService::getInstance()->enqueueTask($task, $request, $response);

} catch (\Exception $e) {
Expand Down
5 changes: 3 additions & 2 deletions core/src/plugins/action.powerfs/PowerFSController.php
Expand Up @@ -33,7 +33,7 @@
use Pydio\Core\PluginFramework\PluginsService;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Pydio\Core\Http\Message\BgActionTrigger;
use Pydio\Core\Http\Message\JsActionTrigger;
use Pydio\Tasks\Task;
use Pydio\Tasks\TaskService;
use RecursiveDirectoryIterator;
Expand Down Expand Up @@ -106,6 +106,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface

if ($taskId === null) {
$task = TaskService::actionAsTask($ctx, $request->getAttribute("action"), $httpVars);
$task->setLabel($mess['powerfs.1']);
$task->setFlags(Task::FLAG_STOPPABLE | Task::FLAG_HAS_PROGRESS);
TaskService::getInstance()->enqueueTask($task, $request, $response);
return;
Expand Down Expand Up @@ -190,7 +191,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
} else {
$archiveName = str_replace("'", "\'", $originalArchiveParam);
$jsCode = " PydioApi.getClient().downloadSelection(null, $('download_form'), 'postcompress_download', {ope_id:'" . $opeId . "',archive_name:'" . $archiveName . "'}); ";
$actionTrigger = BgActionTrigger::createForJsAction($jsCode, $mess["powerfs.3"]);
$actionTrigger = new JsActionTrigger($jsCode, 0);
Controller::applyHook("msg.instant", array($ctx, $actionTrigger->toXML()));

}
Expand Down
6 changes: 2 additions & 4 deletions core/src/plugins/action.quicksend/class.QuicksendManager.js
Expand Up @@ -37,10 +37,8 @@ Class.create("QuicksendManager", AjxpPane, {
var uploader = uploaders[0];
if(pydio.getController().getActionByName("trigger_remote_copy")){
modal.setCloseAction(function(){
ajaxplorer.fireContextRefresh();
var bgManager = pydio.getController().getBackgroundTasksManager();
bgManager.queueAction("trigger_remote_copy", {}, "Copying files to server");
bgManager.next();
pydio.fireContextRefresh();
PydioApi.getClient().request({get_action:'trigger_remote_copy'});
});
}
if(uploader.dialogOnOpen){
Expand Down
12 changes: 12 additions & 0 deletions core/src/plugins/cache.doctrine/src/PydioApcuCache.php
Expand Up @@ -67,4 +67,16 @@ public function setNamespace($namespace)
parent::setNamespace($namespace);
$this->internalNamespace = $namespace;
}

/**
* {@inheritdoc}
*/
protected function doFetchMultiple(array $keys)
{
$test = apcu_fetch($keys);
if($test === false) return [];
else return $test;
}


}
9 changes: 5 additions & 4 deletions core/src/plugins/core.access/src/AbstractAccessDriver.php
Expand Up @@ -144,17 +144,18 @@ public function directoryUsage(AJXP_Node $node){
*/
public function crossRepositoryCopy(ServerRequestInterface &$requestInterface, ResponseInterface &$responseInterface)
{
$httpVars = $requestInterface->getParsedBody();
$httpVars = $requestInterface->getParsedBody();
$mess = LocaleService::getMessages();

$taskId = $requestInterface->getAttribute("pydio-task-id");
$ctx = $requestInterface->getAttribute("ctx");
$taskId = $requestInterface->getAttribute("pydio-task-id");
$ctx = $requestInterface->getAttribute("ctx");
if(empty($taskId)){
$task = TaskService::actionAsTask($ctx, "cross_copy", $httpVars);
$task->setActionLabel($mess, isSet($httpVars["moving_files"]) ? '70' : '66');
$responseInterface = TaskService::getInstance()->enqueueTask($task, $requestInterface, $responseInterface);
return;
}

$mess = LocaleService::getMessages();

$selection = UserSelection::fromContext($ctx, $httpVars);
$files = $selection->getFiles();
Expand Down
3 changes: 2 additions & 1 deletion core/src/plugins/core.ajaxplorer/i18n/ca.php
Expand Up @@ -653,5 +653,6 @@
"552" => "Please provide password.",
"553" => "Invalid password, please try again. \\n Make sure your Caps Lock is not engaged!",
"554" => "%s result(s) in Recycle Bin",
"556" => "Launching task %s in background",

);
);
3 changes: 2 additions & 1 deletion core/src/plugins/core.ajaxplorer/i18n/cs.php
Expand Up @@ -650,4 +650,5 @@
"552" => "Please provide password.",
"553" => "Invalid password, please try again. \\n Make sure your Caps Lock is not engaged!",
"554" => "%s result(s) in Recycle Bin",
);
"556" => "Launching task %s in background",
);
3 changes: 2 additions & 1 deletion core/src/plugins/core.ajaxplorer/i18n/da.php
Expand Up @@ -655,5 +655,6 @@
"552" => "Please provide password.",
"553" => "Invalid password, please try again. \\n Make sure your Caps Lock is not engaged!",
"554" => "%s result(s) in Recycle Bin",
"556" => "Launching task %s in background",
/* END SENTENCE */
);
);
3 changes: 2 additions & 1 deletion core/src/plugins/core.ajaxplorer/i18n/de.php
Expand Up @@ -657,6 +657,7 @@
"552" => "Please provide password.",
"553" => "Invalid password, please try again. \\n Make sure your Caps Lock is not engaged!",
"554" => "%s result(s) in Recycle Bin",
"556" => "Launching task %s in background",
/* END SENTENCE */
/* password strength tester */
);
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/en.php
Expand Up @@ -652,4 +652,5 @@
"552" => "Please provide password.",
"553" => "Invalid password, please try again. \\n Make sure your Caps Lock is not engaged!",
"554" => "%s result(s) in Recycle Bin",
"556" => "Launching task %s in background",
);
3 changes: 2 additions & 1 deletion core/src/plugins/core.ajaxplorer/i18n/es.php
Expand Up @@ -657,4 +657,5 @@
"552" => "Please provide password.",
"553" => "Invalid password, please try again. \\n Make sure your Caps Lock is not engaged!",
"554" => "%s result(s) in Recycle Bin",
);
"556" => "Launching task %s in background",
);
3 changes: 2 additions & 1 deletion core/src/plugins/core.ajaxplorer/i18n/et.php
Expand Up @@ -653,5 +653,6 @@
"552" => "Please provide password.",
"553" => "Invalid password, please try again. \\n Make sure your Caps Lock is not engaged!",
"554" => "%s result(s) in Recycle Bin",
"556" => "Launching task %s in background",
/* END SENTENCE */
);
);
3 changes: 2 additions & 1 deletion core/src/plugins/core.ajaxplorer/i18n/eus.php
Expand Up @@ -651,5 +651,6 @@
"552" => "Please provide password.",
"553" => "Invalid password, please try again. \\n Make sure your Caps Lock is not engaged!",
"554" => "%s result(s) in Recycle Bin",
"556" => "Launching task %s in background",
/* END SENTENCE */
);
);
3 changes: 2 additions & 1 deletion core/src/plugins/core.ajaxplorer/i18n/fi.php
Expand Up @@ -653,5 +653,6 @@
"552" => "Please provide password.",
"553" => "Invalid password, please try again. \\n Make sure your Caps Lock is not engaged!",
"554" => "%s result(s) in Recycle Bin",
"556" => "Launching task %s in background",
/* END SENTENCE */
);
);
15 changes: 8 additions & 7 deletions core/src/plugins/core.ajaxplorer/i18n/fr.php
Expand Up @@ -646,11 +646,12 @@
"546" => "Ce partage provient de %%OWNER%% d'un système distant. Souhaîtez-vous continuer ?",
"547" => "Accepter",
"548" => "Refuser",
"549" => "Vaous avez précedemment accepté ce partage depuis un système distant (par %%OWNER%%). Désirez-vous le rejeter désormais?",
"550" => "Rejeter ce partage",
"551" => "Rejeter",
"552" => "Please provide a password.",
"553" => "Invalid password, please try again. \\n Make sure your Caps Lock is not engaged!",
"554" => "%s résultat(s) dans la Corbeille",
"549" => "Vaous avez précedemment accepté ce partage depuis un système distant (par %%OWNER%%). Désirez-vous le rejeter désormais?",
"550" => "Rejeter ce partage",
"551" => "Rejeter",
"552" => "Please provide a password.",
"553" => "Invalid password, please try again. \\n Make sure your Caps Lock is not engaged!",
"554" => "%s résultat(s) dans la Corbeille",
"556" => "Launching task %s in background",
/* END SENTENCE */
);
);
3 changes: 2 additions & 1 deletion core/src/plugins/core.ajaxplorer/i18n/gr.php
Expand Up @@ -650,5 +650,6 @@
"552" => "Please provide password.",
"553" => "Invalid password, please try again. \\n Make sure your Caps Lock is not engaged!",
"554" => "%s result(s) in Recycle Bin",
"556" => "Launching task %s in background",
/* END SENTENCE */
);
);
3 changes: 2 additions & 1 deletion core/src/plugins/core.ajaxplorer/i18n/he.php
Expand Up @@ -650,5 +650,6 @@
"552" => "Please provide password.",
"553" => "Invalid password, please try again. \\n Make sure your Caps Lock is not engaged!",
"554" => "%s result(s) in Recycle Bin",
"556" => "Launching task %s in background",
/* END SENTENCE */
);
);
3 changes: 2 additions & 1 deletion core/src/plugins/core.ajaxplorer/i18n/hu.php
Expand Up @@ -655,5 +655,6 @@
"552" => "Please provide password.",
"553" => "Invalid password, please try again. \\n Make sure your Caps Lock is not engaged!",
"554" => "%s result(s) in Recycle Bin",
"556" => "Launching task %s in background",
/* END SENTENCE */
);
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/it.php
Expand Up @@ -670,5 +670,6 @@
"552" => "Please provide password.",
"553" => "Invalid password, please try again. \\n Make sure your Caps Lock is not engaged!",
"554" => "%s result(s) in Recycle Bin",
"556" => "Launching task %s in background",
/* END SENTENCE */
);

0 comments on commit 7310b06

Please sign in to comment.