Permalink
Browse files

New -k parameter on command line to pass a taskId that will be then t…

…ransported as an attribute pydio-task-id inside the Request object.
  • Loading branch information...
1 parent bc5c0f9 commit f926af21643923e9cba39a095ff7fb875840f105 @cdujeu cdujeu committed May 19, 2016
@@ -32,6 +32,8 @@
use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Utils\UnixProcess;
use Pydio\Log\Core\AJXP_Logger;
+use Pydio\Tasks\Task;
+use Pydio\Tasks\TaskService;
use Zend\Diactoros\Response;
defined('AJXP_EXEC') or die( 'Access not allowed');
@@ -256,6 +258,13 @@ public static function run(ServerRequestInterface $request, &$actionNode = null)
}
+ public static function applyTaskInBackground(Task $task){
+ $parameters = $task->getParameters();
+ $task->setStatus(Task::STATUS_RUNNING);
+ TaskService::getInstance()->updateTask($task);
+ self::applyActionInBackground($task->getWsId(), $task->getAction(), $parameters, $task->getUserId(), "", $task->getId());
+ }
+
/**
* Launch a command-line version of the framework by passing the actionName & parameters as arguments.
* @static
@@ -264,9 +273,10 @@ public static function run(ServerRequestInterface $request, &$actionNode = null)
* @param array $parameters
* @param string $user
* @param string $statusFile
+ * @param string $taskId
* @return null|UnixProcess
*/
- public static function applyActionInBackground($currentRepositoryId, $actionName, $parameters, $user ="", $statusFile = "")
+ public static function applyActionInBackground($currentRepositoryId, $actionName, $parameters, $user ="", $statusFile = "", $taskId = null)
{
/*
if (empty($user)) {
@@ -292,8 +302,11 @@ public static function applyActionInBackground($currentRepositoryId, $actionName
if(!is_dir($logDir)) mkdir($logDir, 0755);
$logFile = $logDir."/".$token.".out";
if (empty($user)) {
- if(AuthService::usersEnabled() && AuthService::getLoggedUser() !== null) $user = AuthService::getLoggedUser()->getId();
- else $user = "shared";
+ if(AuthService::usersEnabled() && AuthService::getLoggedUser() !== null) {
+ $user = AuthService::getLoggedUser()->getId();
+ }else {
+ $user = "shared";
+ }
}
/*
require_once(AJXP_INSTALL_PATH."/".AJXP_PLUGINS_FOLDER."/core.mq/vendor/autoload.php");
@@ -324,9 +337,12 @@ public static function applyActionInBackground($currentRepositoryId, $actionName
if (PHP_OS == "WIN32" || PHP_OS == "WINNT" || PHP_OS == "Windows") {
$cmd = ConfService::getCoreConf("CLI_PHP")." ".chr(34).$robustInstallPath.DIRECTORY_SEPARATOR."cmd.php".chr(34)." -u=$user -t=$token -a=$actionName -r=$currentRepositoryId";
}
- if ($statusFile != "") {
+ if (!empty($statusFile)) {
$cmd .= " -s=".$statusFile;
}
+ if (!empty($taskId)) {
+ $cmd .= " -k=".$taskId;
+ }
foreach ($parameters as $key=>$value) {
if($key == "action" || $key == "get_action") continue;
if(is_array($value)){
@@ -71,6 +71,11 @@ protected function configure()
's',
InputOption::VALUE_OPTIONAL,
'Path to a file to write status information about the running task'
+ )->addOption(
+ 'cli_task_uuid',
+ 'k',
+ InputOption::VALUE_OPTIONAL,
+ 'Task Uuid'
)
;
}
@@ -94,6 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if(!is_array($pydioCliOptions["r"])){
$pydioCliOptions["r"] = [$pydioCliOptions["r"]];
}
+ $taskUid = $pydioCliOptions["k"];
foreach ($pydioCliOptions["r"] as $repoId){
$reqOptions = $pydioCliOptions;
$reqOptions["r"] = $repoId;
@@ -105,6 +111,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
->withAttribute("api", "cli")
->withAttribute("cli-options", $reqOptions)
->withAttribute("cli-output", $output);
+ if(!empty($taskUid)){
+ $request = $request->withAttribute("pydio-task-id", $taskUid);
+ }
$server->updateRequest($request);
$server->listen();
}
@@ -2144,4 +2144,28 @@ public static function winSetHidden($file)
{
@shell_exec("attrib +H " . escapeshellarg($file));
}
+
+
+ /**
+ * Create a unique UID
+ * @return string
+ */
+ public static function createGUID(){
+ if (function_exists('com_create_guid')){
+ return com_create_guid();
+ }else{
+ mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
+ $charid = strtoupper(md5(uniqid(rand(), true)));
+ $hyphen = chr(45);// "-"
+ $uuid = ""//chr(123)// "{"
+ .substr($charid, 0, 8).$hyphen
+ .substr($charid, 8, 4).$hyphen
+ .substr($charid,12, 4).$hyphen
+ .substr($charid,16, 4).$hyphen
+ .substr($charid,20,12);
+ //.chr(125);// "}"
+ return $uuid;
+ }
+ }
+
}

0 comments on commit f926af2

Please sign in to comment.