2019-09-09 10:04:12 -04:00
|
|
|
<?php
|
2020-04-09 05:50:14 -04:00
|
|
|
|
2019-09-09 10:04:12 -04:00
|
|
|
declare(strict_types=1);
|
2021-06-04 15:52:51 -04:00
|
|
|
|
2019-09-09 10:04:12 -04:00
|
|
|
/**
|
2024-05-30 14:13:41 -04:00
|
|
|
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2019-09-09 10:04:12 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\WorkflowEngine\Check;
|
|
|
|
|
|
|
|
|
|
use OCA\WorkflowEngine\Entity\File;
|
|
|
|
|
use OCP\Files\Node;
|
2024-10-18 06:04:22 -04:00
|
|
|
use OCP\Files\NotFoundException;
|
2019-09-09 10:04:12 -04:00
|
|
|
use OCP\Files\Storage\IStorage;
|
|
|
|
|
use OCP\WorkflowEngine\IEntity;
|
|
|
|
|
|
|
|
|
|
trait TFileCheck {
|
|
|
|
|
/** @var IStorage */
|
|
|
|
|
protected $storage;
|
|
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
|
protected $path;
|
|
|
|
|
|
2019-11-29 06:04:34 -05:00
|
|
|
/** @var bool */
|
|
|
|
|
protected $isDir;
|
|
|
|
|
|
2019-09-09 10:04:12 -04:00
|
|
|
/**
|
|
|
|
|
* @param IStorage $storage
|
|
|
|
|
* @param string $path
|
2019-11-29 06:04:34 -05:00
|
|
|
* @param bool $isDir
|
2019-09-09 10:04:12 -04:00
|
|
|
* @since 18.0.0
|
|
|
|
|
*/
|
2019-11-29 06:04:34 -05:00
|
|
|
public function setFileInfo(IStorage $storage, string $path, bool $isDir = false): void {
|
2019-09-09 10:04:12 -04:00
|
|
|
$this->storage = $storage;
|
|
|
|
|
$this->path = $path;
|
2019-11-29 06:04:34 -05:00
|
|
|
$this->isDir = $isDir;
|
2019-09-09 10:04:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-10-18 06:04:22 -04:00
|
|
|
* @throws NotFoundException
|
2019-09-09 10:04:12 -04:00
|
|
|
*/
|
|
|
|
|
public function setEntitySubject(IEntity $entity, $subject): void {
|
|
|
|
|
if ($entity instanceof File) {
|
|
|
|
|
if (!$subject instanceof Node) {
|
|
|
|
|
throw new \UnexpectedValueException(
|
2025-09-16 08:31:21 -04:00
|
|
|
'Expected Node subject for File entity, got ' . get_class($subject),
|
2019-09-09 10:04:12 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$this->storage = $subject->getStorage();
|
|
|
|
|
$this->path = $subject->getPath();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|