enables the file name check also to match name of mountpoints
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
5ea6481355
commit
c0c88e3bd8
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||||
namespace OCA\WorkflowEngine\Check;
|
namespace OCA\WorkflowEngine\Check;
|
||||||
|
|
||||||
use OCA\WorkflowEngine\Entity\File;
|
use OCA\WorkflowEngine\Entity\File;
|
||||||
|
use OCP\Files\Mount\IMountManager;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\WorkflowEngine\IFileCheck;
|
use OCP\WorkflowEngine\IFileCheck;
|
||||||
|
@ -33,21 +34,38 @@ class FileName extends AbstractStringCheck implements IFileCheck {
|
||||||
|
|
||||||
/** @var IRequest */
|
/** @var IRequest */
|
||||||
protected $request;
|
protected $request;
|
||||||
|
/** @var IMountManager */
|
||||||
|
private $mountManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param IL10N $l
|
* @param IL10N $l
|
||||||
* @param IRequest $request
|
* @param IRequest $request
|
||||||
*/
|
*/
|
||||||
public function __construct(IL10N $l, IRequest $request) {
|
public function __construct(IL10N $l, IRequest $request, IMountManager $mountManager) {
|
||||||
parent::__construct($l);
|
parent::__construct($l);
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
$this->mountManager = $mountManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getActualValue(): string {
|
protected function getActualValue(): string {
|
||||||
return $this->path === null ? '' : basename($this->path);
|
$fileName = $this->path === null ? '' : basename($this->path);
|
||||||
|
if ($fileName === '' && !$this->storage->isLocal()) {
|
||||||
|
// Return the mountpoint name of external storages that are not mounted as user home
|
||||||
|
$mountPoints = $this->mountManager->findByStorageId($this->storage->getId());
|
||||||
|
if (empty($mountPoints) || $mountPoints[0]->getMountType() !== 'external') {
|
||||||
|
return $fileName;
|
||||||
|
}
|
||||||
|
$mountPointPath = rtrim($mountPoints[0]->getMountPoint(), '/');
|
||||||
|
$mountPointPieces = explode('/', $mountPointPath);
|
||||||
|
$mountPointName = array_pop($mountPointPieces);
|
||||||
|
if (!empty($mountPointName) && $mountPointName !== 'files' && count($mountPointPieces) !== 2) {
|
||||||
|
return $mountPointName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue