rootFolder->getUserFolder($owner); } catch (NoUserException $e) { return false; } $node = $userFolder->getFirstNodeById($fileId); return $node !== null; } /** * @param int[] $ids * @return void */ public function deleteShares(array $ids): void { $query = $this->connection->getQueryBuilder(); $query->delete('share') ->where($query->expr()->in('id', $query->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))); $query->executeStatement(); } public function fileExists(int $fileId): bool { $query = $this->connection->getQueryBuilder(); $query->select('fileid') ->from('filecache') ->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); return $query->executeQuery()->fetchOne() !== false; } /** * @return \Traversable */ public function getAllShares() { $query = $this->connection->getQueryBuilder(); $query->select('id', 'file_source', 'uid_owner', 'file_target') ->from('share') ->where($query->expr()->eq('item_type', $query->createNamedParameter('file'))) ->orWhere($query->expr()->eq('item_type', $query->createNamedParameter('folder'))); $result = $query->executeQuery(); while ($row = $result->fetch()) { yield [ 'id' => (int)$row['id'], 'owner' => (string)$row['uid_owner'], 'fileid' => (int)$row['file_source'], 'target' => (string)$row['file_target'], ]; } } public function findOwner(int $fileId): ?string { $mounts = $this->userMountCache->getMountsForFileId($fileId); if (!$mounts) { return null; } foreach ($mounts as $mount) { $userHomeMountPoint = '/' . $mount->getUser()->getUID() . '/'; if ($mount->getMountPoint() === $userHomeMountPoint) { return $mount->getUser()->getUID(); } } return null; } public function updateShareOwner(int $shareId, string $owner): void { $query = $this->connection->getQueryBuilder(); $query->update('share') ->set('uid_owner', $query->createNamedParameter($owner)) ->where($query->expr()->eq('id', $query->createNamedParameter($shareId, IQueryBuilder::PARAM_INT))); $query->executeStatement(); } }