diff --git a/lib/Controller/CollectiveController.php b/lib/Controller/CollectiveController.php index b45006e90..daa84524f 100644 --- a/lib/Controller/CollectiveController.php +++ b/lib/Controller/CollectiveController.php @@ -14,6 +14,7 @@ use OCA\Collectives\Db\Collective; use OCA\Collectives\Fs\NodeHelper; use OCA\Collectives\Service\CollectiveService; +use OCA\Collectives\Service\NotFoundException; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\DataResponse; @@ -38,8 +39,15 @@ public function __construct( parent::__construct($AppName, $request); } + /** + * @throws NotFoundException + */ private function getUserId(): string { - return $this->userSession->getUser()->getUID(); + $user = $this->userSession->getUser(); + if ($user === null) { + throw new NotFoundException('Session user not found'); + } + return $user->getUID(); } private function getUserLang(): string { diff --git a/lib/Controller/CollectiveUserSettingsController.php b/lib/Controller/CollectiveUserSettingsController.php index 5d94fc4d4..2651ec3bd 100644 --- a/lib/Controller/CollectiveUserSettingsController.php +++ b/lib/Controller/CollectiveUserSettingsController.php @@ -12,6 +12,7 @@ use Closure; use OCA\Collectives\Service\CollectiveUserSettingsService; +use OCA\Collectives\Service\NotFoundException; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\DataResponse; @@ -32,8 +33,15 @@ public function __construct( parent::__construct($AppName, $request); } + /** + * @throws NotFoundException + */ private function getUserId(): string { - return $this->userSession->getUser()->getUID(); + $user = $this->userSession->getUser(); + if ($user === null) { + throw new NotFoundException('Session user not found'); + } + return $user->getUID(); } private function prepareResponse(Closure $callback) : DataResponse { diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 40c28db0d..ff0cf799b 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -11,6 +11,7 @@ use OCA\Collectives\Service\AttachmentService; use OCA\Collectives\Service\CollectiveService; +use OCA\Collectives\Service\NotFoundException; use OCA\Collectives\Service\PageService; use OCA\Collectives\Service\SearchService; use OCP\AppFramework\Controller; @@ -36,8 +37,15 @@ public function __construct( parent::__construct($appName, $request); } + /** + * @throws NotFoundException + */ private function getUserId(): string { - return $this->userSession->getUser()->getUID(); + $user = $this->userSession->getUser(); + if ($user === null) { + throw new NotFoundException('Session user not found'); + } + return $user->getUID(); } #[NoAdminRequired] @@ -103,6 +111,7 @@ public function contentSearch(int $collectiveId, string $searchString): DataResp #[NoAdminRequired] public function moveOrCopy(int $collectiveId, int $id, ?int $parentId = null, ?string $title = null, ?int $index = 0, bool $copy = false): DataResponse { + $index = $index ?? 0; return $this->handleErrorResponse(function () use ($collectiveId, $id, $parentId, $title, $index, $copy): array { $userId = $this->getUserId(); $pageInfo = $copy @@ -116,6 +125,7 @@ public function moveOrCopy(int $collectiveId, int $id, ?int $parentId = null, ?s #[NoAdminRequired] public function moveOrCopyToCollective(int $collectiveId, int $id, int $newCollectiveId, ?int $parentId = null, ?int $index = 0, bool $copy = false): DataResponse { + $index = $index ?? 0; return $this->handleErrorResponse(function () use ($collectiveId, $id, $newCollectiveId, $parentId, $index, $copy): array { $userId = $this->getUserId(); if ($copy) { diff --git a/lib/Controller/PageTrashController.php b/lib/Controller/PageTrashController.php index 8cd9dbab0..d1d63e327 100644 --- a/lib/Controller/PageTrashController.php +++ b/lib/Controller/PageTrashController.php @@ -9,6 +9,7 @@ namespace OCA\Collectives\Controller; +use OCA\Collectives\Service\NotFoundException; use OCA\Collectives\Service\PageService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Attribute\NoAdminRequired; @@ -33,8 +34,15 @@ public function __construct( $this->userSession = $userSession; } + /** + * @throws NotFoundException + */ private function getUserId(): string { - return $this->userSession->getUser()->getUID(); + $user = $this->userSession->getUser(); + if ($user === null) { + throw new NotFoundException('Session user not found'); + } + return $user->getUID(); } #[NoAdminRequired] diff --git a/lib/Controller/PublicPageController.php b/lib/Controller/PublicPageController.php index 7ae336d3d..2c66acb72 100644 --- a/lib/Controller/PublicPageController.php +++ b/lib/Controller/PublicPageController.php @@ -210,6 +210,7 @@ public function touch(int $id): DataResponse { #[PublicPage] #[AnonRateLimit(limit: 10, period: 10)] public function moveOrCopy(int $id, ?int $parentId, ?string $title = null, ?int $index = 0, bool $copy = false): DataResponse { + $index = $index ?? 0; return $this->handleErrorResponse(function () use ($id, $parentId, $title, $index, $copy): array { $this->checkEditPermissions(); $owner = $this->getCollectiveShare()->getOwner(); diff --git a/lib/Controller/SessionController.php b/lib/Controller/SessionController.php index ec24046b2..c8b5e9419 100644 --- a/lib/Controller/SessionController.php +++ b/lib/Controller/SessionController.php @@ -10,6 +10,7 @@ namespace OCA\Collectives\Controller; use Closure; +use OCA\Collectives\Service\NotFoundException; use OCA\Collectives\Service\SessionService; use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\DataResponse; @@ -31,8 +32,15 @@ public function __construct( parent::__construct($appName, $request); } + /** + * @throws NotFoundException + */ private function getUserId(): string { - return $this->userSession->getUser()->getUID(); + $user = $this->userSession->getUser(); + if ($user === null) { + throw new NotFoundException('Session user not found'); + } + return $user->getUID(); } private function prepareResponse(Closure $callback) : DataResponse { diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 526c15a12..0fb2c1ea1 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -75,7 +75,7 @@ public function getUserSetting(string $key): DataResponse { } #[NoAdminRequired] - public function setUserSetting(string $key, ?string $value): DataResponse { + public function setUserSetting(string $key, string $value): DataResponse { return $this->prepareResponse(function () use ($key, $value): ?string { $this->validateSetUserSetting($key, $value); $this->config->setUserValue($this->userId, 'collectives', $key, $value); diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php index d47e358ef..eda7abc84 100644 --- a/lib/Controller/ShareController.php +++ b/lib/Controller/ShareController.php @@ -13,6 +13,7 @@ use OCA\Collectives\Service\CollectiveService; use OCA\Collectives\Service\CollectiveShareService; +use OCA\Collectives\Service\NotFoundException; use OCA\Collectives\Service\PageService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Attribute\NoAdminRequired; @@ -36,8 +37,15 @@ public function __construct( parent::__construct($AppName, $request); } + /** + * @throws NotFoundException + */ private function getUserId(): string { - return $this->userSession->getUser()->getUID(); + $user = $this->userSession->getUser(); + if ($user === null) { + throw new NotFoundException('Session user not found'); + } + return $user->getUID(); } private function prepareResponse(Closure $callback) : DataResponse { diff --git a/lib/Controller/TemplateController.php b/lib/Controller/TemplateController.php index 5b25a4e98..ae23bca66 100644 --- a/lib/Controller/TemplateController.php +++ b/lib/Controller/TemplateController.php @@ -9,6 +9,7 @@ namespace OCA\Collectives\Controller; +use OCA\Collectives\Service\NotFoundException; use OCA\Collectives\Service\TemplateService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Attribute\NoAdminRequired; @@ -30,8 +31,15 @@ public function __construct( parent::__construct($appName, $request); } + /** + * @throws NotFoundException + */ private function getUserId(): string { - return $this->userSession->getUser()->getUID(); + $user = $this->userSession->getUser(); + if ($user === null) { + throw new NotFoundException('Session user not found'); + } + return $user->getUID(); } #[NoAdminRequired] diff --git a/lib/Controller/TrashController.php b/lib/Controller/TrashController.php index 5672473c4..46b9b5942 100644 --- a/lib/Controller/TrashController.php +++ b/lib/Controller/TrashController.php @@ -10,6 +10,7 @@ namespace OCA\Collectives\Controller; use OCA\Collectives\Service\CollectiveService; +use OCA\Collectives\Service\NotFoundException; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\DataResponse; @@ -30,8 +31,15 @@ public function __construct( parent::__construct($AppName, $request); } + /** + * @throws NotFoundException + */ private function getUserId(): string { - return $this->userSession->getUser()->getUID(); + $user = $this->userSession->getUser(); + if ($user === null) { + throw new NotFoundException('Session user not found'); + } + return $user->getUID(); } #[NoAdminRequired] diff --git a/lib/Db/Collective.php b/lib/Db/Collective.php index a3a75f8f9..c7c629ec1 100644 --- a/lib/Db/Collective.php +++ b/lib/Db/Collective.php @@ -75,9 +75,9 @@ class Collective extends Entity implements JsonSerializable { protected bool $userShowMembers = Collective::defaultShowMembers; protected bool $userShowRecentPages = Collective::defaultShowRecentPages; protected array $userFavoritePages = []; - protected ?bool $canLeave = null; + protected bool $canLeave = false; - public function getCircleId(): ?string { + public function getCircleId(): string { return $this->getCircleUniqueId(); } @@ -200,11 +200,11 @@ public function getUserFavoritePages(): array { return $this->userFavoritePages; } - public function getCanLeave(): ?bool { + public function getCanLeave(): bool { return $this->canLeave; } - public function setCanLeave(?bool $canLeave): void { + public function setCanLeave(bool $canLeave): void { $this->canLeave = $canLeave; } diff --git a/lib/Db/CollectiveMapper.php b/lib/Db/CollectiveMapper.php index 79788241b..d52b4cd9c 100644 --- a/lib/Db/CollectiveMapper.php +++ b/lib/Db/CollectiveMapper.php @@ -15,7 +15,6 @@ use OCA\Collectives\Service\NotFoundException; use OCA\Collectives\Service\NotPermittedException; use OCP\AppFramework\Db\DoesNotExistException; -use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\AppFramework\Db\QBMapper; use OCP\DB\Exception; @@ -23,10 +22,10 @@ use OCP\IDBConnection; /** - * @method Collective insert(Entity $collective) - * @method Collective delete(Entity $collective) + * @method Collective insert(Collective $collective) + * @method Collective delete(Collective $collective) * @method Collective findEntity(IQueryBuilder $query) - * @method Collective update(Entity $collective) + * @method Collective update(Collective $collective) * @template-extends QBMapper */ class CollectiveMapper extends QBMapper { diff --git a/lib/Db/CollectiveShareMapper.php b/lib/Db/CollectiveShareMapper.php index c85de71cc..d76d8e291 100644 --- a/lib/Db/CollectiveShareMapper.php +++ b/lib/Db/CollectiveShareMapper.php @@ -28,6 +28,9 @@ public function __construct(IDBConnection $db) { parent::__construct($db, 'collectives_shares', CollectiveShare::class); } + /** + * @return CollectiveShare[] + */ public function findByCollectiveId(int $collectiveId): array { $qb = $this->db->getQueryBuilder(); $qb->select('*') @@ -39,6 +42,7 @@ public function findByCollectiveId(int $collectiveId): array { } /** + * @return CollectiveShare[] * @throws Exception */ public function findByCollectiveIdAndUser(int $collectiveId, string $userId): array { diff --git a/lib/Db/CollectiveUserSettings.php b/lib/Db/CollectiveUserSettings.php index 612f5b669..d62ec7d3a 100644 --- a/lib/Db/CollectiveUserSettings.php +++ b/lib/Db/CollectiveUserSettings.php @@ -36,7 +36,7 @@ class CollectiveUserSettings extends Entity implements JsonSerializable { protected ?int $collectiveId = null; protected ?string $userId = null; protected int $pageOrder = Collective::defaultPageOrder; - protected ?string $settings = '{}'; + protected string $settings = '{}'; /** * @throws NotPermittedException @@ -52,7 +52,7 @@ private static function checkSetting(string $setting): void { * @throws NotPermittedException * @throws JsonException */ - public function getSetting(string $setting) { + public function getSetting(string $setting): mixed { self::checkSetting($setting); return json_decode($this->settings, true, 512, JSON_THROW_ON_ERROR)[$setting] ?? null; } diff --git a/lib/Db/CollectiveUserSettingsMapper.php b/lib/Db/CollectiveUserSettingsMapper.php index 62cbc205b..0dd93fba2 100644 --- a/lib/Db/CollectiveUserSettingsMapper.php +++ b/lib/Db/CollectiveUserSettingsMapper.php @@ -31,12 +31,9 @@ public function __construct(IDBConnection $db) { * Provide our own implementation of `insertOrUpdate` as the one from QBMapper throws * `REASON_NOT_NULL_CONSTRAINT_VIOLATION` for existing entities. * - * TODO: Migrate to using `CollectiveUserSettings` in type hints once we drop PHP7.3. - * - * @return CollectiveUserSettings * @throws Exception */ - public function insertOrUpdate(Entity $entity): Entity { + public function insertOrUpdate(CollectiveUserSettings|Entity $entity): CollectiveUserSettings { if ($entity->getId() === null) { return $this->insert($entity); } diff --git a/lib/Db/PageMapper.php b/lib/Db/PageMapper.php index 77eabb9d1..c69b85ee5 100644 --- a/lib/Db/PageMapper.php +++ b/lib/Db/PageMapper.php @@ -10,22 +10,21 @@ namespace OCA\Collectives\Db; use OCP\AppFramework\Db\DoesNotExistException; -use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\AppFramework\Db\QBMapper; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; /** - * @method Page insert(Entity $page) - * @method Page update(Entity $page) - * @method Page delete(Entity $page) + * @method Page insert(Page $page) + * @method Page update(Page $page) + * @method Page delete(Page $page) * @method Page findEntity(IQueryBuilder $query) * @template-extends QBMapper */ class PageMapper extends QBMapper { - public function __construct(IDBConnection $db, ?string $entityClass = null) { - parent::__construct($db, 'collectives_pages', $entityClass); + public function __construct(IDBConnection $db) { + parent::__construct($db, 'collectives_pages', Page::class); } public function updateOrInsert(Page $page): Page { diff --git a/lib/Listeners/BeforeTemplateRenderedListener.php b/lib/Listeners/BeforeTemplateRenderedListener.php index 528eced6f..fef22a68c 100644 --- a/lib/Listeners/BeforeTemplateRenderedListener.php +++ b/lib/Listeners/BeforeTemplateRenderedListener.php @@ -11,6 +11,7 @@ use OCA\Collectives\AppInfo\Application; use OCA\Collectives\Fs\UserFolderHelper; +use OCA\Collectives\Service\NotFoundException; use OCA\Collectives\Service\NotPermittedException; use OCA\Text\Event\LoadEditor; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; @@ -44,9 +45,10 @@ public function handle(Event $event): void { Util::addStyle('collectives', 'collectives'); // Get Collectives user folder for users - $userId = $this->userSession->getUser() - ? $this->userSession->getUser()->getUID() - : null; + $userId = $this->userSession->getUser()?->getUID(); + if ($userId === null) { + throw new NotFoundException('Session user not found'); + } $userFolder = $this->userFolderHelper->getUserFolderSetting($userId); } diff --git a/lib/Listeners/TextMentionListener.php b/lib/Listeners/TextMentionListener.php index 0de0d1ea0..8fd5df627 100644 --- a/lib/Listeners/TextMentionListener.php +++ b/lib/Listeners/TextMentionListener.php @@ -40,6 +40,10 @@ public function handle(Event $event): void { return; } + if (!$this->userId) { + return; + } + $collective = $this->collectiveService->getCollective($mountPoint->getFolderId(), $this->userId); $pageInfo = $this->pageService->findByFile($mountPoint->getFolderId(), $event->getFile(), $this->userId); diff --git a/lib/Migration/MigrateTemplates.php b/lib/Migration/MigrateTemplates.php index 1bf4635ed..c6358d350 100644 --- a/lib/Migration/MigrateTemplates.php +++ b/lib/Migration/MigrateTemplates.php @@ -90,6 +90,7 @@ private function getFolderTemplateFiles(Folder $folder, bool $recursive = false) */ private function getTemplateFolder(Folder $collectiveFolder): Folder { try { + /** @var Folder $templateFolder */ $templateFolder = $collectiveFolder->get(self::TEMPLATE_FOLDER); } catch (FilesNotFoundException) { // Create missing template folder diff --git a/lib/Model/PageInfo.php b/lib/Model/PageInfo.php index e8cf7a8d6..4901d4854 100644 --- a/lib/Model/PageInfo.php +++ b/lib/Model/PageInfo.php @@ -179,7 +179,7 @@ public function jsonSerialize(): array { * @throws InvalidPathException * @throws NotFoundException */ - public function fromFile(File $file, int $parentId, ?string $lastUserId = null, ?string $lastUserDisplayName = null, ?string $emoji = null, ?string $subpageOrder = null, bool $fullWidth = false): void { + public function fromFile(File $file, int $parentId, ?string $lastUserId = null, ?string $lastUserDisplayName = null, ?string $emoji = null, ?string $subpageOrder = null, ?bool $fullWidth = null): void { $this->setId($file->getId()); // Set folder name as title for all index pages except the collective landing page $dirName = dirname($file->getInternalPath()); @@ -191,7 +191,7 @@ public function fromFile(File $file, int $parentId, ?string $lastUserId = null, } $this->setFilePath($dirName); $this->setTimestamp($file->getMTime()); - $this->setSize($file->getSize()); + $this->setSize((int)$file->getSize()); $this->setFileName($file->getName()); $mountPoint = explode('/', $file->getMountPoint()->getMountPoint(), 4); if (count($mountPoint) >= 4) { diff --git a/lib/Mount/CollectiveFolderManager.php b/lib/Mount/CollectiveFolderManager.php index e7d840f0c..7d3ee4a0c 100644 --- a/lib/Mount/CollectiveFolderManager.php +++ b/lib/Mount/CollectiveFolderManager.php @@ -28,7 +28,6 @@ use OCP\IRequest; use OCP\IUser; use OCP\IUserSession; -use OCP\Util; use RuntimeException; class CollectiveFolderManager { @@ -99,6 +98,9 @@ public function getMount(int $id, return null; } $cacheEntry = $this->getRootFolder()->getStorage()->getCache()->get($folder->getId()); + if ($cacheEntry === false) { + return null; + } } $storage = new NoExcludePropagatorStorageWrapper(['storage' => $this->getRootFolder()->getStorage()]); @@ -107,8 +109,7 @@ public function getMount(int $id, // apply acl before jail if ($user) { - $inShare = $this->getCurrentUID() === null || $this->getCurrentUID() !== $user->getUID(); - [$major, $minor, $micro] = Util::getVersion(); + $inShare = !\OC::$CLI && ($this->getCurrentUID() === null || $this->getCurrentUID() !== $user->getUID()); $storage = new ACLStorageWrapper([ 'storage' => $storage, 'permissions' => $permissions, @@ -159,7 +160,7 @@ private function getRootFolderId(): int { ->where($qb->expr()->eq('storage', $qb->createNamedParameter($this->getRootFolderStorageId()))) ->andWhere($qb->expr()->eq('path_hash', $qb->createNamedParameter(md5($this->getRootPath())))); - $this->rootFolderId = (int)$qb->execute()->fetchColumn(); + $this->rootFolderId = (int)$qb->executeQuery()->fetchColumn(); } return $this->rootFolderId; @@ -206,7 +207,7 @@ public function getFolderFileCache(int $id, string $name): array { ->where($qb->expr()->eq('co.id', $qb->createNamedParameter($id))) ->andWhere($qb->expr()->eq('fc.parent', $qb->createNamedParameter($this->getRootFolderId()))) ->andWhere($qb->expr()->eq('fc.storage', $qb->createNamedParameter($this->getRootFolderStorageId(), IQueryBuilder::PARAM_INT))); - $cache = $qb->execute()->fetch(); + $cache = $qb->executeQuery()->fetch(); $cache['mount_point'] = $name; return $cache; } @@ -231,6 +232,7 @@ public function getOrCreateFolder(int $id): Folder { try { $folder = $this->getFolder($id); } catch (NotFoundException) { + /** @var Folder $folder */ $folder = $this->getSkeletonFolder($this->getRootFolder()) ->copy($this->getRootFolder()->getPath() . '/' . $id); } diff --git a/lib/Mount/CollectiveStorage.php b/lib/Mount/CollectiveStorage.php index ac4aeaf33..557f542b9 100644 --- a/lib/Mount/CollectiveStorage.php +++ b/lib/Mount/CollectiveStorage.php @@ -15,6 +15,8 @@ use OC\Files\ObjectStore\ObjectStoreStorage; use OC\Files\Storage\Wrapper\Wrapper; use OCP\Files\Cache\ICacheEntry; +use OCP\Files\Cache\IScanner; +use OCP\Files\Storage\IStorage; use OCP\IUser; class CollectiveStorage extends Wrapper { @@ -64,7 +66,7 @@ public function getCache($path = '', $storage = null): RootEntryCache { * @param string $path * @param null $storage */ - public function getScanner($path = '', $storage = null): Scanner { + public function getScanner($path = '', $storage = null): IScanner { if (!$storage) { $storage = $this; } diff --git a/lib/Mount/MountProvider.php b/lib/Mount/MountProvider.php index 1ae12805a..35eabba08 100644 --- a/lib/Mount/MountProvider.php +++ b/lib/Mount/MountProvider.php @@ -89,9 +89,6 @@ public function getFoldersForUser(IUser $user): array { return $folders; } - /** - * @return IMountPoint[]|null[] - */ public function getMountsForUser(IUser $user, IStorageFactory $loader): array { if (!$this->isEnabledForUser($user)) { return []; @@ -99,14 +96,14 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader): array { $folders = $this->getFoldersForUser($user); try { - return array_map(fn ($folder) => $this->collectiveFolderManager->getMount( + return array_filter(array_map(fn ($folder): ?IMountPoint => $this->collectiveFolderManager->getMount( $folder['folder_id'], '/' . $user->getUID() . '/files/' . $folder['mount_point'], $folder['permissions'], $folder['rootCacheEntry'], $loader, $user - ), $folders); + ), $folders)); } catch (FilesNotFoundException|\Exception $e) { $this->log($e); return []; diff --git a/lib/Search/FileSearch/FileIndexer.php b/lib/Search/FileSearch/FileIndexer.php index b0817a134..b54c25f65 100644 --- a/lib/Search/FileSearch/FileIndexer.php +++ b/lib/Search/FileSearch/FileIndexer.php @@ -71,14 +71,15 @@ public function runOnDirectory(Folder $folder, bool $recursive = true): void { * @throws FileSearchException */ public function run(array $pages = []): void { - if (!$this->getIndex()) { + $index = $this->getIndex(); + if ($index === null) { throw new FileSearchException('Indexing could not be performed because index is not selected.'); } - $this->getIndex()->exec('CREATE TABLE IF NOT EXISTS filemap ( + $index->exec('CREATE TABLE IF NOT EXISTS filemap ( id INTEGER PRIMARY KEY, path TEXT)'); - $this->getIndex()->beginTransaction(); + $index->beginTransaction(); $processedPages = 0; foreach ($pages as $page) { @@ -97,7 +98,7 @@ public function run(array $pages = []): void { } $this->processDocument($fileCollection); - $statement = $this->getIndex()->prepare("INSERT INTO filemap ( 'id', 'path') values ( :id, :path)"); + $statement = $index->prepare("INSERT INTO filemap ( 'id', 'path') values ( :id, :path)"); $statement->bindParam(':id', $id); $statement->bindParam(':path', $internalPath); $statement->execute(); @@ -107,10 +108,10 @@ public function run(array $pages = []): void { throw new FileSearchException('File indexer failed to open and/or read file', 0, $e); } } - $this->getIndex()->exec("UPDATE info SET `value`=$processedPages WHERE `key`='total_documents'"); - $this->getIndex()->exec("INSERT INTO info ( 'key', 'value') values ( 'driver', 'filesystem')"); + $index->exec("UPDATE info SET `value`=$processedPages WHERE `key`='total_documents'"); + $index->exec("INSERT INTO info ( 'key', 'value') values ( 'driver', 'filesystem')"); - $this->getIndex()->commit(); + $index->commit(); } public function getIndex(): ?PDO { diff --git a/lib/Service/CircleHelper.php b/lib/Service/CircleHelper.php index 72b94fc48..b7013ddf8 100644 --- a/lib/Service/CircleHelper.php +++ b/lib/Service/CircleHelper.php @@ -62,6 +62,7 @@ private function getFederatedUser(?string $userId = null): ?FederatedUser { } try { + /** @psalm-suppress PossiblyNullReference - we check if circlesManager is null */ return $this->circlesManager->getFederatedUser($userId, Member::TYPE_USER); } catch (CircleNotFoundException $e) { throw new NotFoundException($e->getMessage(), 0, $e); @@ -108,6 +109,7 @@ public function getCircles(?string $userId = null): array { $circleProbe->mustBeMember(); $dataProbe = new DataProbe(); $dataProbe->add(DataProbe::INITIATOR); + /** @psalm-suppress PossiblyNullReference - we check if circlesManager is null */ $circles = self::useProbeCircles() ? $this->circlesManager->probeCircles($circleProbe, $dataProbe) : $this->circlesManager->getCircles($circleProbe, true); @@ -132,6 +134,7 @@ public function getCircle(string $circleId, ?string $userId = null, bool $super } else { $this->startSession($userId); } + /** @psalm-suppress PossiblyNullReference - we check if circlesManager is null */ $circle = $this->circlesManager->getCircle($circleId); } catch (CircleNotFoundException $e) { throw new NotFoundException($e->getMessage(), 0, $e); @@ -167,8 +170,9 @@ public function findCircle(string $name, string $userId, int $level = Member::LE * @throws NotPermittedException */ private function existsCircle(string $name): bool { - $this->circlesManager->startSuperSession(); + $this->startSuperSession(); try { + /** @psalm-suppress PossiblyNullReference - we check if circlesManager is null */ $circles = self::useProbeCircles() ? $this->circlesManager->probeCircles() : $this->circlesManager->getCircles(); @@ -199,6 +203,7 @@ public function createCircle(string $name, string $userId): Circle { throw new CircleExistsException('A team with that name exists'); } $this->startSession($userId); + /** @psalm-suppress PossiblyNullReference - we check if circlesManager is null */ $circle = $this->circlesManager->createCircle($name, null, false, false); } catch (CircleNotFoundException $e) { throw new NotFoundException($e->getMessage(), 0, $e); @@ -217,8 +222,9 @@ public function createCircle(string $name, string $userId): Circle { * @throws NotPermittedException */ public function flagCircleAsAppManaged(string $circleId): void { - $this->circlesManager->startSuperSession(); + $this->startSuperSession(); try { + /** @psalm-suppress PossiblyNullReference - we check if circlesManager is null */ $this->circlesManager->flagAsAppManaged($circleId); } catch (RequestBuilderException| FederatedItemException $e) { @@ -231,8 +237,9 @@ public function flagCircleAsAppManaged(string $circleId): void { * @throws NotPermittedException */ public function unflagCircleAsAppManaged(string $circleId): void { - $this->circlesManager->startSuperSession(); + $this->startSuperSession(); try { + /** @psalm-suppress PossiblyNullReference - we check if circlesManager is null */ $this->circlesManager->flagAsAppManaged($circleId, false); } catch (RequestBuilderException| FederatedItemException $e) { @@ -253,6 +260,7 @@ public function destroyCircle(string $circleId, string $userId): void { try { $this->unflagCircleAsAppManaged($circleId); $this->startSession($userId); + /** @psalm-suppress PossiblyNullReference - we check if circlesManager is null */ $this->circlesManager->destroyCircle($circleId); } catch (CircleNotFoundException $e) { throw new NotFoundException($e->getMessage(), 0, $e); diff --git a/lib/Service/CollectiveShareService.php b/lib/Service/CollectiveShareService.php index 50072f356..746593c8a 100644 --- a/lib/Service/CollectiveShareService.php +++ b/lib/Service/CollectiveShareService.php @@ -231,9 +231,7 @@ public function updateShare(string $userId, Collective $collective, ?PageInfo $p $pageId = $pageInfo->getId(); } - if (null === $share = $this->collectiveShareMapper->findOneByCollectiveIdAndTokenAndUser($collective->getId(), $pageId, $token, $userId)) { - throw new NotFoundException($this->l10n->t('Share not found for user')); - } + $share = $this->collectiveShareMapper->findOneByCollectiveIdAndTokenAndUser($collective->getId(), $pageId, $token, $userId); try { $folderShare = $this->shareManager->getShareByToken($token); diff --git a/lib/Service/TemplateService.php b/lib/Service/TemplateService.php index ffc03a004..fef867d44 100644 --- a/lib/Service/TemplateService.php +++ b/lib/Service/TemplateService.php @@ -78,7 +78,7 @@ public function getTemplates(int $collectiveId, string $userId): array { * @throws NotFoundException * @throws NotPermittedException */ - public function create(int $collectiveId, ?int $parentId, string $title, string $userId): PageInfo { + public function create(int $collectiveId, int $parentId, string $title, string $userId): PageInfo { $parentId = $parentId !== 0 ? $parentId : PageService::getIndexPageFile($this->getTemplateFolder($collectiveId, $userId))->getId(); diff --git a/lib/Team/CollectiveTeamResourceProvider.php b/lib/Team/CollectiveTeamResourceProvider.php index 1f80da991..e3539a8a8 100644 --- a/lib/Team/CollectiveTeamResourceProvider.php +++ b/lib/Team/CollectiveTeamResourceProvider.php @@ -65,7 +65,7 @@ public function getSharedWith(string $teamId): array { public function isSharedWithTeam(string $teamId, string $resourceId): bool { $teamIds = $this->getTeamsForResource($resourceId); - return in_array($teamId, $teamIds); + return in_array($teamId, $teamIds, true); } public function getTeamsForResource(string $resourceId): array { @@ -74,7 +74,6 @@ public function getTeamsForResource(string $resourceId): array { } catch (NotFoundException|NotPermittedException) { return []; } - $circleId = $collective->getCircleId(); - return $circleId === null ? [] : [$circleId]; + return [$collective->getCircleId()]; } } diff --git a/lib/Versions/CollectiveVersionsExpireManager.php b/lib/Versions/CollectiveVersionsExpireManager.php index 2f01de975..69187ef1a 100644 --- a/lib/Versions/CollectiveVersionsExpireManager.php +++ b/lib/Versions/CollectiveVersionsExpireManager.php @@ -51,7 +51,7 @@ public function getAllFolders(): array { $qb = $this->connection->getQueryBuilder(); $qb->select('co.id AS id', 'circle_unique_id') ->from('collectives', 'co'); - $rows = $qb->execute()->fetchAll(); + $rows = $qb->executeQuery()->fetchAll(); $folderMap = []; try { diff --git a/lib/Versions/ExpireManager.php b/lib/Versions/ExpireManager.php index b7d3f2676..43f9cde8c 100644 --- a/lib/Versions/ExpireManager.php +++ b/lib/Versions/ExpireManager.php @@ -11,6 +11,7 @@ use OCA\Collectives\Service\MissingDependencyException; use OCA\Files_Versions\Expiration; +use OCA\Files_Versions\Versions\IMetadataVersion; use OCA\Files_Versions\Versions\IVersion; use OCP\AppFramework\QueryException; use Psr\Container\ContainerInterface; @@ -44,43 +45,49 @@ public function __construct(ContainerInterface $appContainer) { } /** - * get list of files we want to archive + * Get list of files we want to expire + * + * @param IVersion[] $versions + * @return IVersion[] */ protected function getAutoExpireList(int $time, array $versions): array { if (!$versions) { return []; } + $toDelete = []; // versions we want to delete - // ensure the versions are sorted by newest first - usort($versions, static fn (IVersion $a, IVersion $b) => $b->getTimestamp() <=> $a->getTimestamp()); + // ensure the versions are sorted newest first + usort($versions, static fn (IVersion $a, IVersion $b): int => $b->getTimestamp() <=> $a->getTimestamp()); $interval = 1; $step = self::MAX_VERSIONS_PER_INTERVAL[$interval]['step']; - if (self::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter'] === -1) { - $nextInterval = -1; - } else { - $nextInterval = $time - self::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter']; - } + $nextInterval = $time - self::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter']; + /** @var IVersion $firstVersion */ $firstVersion = array_shift($versions); $prevTimestamp = $firstVersion->getTimestamp(); $nextVersion = $firstVersion->getTimestamp() - $step; foreach ($versions as $version) { $newInterval = true; - while ($newInterval && $interval <= 5) { + while ($newInterval) { if ($nextInterval === -1 || $prevTimestamp > $nextInterval) { if ($version->getTimestamp() > $nextVersion) { - // distance between two versions is too small, mark to delete - $toDelete[] = $version; + // Do not expire versions with a label. + if (!($version instanceof IMetadataVersion) || $version->getMetadataValue('label') === null || $version->getMetadataValue('label') === '') { + //distance between two version too small, mark to delete + $toDelete[] = $version; + } } else { $nextVersion = $version->getTimestamp() - $step; $prevTimestamp = $version->getTimestamp(); } + $newInterval = false; // version checked so we can move to the next one } else { // time to move on to the next interval $interval++; + /** @psalm-suppress InvalidArrayOffset We know that $interval is <= 6 thanks to the -1 intervalEndsAfter in the last step */ $step = self::MAX_VERSIONS_PER_INTERVAL[$interval]['step']; $nextVersion = $prevTimestamp - $step; if (self::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter'] === -1) { @@ -88,6 +95,7 @@ protected function getAutoExpireList(int $time, array $versions): array { } else { $nextInterval = $time - self::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter']; } + $newInterval = true; // we changed the interval -> check same version with new interval } } @@ -97,6 +105,8 @@ protected function getAutoExpireList(int $time, array $versions): array { } /** + * @param IVersion[] $versions + * @return IVersion[] * @throws MissingDependencyException */ public function getExpiredVersion(array $versions, int $time, bool $quotaExceeded): array { @@ -110,10 +120,22 @@ public function getExpiredVersion(array $versions, int $time, bool $quotaExceede $autoExpire = []; } - $versionsLeft = array_udiff($versions, $autoExpire, static fn (IVersion $a, IVersion $b) => ($a->getRevisionId() <=> $b->getRevisionId()) * - ($a->getSourceFile()->getId() <=> $b->getSourceFile()->getId())); + $versionsLeft = array_udiff($versions, $autoExpire, static fn (IVersion $a, IVersion $b): int => ($a->getRevisionId() <=> $b->getRevisionId()) * + ($a->getSourceFile()->getId() <=> $b->getSourceFile()->getId())); + + $expired = array_filter($versionsLeft, function (IVersion $version) use ($quotaExceeded): bool { + // Do not expire current version. + if ($version->getTimestamp() === $version->getSourceFile()->getMtime()) { + return false; + } - $expired = array_filter($versionsLeft, fn (IVersion $version) => $this->expiration->isExpired($version->getTimestamp(), $quotaExceeded)); + // Do not expire versions with a label. + if ($version instanceof IMetadataVersion && $version->getMetadataValue('label') !== null && $version->getMetadataValue('label') !== '') { + return false; + } + /** @psalm-suppress PossiblyNullReference - we checked if $this->expiration is null above */ + return $this->expiration->isExpired($version->getTimestamp(), $quotaExceeded); + }); return array_merge($autoExpire, $expired); } diff --git a/lib/Versions/VersionsBackend.php b/lib/Versions/VersionsBackend.php index a4a3ae8da..d07dcc643 100644 --- a/lib/Versions/VersionsBackend.php +++ b/lib/Versions/VersionsBackend.php @@ -62,7 +62,7 @@ public function getVersionsForFile(IUser $user, FileInfo $file): array { (int)$versionFile->getName(), (int)$versionFile->getName(), $file->getName(), - $versionFile->getSize(), + (int)$versionFile->getSize(), $versionFile->getMimetype(), $versionFile->getPath(), $file, diff --git a/psalm.xml b/psalm.xml index 5949f5d36..05ed9f8c9 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,46 +1,46 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + diff --git a/tests/Unit/Controller/SettingsControllerTest.php b/tests/Unit/Controller/SettingsControllerTest.php index 81a30fe2e..06985159b 100644 --- a/tests/Unit/Controller/SettingsControllerTest.php +++ b/tests/Unit/Controller/SettingsControllerTest.php @@ -47,11 +47,6 @@ public function testSetUserSettingInvalidSetting(): void { self::assertEquals($response, $this->settingsController->setUserSetting('nonexistent', 'value')); } - public function testSetUserSettingsEmptyValue(): void { - $response = new DataResponse('Empty value for setting user_folder', Http::STATUS_BAD_REQUEST); - self::assertEquals($response, $this->settingsController->setUserSetting('user_folder', null)); - } - public function testSetUserSettingsEmptyString(): void { $response = new DataResponse('Invalid collectives folder path', Http::STATUS_BAD_REQUEST); self::assertEquals($response, $this->settingsController->setUserSetting('user_folder', '')); diff --git a/tests/stub.phpstub b/tests/stub.phpstub index 0ef2f4064..0dd3c9164 100644 --- a/tests/stub.phpstub +++ b/tests/stub.phpstub @@ -11,11 +11,11 @@ namespace { use OCP\IServerContainer; class OC { - static $CLI = false; - /** @var string */ - static $WEBROOT; - /** @var IServerContainer */ - static $server; + static $CLI = false; + /** @var string */ + static $WEBROOT; + /** @var IServerContainer */ + static $server; } } @@ -25,16 +25,16 @@ namespace OC\Files\Node { /** @return FileInfo|\ArrayAccess */ public function getFileInfo() {} - /** @return \OCP\Files\Mount\IMountPoint */ - public function getMountPoint() {} + /** @return \OCP\Files\Mount\IMountPoint */ + public function getMountPoint() {} } } namespace OC\Hooks { class Emitter { - public function emit(string $class, string $value, array $option) {} - /** Closure $closure */ - public function listen(string $class, string $value, $closure) {} + public function emit(string $class, string $value, array $option) {} + /** Closure $closure */ + public function listen(string $class, string $value, $closure) {} } class BasicEmitter extends Emitter { } @@ -60,17 +60,17 @@ namespace OC\Core\Command { use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class Base { - public const OUTPUT_FORMAT_PLAIN = 'plain'; - public const OUTPUT_FORMAT_JSON = 'json'; - public const OUTPUT_FORMAT_JSON_PRETTY = 'json_pretty'; - - public function __construct() {} - protected function configure() {} - public function run(InputInterface $input, OutputInterface $output) {} - public function setName(string $name) {} - public function getHelper(string $name) {} - protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, $items, $prefix = ' - ') { - } + public const OUTPUT_FORMAT_PLAIN = 'plain'; + public const OUTPUT_FORMAT_JSON = 'json'; + public const OUTPUT_FORMAT_JSON_PRETTY = 'json_pretty'; + + public function __construct() {} + protected function configure() {} + public function run(InputInterface $input, OutputInterface $output) {} + public function setName(string $name) {} + public function getHelper(string $name) {} + protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, $items, $prefix = ' - ') { + } } } @@ -114,9 +114,9 @@ namespace Symfony\Component\Console\Question { namespace Symfony\Component\Console\Output { class OutputInterface { - public const VERBOSITY_VERBOSE = 1; - public function writeln(string $text, int $flat = 0) {} - public function write($messages, $newline = false, $options = 0) {} + public const VERBOSITY_VERBOSE = 1; + public function writeln(string $text, int $flat = 0) {} + public function write($messages, $newline = false, $options = 0) {} } } @@ -128,11 +128,11 @@ namespace OC\Collaboration\Reference { use OCP\Collaboration\Reference\IReferenceManager; class LinkReferenceProvider { - public function resolveReference(string $referenceText) {} + public function resolveReference(string $referenceText) {} } class ReferenceManager implements IReferenceManager { - public function invalidateCache(string $cachePrefix, ?string $cacheKey = null): void; + public function invalidateCache(string $cachePrefix, ?string $cacheKey = null): void; } } @@ -145,40 +145,40 @@ namespace OC\Files\Cache { use OCP\Files\IMimeTypeLoader; class Cache implements ICache { - /** - * @param \OCP\Files\Cache\ICache $cache - */ - public function __construct($cache) { - $this->cache = $cache; - } - public function getNumericStorageId() { } - public function get() { } - public function getIncomplete() {} - public function getPathById($id) {} - public function getAll() {} - public function get($file) {} - public function getFolderContents($folder) {} - public function getFolderContentsById($fileId) {} - public function put($file, array $data) {} - public function insert($file, array $data) {} - public function update($id, array $data) {} - public function getId($file) {} - public function getParentId($file) {} - public function inCache($file) {} - public function remove($file) {} - public function move($source, $target) {} - public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {} - public function clear() {} - public function getStatus($file) {} - public function search($pattern) {} - public function searchByMime($mimetype) {} - public function searchQuery(ISearchQuery $query) {} - public function correctFolderSize($path, $data = null, $isBackgroundScan = false) {} - public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int {} - public function normalize($path) {} - public function getQueryFilterForStorage(): ISearchOperator {} - public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEntry {} - public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader): ICacheEntry {} + /** + * @param \OCP\Files\Cache\ICache $cache + */ + public function __construct($cache) { + $this->cache = $cache; + } + public function getNumericStorageId() { } + public function get() { } + public function getIncomplete() {} + public function getPathById($id) {} + public function getAll() {} + public function get($file) {} + public function getFolderContents($folder) {} + public function getFolderContentsById($fileId) {} + public function put($file, array $data) {} + public function insert($file, array $data) {} + public function update($id, array $data) {} + public function getId($file) {} + public function getParentId($file) {} + public function inCache($file) {} + public function remove($file) {} + public function move($source, $target) {} + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {} + public function clear() {} + public function getStatus($file) {} + public function search($pattern) {} + public function searchByMime($mimetype) {} + public function searchQuery(ISearchQuery $query) {} + public function correctFolderSize($path, $data = null, $isBackgroundScan = false) {} + public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int {} + public function normalize($path) {} + public function getQueryFilterForStorage(): ISearchOperator {} + public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEntry {} + public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader): ICacheEntry {} } } @@ -193,24 +193,24 @@ namespace OC\Files { use OCP\IUser; class Filesystem { - public static function addStorageWrapper(string $wrapperName, callable $wrapper, int $priority = 50) { - } + public static function addStorageWrapper(string $wrapperName, callable $wrapper, int $priority = 50) { + } } class FileInfo implements \OCP\Files\FileInfo { - /** - * @param string|boolean $path - * @param \OCP\Files\Storage\IStorage $storage - * @param string $internalPath - * @param array|ICacheEntry $data - * @param \OCP\Files\Mount\IMountPoint $mount - * @param \OCP\IUser|null $owner - */ - public function __construct($path, $storage, $internalPath, $data, $mount, $owner = null) {} + /** + * @param string|boolean $path + * @param \OCP\Files\Storage\IStorage $storage + * @param string $internalPath + * @param array|ICacheEntry $data + * @param \OCP\Files\Mount\IMountPoint $mount + * @param \OCP\IUser|null $owner + */ + public function __construct($path, $storage, $internalPath, $data, $mount, $owner = null) {} } class View { - public function __construct(string $path) {} - public function unlink($path) {} + public function __construct(string $path) {} + public function unlink($path) {} public function is_dir($path): bool {} public function mkdir($path) {} public function getRoot(): string {} @@ -223,7 +223,7 @@ namespace OC\User { use OCP\IUser; use OCP\UserInterface; class User implements IUser { - public function __construct(string $uid, ?UserInterface $backend, IEventDispatcher $dispatcher, $emitter = null, IConfig $config = null, $urlGenerator = null) {} + public function __construct(string $uid, ?UserInterface $backend, IEventDispatcher $dispatcher, $emitter = null, IConfig $config = null, $urlGenerator = null) {} } } @@ -252,28 +252,28 @@ namespace OC\BackgroundJob { use OCP\ILogger; abstract class TimedJob implements IJob { - public function execute(IJobList $jobList, ILogger $logger = null) { - } + public function execute(IJobList $jobList, ILogger $logger = null) { + } - abstract protected function run($argument); + abstract protected function run($argument); - public function setId(int $id) { - } + public function setId(int $id) { + } - public function setLastRun(int $lastRun) { - } + public function setLastRun(int $lastRun) { + } - public function setArgument($argument) { - } + public function setArgument($argument) { + } - public function getId() { - } + public function getId() { + } - public function getLastRun() { - } + public function getLastRun() { + } - public function getArgument() { - } + public function getArgument() { + } } } @@ -284,122 +284,122 @@ namespace OC\Files\Mount { use OCP\Files\Mount\IMountPoint; class MountPoint implements IMountPoint { - /** - * @var \OC\Files\Storage\Storage $storage - */ - protected $storage = null; - protected $class; - protected $storageId; - protected $rootId = null; - - /** @var int|null */ - protected $mountId; - - /** - * @param string|\OCP\Files\Storage\IStorage $storage - * @param string $mountpoint - * @param array $arguments (optional) configuration for the storage backend - * @param \OCP\Files\Storage\IStorageFactory $loader - * @param array $mountOptions mount specific options - * @param int|null $mountId - * @throws \Exception - */ - public function __construct($storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) { - throw new \Exception('stub'); - } - - /** - * get complete path to the mount point, relative to data/ - * - * @return string - */ - public function getMountPoint() { - throw new \Exception('stub'); - } - - /** - * Sets the mount point path, relative to data/ - * - * @param string $mountPoint new mount point - */ - public function setMountPoint($mountPoint) { - throw new \Exception('stub'); - } - - /** - * @return \OCP\Files\Storage\IStorage - */ - public function getStorage() { - throw new \Exception('stub'); - } - - /** - * @return string - */ - public function getStorageId() { - throw new \Exception('stub'); - } - - /** - * @return int - */ - public function getNumericStorageId() { - throw new \Exception('stub'); - } - - /** - * @param string $path - * @return string - */ - public function getInternalPath($path) { - throw new \Exception('stub'); - } - - /** - * @param callable $wrapper - */ - public function wrapStorage($wrapper) { - throw new \Exception('stub'); - } - - /** - * Get a mount option - * - * @param string $name Name of the mount option to get - * @param mixed $default Default value for the mount option - * @return mixed - */ - public function getOption($name, $default) { - throw new \Exception('stub'); - } - - /** - * Get all options for the mount - * - * @return array - */ - public function getOptions() { - throw new \Exception('stub'); - } - - /** - * @return int - */ - public function getStorageRootId() { - throw new \Exception('stub'); - } - - public function getMountId() { - throw new \Exception('stub'); - } - - public function getMountType() { - throw new \Exception('stub'); - } - - public function getMountProvider(): string { - throw new \Exception('stub'); - } + /** + * @var \OC\Files\Storage\Storage $storage + */ + protected $storage = null; + protected $class; + protected $storageId; + protected $rootId = null; + + /** @var int|null */ + protected $mountId; + + /** + * @param string|\OCP\Files\Storage\IStorage $storage + * @param string $mountpoint + * @param array $arguments (optional) configuration for the storage backend + * @param \OCP\Files\Storage\IStorageFactory $loader + * @param array $mountOptions mount specific options + * @param int|null $mountId + * @throws \Exception + */ + public function __construct($storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) { + throw new \Exception('stub'); + } + + /** + * get complete path to the mount point, relative to data/ + * + * @return string + */ + public function getMountPoint() { + throw new \Exception('stub'); + } + + /** + * Sets the mount point path, relative to data/ + * + * @param string $mountPoint new mount point + */ + public function setMountPoint($mountPoint) { + throw new \Exception('stub'); + } + + /** + * @return \OCP\Files\Storage\IStorage + */ + public function getStorage() { + throw new \Exception('stub'); + } + + /** + * @return string + */ + public function getStorageId() { + throw new \Exception('stub'); + } + + /** + * @return int + */ + public function getNumericStorageId() { + throw new \Exception('stub'); + } + + /** + * @param string $path + * @return string + */ + public function getInternalPath($path) { + throw new \Exception('stub'); + } + + /** + * @param callable $wrapper + */ + public function wrapStorage($wrapper) { + throw new \Exception('stub'); + } + + /** + * Get a mount option + * + * @param string $name Name of the mount option to get + * @param mixed $default Default value for the mount option + * @return mixed + */ + public function getOption($name, $default) { + throw new \Exception('stub'); + } + + /** + * Get all options for the mount + * + * @return array + */ + public function getOptions() { + throw new \Exception('stub'); + } + + /** + * @return int + */ + public function getStorageRootId() { + throw new \Exception('stub'); + } + + public function getMountId() { + throw new \Exception('stub'); + } + + public function getMountType() { + throw new \Exception('stub'); + } + + public function getMountProvider(): string { + throw new \Exception('stub'); + } } } @@ -411,204 +411,204 @@ namespace OC\Files\Storage\Wrapper{ use OCP\Files\Storage\IStorage; class Wrapper implements IStorage { - public function __construct(array $parameters) { - } + public function __construct(array $parameters) { + } - public function getWrapperStorage(): ?IStorage {} + public function getWrapperStorage(): ?IStorage {} - public function getId() {} + public function getId() {} - public function mkdir($path) {} + public function mkdir($path) {} - public function rmdir($path) {} + public function rmdir($path) {} - public function opendir($path) { - throw new \Exception('stub'); - } + public function opendir($path) { + throw new \Exception('stub'); + } - public function is_dir($path) { - throw new \Exception('stub'); - } + public function is_dir($path) { + throw new \Exception('stub'); + } - public function is_file($path) { - throw new \Exception('stub'); - } + public function is_file($path) { + throw new \Exception('stub'); + } - public function stat($path) { - throw new \Exception('stub'); - } + public function stat($path) { + throw new \Exception('stub'); + } - public function filetype($path) { - throw new \Exception('stub'); - } + public function filetype($path) { + throw new \Exception('stub'); + } - public function filesize($path) { - throw new \Exception('stub'); - } + public function filesize($path) { + throw new \Exception('stub'); + } - public function isCreatable($path) { - throw new \Exception('stub'); - } + public function isCreatable($path) { + throw new \Exception('stub'); + } - public function isReadable($path) { - throw new \Exception('stub'); - } + public function isReadable($path) { + throw new \Exception('stub'); + } - public function isUpdatable($path) { - throw new \Exception('stub'); - } + public function isUpdatable($path) { + throw new \Exception('stub'); + } - public function isDeletable($path) { - throw new \Exception('stub'); - } + public function isDeletable($path) { + throw new \Exception('stub'); + } - public function isSharable($path) { - throw new \Exception('stub'); - } + public function isSharable($path) { + throw new \Exception('stub'); + } - public function getPermissions($path) { - throw new \Exception('stub'); - } + public function getPermissions($path) { + throw new \Exception('stub'); + } - public function file_exists($path) { - throw new \Exception('stub'); - } + public function file_exists($path) { + throw new \Exception('stub'); + } - public function filemtime($path) { - throw new \Exception('stub'); - } + public function filemtime($path) { + throw new \Exception('stub'); + } - public function file_get_contents($path) { - throw new \Exception('stub'); - } + public function file_get_contents($path) { + throw new \Exception('stub'); + } - public function file_put_contents($path, $data) { - throw new \Exception('stub'); - } + public function file_put_contents($path, $data) { + throw new \Exception('stub'); + } - public function unlink($path) { - throw new \Exception('stub'); - } + public function unlink($path) { + throw new \Exception('stub'); + } - public function rename($path1, $path2) { - throw new \Exception('stub'); - } + public function rename($path1, $path2) { + throw new \Exception('stub'); + } - public function copy($path1, $path2) { - throw new \Exception('stub'); - } + public function copy($path1, $path2) { + throw new \Exception('stub'); + } - public function fopen($path, $mode) { - throw new \Exception('stub'); - } + public function fopen($path, $mode) { + throw new \Exception('stub'); + } - public function getMimeType($path) { - throw new \Exception('stub'); - } + public function getMimeType($path) { + throw new \Exception('stub'); + } - public function hash($type, $path, $raw = false) { - throw new \Exception('stub'); - } + public function hash($type, $path, $raw = false) { + throw new \Exception('stub'); + } - public function free_space($path) { - throw new \Exception('stub'); - } + public function free_space($path) { + throw new \Exception('stub'); + } - public function touch($path, $mtime = null) { - throw new \Exception('stub'); - } + public function touch($path, $mtime = null) { + throw new \Exception('stub'); + } - public function getLocalFile($path) { - throw new \Exception('stub'); - } + public function getLocalFile($path) { + throw new \Exception('stub'); + } - public function hasUpdated($path, $time) { - throw new \Exception('stub'); - } + public function hasUpdated($path, $time) { + throw new \Exception('stub'); + } - public function getETag($path) { - throw new \Exception('stub'); - } + public function getETag($path) { + throw new \Exception('stub'); + } - public function isLocal() { - throw new \Exception('stub'); - } + public function isLocal() { + throw new \Exception('stub'); + } - public function instanceOfStorage($class) { - throw new \Exception('stub'); - } + public function instanceOfStorage($class) { + throw new \Exception('stub'); + } - public function getDirectDownload($path) { - throw new \Exception('stub'); - } + public function getDirectDownload($path) { + throw new \Exception('stub'); + } - public function verifyPath($path, $fileName) { - throw new \Exception('stub'); - } + public function verifyPath($path, $fileName) { + throw new \Exception('stub'); + } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { - throw new \Exception('stub'); - } + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + throw new \Exception('stub'); + } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { - throw new \Exception('stub'); - } + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + throw new \Exception('stub'); + } - public function test() { - throw new \Exception('stub'); - } + public function test() { + throw new \Exception('stub'); + } - public function getAvailability() { - throw new \Exception('stub'); - } + public function getAvailability() { + throw new \Exception('stub'); + } - public function setAvailability($isAvailable) { - throw new \Exception('stub'); - } + public function setAvailability($isAvailable) { + throw new \Exception('stub'); + } - public function getOwner($path) { - throw new \Exception('stub'); - } + public function getOwner($path) { + throw new \Exception('stub'); + } - public function getCache() { - throw new \Exception('stub'); - } + public function getCache() { + throw new \Exception('stub'); + } - public function getPropagator() { - throw new \Exception('stub'); - } + public function getPropagator() { + throw new \Exception('stub'); + } - public function getScanner() { - throw new \Exception('stub'); - } + public function getScanner() { + throw new \Exception('stub'); + } - public function getUpdater() { - throw new \Exception('stub'); - } + public function getUpdater() { + throw new \Exception('stub'); + } - public function getWatcher() { - throw new \Exception('stub'); - } + public function getWatcher() { + throw new \Exception('stub'); + } public function needsPartFile(): bool { - throw new \Exception('stub'); + throw new \Exception('stub'); } public function setOwner(?string $user): void { - throw new \Exception('stub'); + throw new \Exception('stub'); } } class Jail extends Wrapper { - public function getUnjailedPath(string $path): string {} + public function getUnjailedPath(string $path): string {} } class Quota extends Wrapper { - public function getQuota() {} + public function getQuota() {} } class PermissionsMask extends Wrapper { - public function getQuota() {} + public function getQuota() {} } } @@ -618,37 +618,37 @@ namespace OCA\Viewer\Event { namespace OCA\Circles\Model { class Member { - public const LEVEL_NONE = 0; - public const LEVEL_MEMBER = 1; - public const LEVEL_MODERATOR = 4; - public const LEVEL_ADMIN = 8; - public const LEVEL_OWNER = 9; + public const LEVEL_NONE = 0; + public const LEVEL_MEMBER = 1; + public const LEVEL_MODERATOR = 4; + public const LEVEL_ADMIN = 8; + public const LEVEL_OWNER = 9; - public const TYPE_SINGLE = 0; - public const TYPE_USER = 1; - public const TYPE_GROUP = 2; - public const TYPE_MAIL = 4; - public const TYPE_CONTACT = 8; - public const TYPE_CIRCLE = 16; - public const TYPE_APP = 10000; + public const TYPE_SINGLE = 0; + public const TYPE_USER = 1; + public const TYPE_GROUP = 2; + public const TYPE_MAIL = 4; + public const TYPE_CONTACT = 8; + public const TYPE_CIRCLE = 16; + public const TYPE_APP = 10000; - public const ALLOWING_ALL_TYPES = 31; + public const ALLOWING_ALL_TYPES = 31; - public const APP_CIRCLES = 10001; - public const APP_OCC = 10002; - public const APP_DEFAULT = 11000; + public const APP_CIRCLES = 10001; + public const APP_OCC = 10002; + public const APP_DEFAULT = 11000; - public function getSingleId(): string {} - public function getUserType(): int {} - public function getLevel(): int {} + public function getSingleId(): string {} + public function getUserType(): int {} + public function getLevel(): int {} } class Circle { - public function getName(): string {} - public function getSingleId(): string {} - public function getSanitizedName(): string {} - public function getMembers(): array {} - public function getInitiator(): Member {} + public function getName(): string {} + public function getSingleId(): string {} + public function getSanitizedName(): string {} + public function getMembers(int $limit = 0): array {} + public function getInitiator(): Member {} } class FederatedUser { @@ -660,7 +660,7 @@ namespace OCA\Circles\Model\Probes { public function mustBeMember(bool $must = true): self {} } class DataProbe { - public const INITIATOR = 'h'; + public const INITIATOR = 'h'; public function add(string $key, array $path = []): self {} } } @@ -703,16 +703,16 @@ namespace OCA\Circles { use OCA\Circles\Model\Probes\CircleProbe; use OCA\Circles\Model\Probes\DataProbe; class CirclesManager { - public function getFederatedUser(string $federatedId, int $type = Member::TYPE_SINGLE): FederatedUser {} - public function startSession(?FederatedUser $federatedUser = null): void {} - public function startSuperSession(): void {} - public function stopSession(): void {} + public function getFederatedUser(string $federatedId, int $type = Member::TYPE_SINGLE): FederatedUser {} + public function startSession(?FederatedUser $federatedUser = null): void {} + public function startSuperSession(): void {} + public function stopSession(): void {} public function createCircle(string $name, ?FederatedUser $owner = null, bool $personal = false, bool $local = false): Circle {} - public function destroyCircle(string $singleId): void {} - public function getCircles(?CircleProbe $probe = null): array {} - public function getCircle(string $singleId, ?CircleProbe $probe = null): Circle {} - public function flagAsAppManaged(string $circleId, bool $enabled = true): void {} - public function probeCircles(?CircleProbe $circleProbe = null, ?DataProbe $dataProbe = null): array {} + public function destroyCircle(string $singleId): void {} + public function getCircles(?CircleProbe $probe = null, bool $refreshCache = false): array {} + public function getCircle(string $singleId, ?CircleProbe $probe = null): Circle {} + public function flagAsAppManaged(string $circleId, bool $enabled = true): void {} + public function probeCircles(?CircleProbe $circleProbe = null, ?DataProbe $dataProbe = null): array {} } } @@ -723,126 +723,130 @@ namespace OCA\Files_Versions\Versions { use OCP\Files\Storage\IStorage; use OCP\IUser; + interface IMetadataVersion { + public function getMetadataValue(string $key): ?string; + } + interface IVersionBackend { - public function useBackendForStorage(IStorage $storage): bool; + public function useBackendForStorage(IStorage $storage): bool; - /** - * @return IVersion[] - */ - public function getVersionsForFile(IUser $user, FileInfo $file): array; + /** + * @return IVersion[] + */ + public function getVersionsForFile(IUser $user, FileInfo $file): array; - public function createVersion(IUser $user, FileInfo $file); + public function createVersion(IUser $user, FileInfo $file); - public function rollback(IVersion $version); + public function rollback(IVersion $version); - /** - * @return resource|false - * @throws NotFoundException - */ - public function read(IVersion $version); + /** + * @return resource|false + * @throws NotFoundException + */ + public function read(IVersion $version); - /** - * @param int|string $revision - */ - public function getVersionFile(IUser $user, FileInfo $sourceFile, $revision): ?File; + /** + * @param int|string $revision + */ + public function getVersionFile(IUser $user, FileInfo $sourceFile, $revision): ?File; } interface IVersion { - public function getBackend(): IVersionBackend; + public function getBackend(): IVersionBackend; - public function getSourceFile(): FileInfo; + public function getSourceFile(): FileInfo; - /** - * @return int|string - */ - public function getRevisionId(); + /** + * @return int|string + */ + public function getRevisionId(); - public function getTimestamp(): int; + public function getTimestamp(): int; - public function getSize(): int; + public function getSize(): int; - public function getSourceFileName(): string; + public function getSourceFileName(): string; - public function getMimeType(): string; + public function getMimeType(): string; - public function getVersionPath(): string; + public function getVersionPath(): string; - public function getUser(): IUser; + public function getUser(): IUser; } class Version implements IVersion { - public function __construct( - int $timestamp, - $revisionId, - string $name, - int $size, - string $mimetype, - string $path, - FileInfo $sourceFileInfo, - IVersionBackend $backend, - IUser $user - ) { - } + public function __construct( + int $timestamp, + $revisionId, + string $name, + int $size, + string $mimetype, + string $path, + FileInfo $sourceFileInfo, + IVersionBackend $backend, + IUser $user + ) { + } - public function getBackend(): IVersionBackend { - throw new \Exception('stub'); - } + public function getBackend(): IVersionBackend { + throw new \Exception('stub'); + } - public function getSourceFile(): FileInfo { - throw new \Exception('stub'); - } + public function getSourceFile(): FileInfo { + throw new \Exception('stub'); + } - public function getRevisionId() { - throw new \Exception('stub'); - } + public function getRevisionId() { + throw new \Exception('stub'); + } - public function getTimestamp(): int { - throw new \Exception('stub'); - } + public function getTimestamp(): int { + throw new \Exception('stub'); + } - public function getSize(): int { - throw new \Exception('stub'); - } + public function getSize(): int { + throw new \Exception('stub'); + } - public function getSourceFileName(): string { - throw new \Exception('stub'); - } + public function getSourceFileName(): string { + throw new \Exception('stub'); + } - public function getMimeType(): string { - throw new \Exception('stub'); - } + public function getMimeType(): string { + throw new \Exception('stub'); + } - public function getVersionPath(): string { - throw new \Exception('stub'); - } + public function getVersionPath(): string { + throw new \Exception('stub'); + } - public function getUser(): IUser { - throw new \Exception('stub'); - } + public function getUser(): IUser { + throw new \Exception('stub'); + } } } namespace OCA\Files_Versions { class Expiration { - public function shouldAutoExpire() { } + public function shouldAutoExpire() { } - /** - * @param int $timestamp - * @param bool $quotaExceeded - * @return bool - */ - public function isExpired($timestamp, $quotaExceeded = false) {} + /** + * @param int $timestamp + * @param bool $quotaExceeded + * @return bool + */ + public function isExpired($timestamp, $quotaExceeded = false) {} } } namespace OCA\Files_Trashbin { class Expiration { - /** - * @param int $timestamp - * @param bool $quotaExceeded - * @return bool - */ - public function isExpired($timestamp, $quotaExceeded = false) {} + /** + * @param int $timestamp + * @param bool $quotaExceeded + * @return bool + */ + public function isExpired($timestamp, $quotaExceeded = false) {} } }