Permalink
Browse files

CLI: pass user impersonate to Task.

  • Loading branch information...
1 parent 5578b5b commit 8f8b9111f12f7a574bbde89e61564d5cce447980 @cdujeu cdujeu committed Jul 19, 2016
@@ -49,7 +49,7 @@ public static function applyTaskInBackground(Task $task)
$parameters = $task->getParameters();
$task->setStatus(Task::STATUS_RUNNING);
TaskService::getInstance()->updateTask($task);
- self::applyActionInBackground($task->getContext(), $task->getAction(), $parameters, "", $task->getId());
+ self::applyActionInBackground($task->getContext(), $task->getAction(), $parameters, "", $task->getId(), $task->getImpersonateUsers());
}
@@ -61,9 +61,10 @@ public static function applyTaskInBackground(Task $task)
* @param array $parameters
* @param string $statusFile
* @param string $taskId
+ * @param string $impersonateUsers
* @return null|UnixProcess
*/
- public static function applyActionInBackground(ContextInterface $ctx, $actionName, $parameters, $statusFile = "", $taskId = null)
+ public static function applyActionInBackground(ContextInterface $ctx, $actionName, $parameters, $statusFile = "", $taskId = null, $impersonateUsers = null)
{
$repositoryId = $ctx->getRepositoryId();
$user = $ctx->hasUser() ? $ctx->getUser()->getId() : "shared";
@@ -82,6 +83,9 @@ public static function applyActionInBackground(ContextInterface $ctx, $actionNam
}
$robustInstallPath = str_replace("/", DIRECTORY_SEPARATOR, AJXP_INSTALL_PATH);
$cmd = ConfService::getGlobalConf("CLI_PHP") . " " . $robustInstallPath . DIRECTORY_SEPARATOR . "cmd.php -u=$user -t=$token -a=$actionName -r=$repositoryId";
+ if($impersonateUsers !== null){
+ $cmd .= "-i=".$impersonateUsers;
+ }
/* Inserted next 3 lines to quote the command if in windows - rmeske*/
if (PHP_OS == "WIN32" || PHP_OS == "WINNT" || PHP_OS == "Windows") {
$cmd = ConfService::getGlobalConf("CLI_PHP") . " " . chr(34) . $robustInstallPath . DIRECTORY_SEPARATOR . "cmd.php" . chr(34) . " -u=$user -t=$token -a=$actionName -r=$repositoryId";
@@ -39,6 +39,8 @@
use Pydio\Core\Utils\TextEncoder;
use Pydio\Core\Utils\Utils;
use Pydio\Log\Core\Logger;
+use Pydio\Tasks\Task;
+use Pydio\Tasks\TaskService;
use Symfony\Component\Console\Output\OutputInterface;
use Zend\Diactoros\Response;
use Zend\Diactoros\Stream;
@@ -179,6 +181,7 @@ public static function handleRequest(ServerRequestInterface $requestInterface, R
$applyCallback = function ($userId, $baseGroup, $index, $total) use ($optRepoId, $requestInterface, $output, $next){
$actionName = $requestInterface->getAttribute("action");
+ $taskId = $requestInterface->getAttribute("pydio-task-id");
$output->writeln("<info>*****************************</info>");
$output->writeln("<info>Current User is '".$userId."'</info>");
$output->writeln("<info>*****************************</info>");
@@ -236,15 +239,21 @@ public static function handleRequest(ServerRequestInterface $requestInterface, R
}catch (\Exception $repoEx){
- $output->writeln("<error>".$repoEx->getMessage()."</error>");
+ $output->writeln("<error>$taskId: ".$repoEx->getMessage()."</error>");
+ if(!empty($taskId)){
+ TaskService::getInstance()->updateTaskStatus($taskId, Task::STATUS_FAILED, $repoEx->getMessage());
+ }
}
}
}catch (\Exception $userEx){
- $output->writeln("<error>".$userEx->getMessage()."</error>");
+ $output->writeln("<error>USER: ".$userEx->getMessage()."</error>");
+ if(!empty($taskId)){
+ TaskService::getInstance()->updateTaskStatus($taskId, Task::STATUS_FAILED, $userEx->getMessage());
+ }
}
@@ -97,6 +97,11 @@ class Task
public $parameters;
/**
+ * @var string
+ */
+ private $impersonateUsers;
+
+ /**
* @var array
*/
public $nodes = [];
@@ -320,9 +325,29 @@ public function setParameters($parameters)
$this->parameters = $parameters;
}
+ /**
+ * @param $nodePath
+ */
public function attachToNode($nodePath){
$this->nodes[] = $nodePath;
}
+ /**
+ * @return string
+ */
+ public function getImpersonateUsers()
+ {
+ return $this->impersonateUsers;
+ }
+
+ /**
+ * @param string $impersonateUsers
+ */
+ public function setImpersonateUsers($impersonateUsers)
+ {
+ $this->impersonateUsers = $impersonateUsers;
+ }
+
+
}

0 comments on commit 8f8b911

Please sign in to comment.