From 25ecf150f2ef2e0a1c84719e645dee958180da5a Mon Sep 17 00:00:00 2001 From: Kilian Pfeiffer Date: Fri, 16 Oct 2020 14:09:42 +0200 Subject: [PATCH 1/4] Update Operation.php Fix to allow '%n' parameter to give out real relative file path in shared folder scenario. Signed-off-by: Kilian Pfeiffer --- lib/Operation.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Operation.php b/lib/Operation.php index e3c79b4..9664a40 100644 --- a/lib/Operation.php +++ b/lib/Operation.php @@ -23,6 +23,7 @@ namespace OCA\WorkflowScript; +use OC\Config; use OC\Files\View; use OCA\WorkflowEngine\Entity\File; use OCA\WorkflowScript\BackgroundJobs\Launcher; @@ -34,6 +35,7 @@ use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\Files\NotFoundException; +use OCP\Files\Filesystem; use OCP\IL10N; use OCP\IUser; use OCP\IUserSession; @@ -73,7 +75,18 @@ protected function buildCommand(string $template, Node $node, string $event, arr if (strpos($command, '%n')) { // Nextcloud relative-path - $command = str_replace('%n', escapeshellarg($node->getPath()), $command); + $nodeID = -1; + try { + $nodeID = $node->getId(); + } catch (InvalidPathException $e) { + } catch (NotFoundException $e) { + } + $config = new Config('config/'); + $base_path = $config->getValue('datadirectory'); + + $path = Filesystem::getLocalFile(Filesystem::getPath($nodeID)); + $command = str_replace('%n', escapeshellarg(str_replace($base_path . '/','',$path)), $command); + } if (false && strpos($command, '%f')) { From 25e4a3826a0eef5d5e74b39e760e46cf652dab2c Mon Sep 17 00:00:00 2001 From: Kilian Pfeiffer Date: Wed, 28 Oct 2020 16:06:45 +0100 Subject: [PATCH 2/4] IConfig fix Signed-off-by: Kilian Pfeiffer --- lib/Operation.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/Operation.php b/lib/Operation.php index 9664a40..2ff312e 100644 --- a/lib/Operation.php +++ b/lib/Operation.php @@ -23,8 +23,8 @@ namespace OCA\WorkflowScript; -use OC\Config; use OC\Files\View; +use OC\Files\Filesystem; use OCA\WorkflowEngine\Entity\File; use OCA\WorkflowScript\BackgroundJobs\Launcher; use OCP\BackgroundJob\IJobList; @@ -35,10 +35,10 @@ use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\Files\NotFoundException; -use OCP\Files\Filesystem; use OCP\IL10N; use OCP\IUser; use OCP\IUserSession; +use OCP\IConfig; use OCP\SystemTag\MapperEvent; use OCP\WorkflowEngine\IManager; use OCP\WorkflowEngine\IRuleMatcher; @@ -57,13 +57,16 @@ class Operation implements ISpecificOperation { private $session; /** @var IRootFolder */ private $rootFolder; + /** @var IConfig */ + private $config; - public function __construct(IManager $workflowEngineManager, IJobList $jobList, IL10N $l, IUserSession $session, IRootFolder $rootFolder) { + public function __construct(IManager $workflowEngineManager, IJobList $jobList, IL10N $l, IUserSession $session, IRootFolder $rootFolder, IConfig $config) { $this->workflowEngineManager = $workflowEngineManager; $this->jobList = $jobList; $this->l = $l; $this->session = $session; $this->rootFolder = $rootFolder; + $this->config = $config; } protected function buildCommand(string $template, Node $node, string $event, array $extra = []) { @@ -80,13 +83,12 @@ protected function buildCommand(string $template, Node $node, string $event, arr $nodeID = $node->getId(); } catch (InvalidPathException $e) { } catch (NotFoundException $e) { - } - $config = new Config('config/'); - $base_path = $config->getValue('datadirectory'); - - $path = Filesystem::getLocalFile(Filesystem::getPath($nodeID)); - $command = str_replace('%n', escapeshellarg(str_replace($base_path . '/','',$path)), $command); - + } + + $base_path = $this->config->getSystemValue('datadirectory'); + + $path = Filesystem::getLocalFile(Filesystem::getPath($nodeID)); + $command = str_replace('%n', escapeshellarg(str_replace($base_path . '/','',$path)), $command); } if (false && strpos($command, '%f')) { From d889e18cfd7df773cb46e3a4ea9ffc7784c043a1 Mon Sep 17 00:00:00 2001 From: Kilian Pfeiffer Date: Wed, 28 Oct 2020 16:07:52 +0100 Subject: [PATCH 3/4] indention fix Signed-off-by: Kilian Pfeiffer --- lib/Operation.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Operation.php b/lib/Operation.php index 2ff312e..3234dff 100644 --- a/lib/Operation.php +++ b/lib/Operation.php @@ -83,12 +83,12 @@ protected function buildCommand(string $template, Node $node, string $event, arr $nodeID = $node->getId(); } catch (InvalidPathException $e) { } catch (NotFoundException $e) { - } + } - $base_path = $this->config->getSystemValue('datadirectory'); + $base_path = $this->config->getSystemValue('datadirectory'); - $path = Filesystem::getLocalFile(Filesystem::getPath($nodeID)); - $command = str_replace('%n', escapeshellarg(str_replace($base_path . '/','',$path)), $command); + $path = Filesystem::getLocalFile(Filesystem::getPath($nodeID)); + $command = str_replace('%n', escapeshellarg(str_replace($base_path . '/','',$path)), $command); } if (false && strpos($command, '%f')) { From 283b1ffd17b10f0887f27c0c3f3bdda037e4f1ba Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 24 Nov 2020 12:03:30 +0100 Subject: [PATCH 4/4] fix indentation Signed-off-by: Arthur Schiwon Signed-off-by: Kilian Pfeiffer --- lib/Operation.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Operation.php b/lib/Operation.php index 3234dff..e1402c2 100644 --- a/lib/Operation.php +++ b/lib/Operation.php @@ -23,8 +23,8 @@ namespace OCA\WorkflowScript; -use OC\Files\View; use OC\Files\Filesystem; +use OC\Files\View; use OCA\WorkflowEngine\Entity\File; use OCA\WorkflowScript\BackgroundJobs\Launcher; use OCP\BackgroundJob\IJobList; @@ -35,10 +35,10 @@ use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\Files\NotFoundException; +use OCP\IConfig; use OCP\IL10N; use OCP\IUser; use OCP\IUserSession; -use OCP\IConfig; use OCP\SystemTag\MapperEvent; use OCP\WorkflowEngine\IManager; use OCP\WorkflowEngine\IRuleMatcher; @@ -78,17 +78,17 @@ protected function buildCommand(string $template, Node $node, string $event, arr if (strpos($command, '%n')) { // Nextcloud relative-path - $nodeID = -1; - try { - $nodeID = $node->getId(); - } catch (InvalidPathException $e) { - } catch (NotFoundException $e) { + $nodeID = -1; + try { + $nodeID = $node->getId(); + } catch (InvalidPathException $e) { + } catch (NotFoundException $e) { } - + $base_path = $this->config->getSystemValue('datadirectory'); - + $path = Filesystem::getLocalFile(Filesystem::getPath($nodeID)); - $command = str_replace('%n', escapeshellarg(str_replace($base_path . '/','',$path)), $command); + $command = str_replace('%n', escapeshellarg(str_replace($base_path . '/', '', $path)), $command); } if (false && strpos($command, '%f')) {