aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib/OrphanHelper.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/lib/OrphanHelper.php')
-rw-r--r--apps/files_sharing/lib/OrphanHelper.php36
1 files changed, 27 insertions, 9 deletions
diff --git a/apps/files_sharing/lib/OrphanHelper.php b/apps/files_sharing/lib/OrphanHelper.php
index 94fe4f08318..6e070f1446b 100644
--- a/apps/files_sharing/lib/OrphanHelper.php
+++ b/apps/files_sharing/lib/OrphanHelper.php
@@ -10,19 +10,16 @@ namespace OCA\Files_Sharing;
use OC\User\NoUserException;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\Files\Config\IUserMountCache;
use OCP\Files\IRootFolder;
use OCP\IDBConnection;
class OrphanHelper {
- private IDBConnection $connection;
- private IRootFolder $rootFolder;
-
public function __construct(
- IDBConnection $connection,
- IRootFolder $rootFolder
+ private IDBConnection $connection,
+ private IRootFolder $rootFolder,
+ private IUserMountCache $userMountCache,
) {
- $this->connection = $connection;
- $this->rootFolder = $rootFolder;
}
public function isShareValid(string $owner, int $fileId): bool {
@@ -61,8 +58,7 @@ class OrphanHelper {
$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')));
+ ->where($query->expr()->in('item_type', $query->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)));
$result = $query->executeQuery();
while ($row = $result->fetch()) {
yield [
@@ -73,4 +69,26 @@ class OrphanHelper {
];
}
}
+
+ 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();
+ }
}