2018-10-03 18:24:42 +02:00
|
|
|
<?php
|
2020-04-09 11:50:14 +02:00
|
|
|
|
2018-10-03 20:26:00 +02:00
|
|
|
declare(strict_types=1);
|
2021-06-04 21:52:51 +02:00
|
|
|
|
2018-10-03 18:24:42 +02:00
|
|
|
/**
|
2024-05-30 20:13:41 +02:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2018-10-03 18:24:42 +02:00
|
|
|
*/
|
|
|
|
namespace OCA\WorkflowEngine\Check;
|
|
|
|
|
2020-12-15 11:50:04 +01:00
|
|
|
use OC\Files\Storage\Local;
|
2019-09-05 15:52:11 +02:00
|
|
|
use OCA\WorkflowEngine\Entity\File;
|
2020-12-15 00:02:43 +01:00
|
|
|
use OCP\Files\Mount\IMountManager;
|
2018-10-03 18:24:42 +02:00
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\IRequest;
|
2019-09-09 14:27:10 +02:00
|
|
|
use OCP\WorkflowEngine\IFileCheck;
|
2018-10-03 18:24:42 +02:00
|
|
|
|
2019-09-09 14:27:10 +02:00
|
|
|
class FileName extends AbstractStringCheck implements IFileCheck {
|
2019-09-09 16:04:12 +02:00
|
|
|
use TFileCheck;
|
2018-10-03 18:24:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IL10N $l
|
|
|
|
* @param IRequest $request
|
|
|
|
*/
|
2024-10-18 12:04:22 +02:00
|
|
|
public function __construct(
|
|
|
|
IL10N $l,
|
|
|
|
protected IRequest $request,
|
|
|
|
private IMountManager $mountManager,
|
|
|
|
) {
|
2018-10-03 18:24:42 +02:00
|
|
|
parent::__construct($l);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-10-03 20:26:00 +02:00
|
|
|
protected function getActualValue(): string {
|
2020-12-15 00:02:43 +01:00
|
|
|
$fileName = $this->path === null ? '' : basename($this->path);
|
2020-12-15 11:50:04 +01:00
|
|
|
if ($fileName === '' && (!$this->storage->isLocal() || $this->storage->instanceOfStorage(Local::class))) {
|
2021-05-20 12:13:04 +02:00
|
|
|
// Return the mountpoint name of external storage that are not mounted as user home
|
2020-12-15 00:02:43 +01:00
|
|
|
$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;
|
2018-10-03 18:24:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $operator
|
2018-10-05 17:54:48 +02:00
|
|
|
* @param string $checkValue
|
|
|
|
* @param string $actualValue
|
2018-10-03 18:24:42 +02:00
|
|
|
* @return bool
|
|
|
|
*/
|
2018-10-05 17:54:48 +02:00
|
|
|
protected function executeStringCheck($operator, $checkValue, $actualValue): bool {
|
|
|
|
if ($operator === 'is' || $operator === '!is') {
|
|
|
|
$checkValue = mb_strtolower($checkValue);
|
|
|
|
$actualValue = mb_strtolower($actualValue);
|
|
|
|
}
|
|
|
|
return parent::executeStringCheck($operator, $checkValue, $actualValue);
|
2018-10-03 18:24:42 +02:00
|
|
|
}
|
2019-09-05 15:52:11 +02:00
|
|
|
|
|
|
|
public function supportedEntities(): array {
|
|
|
|
return [ File::class ];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isAvailableForScope(int $scope): bool {
|
|
|
|
return true;
|
|
|
|
}
|
2018-10-03 18:24:42 +02:00
|
|
|
}
|