Passed
Push — master ( 348454...c8160a )
by Joas
15:07 queued 14s
created
apps/user_ldap/lib/Command/ShowRemnants.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -89,8 +89,8 @@
 block discarded – undo
89 89
 				'displayName' => $user->getDisplayName(),
90 90
 				'uid' => $user->getUID(),
91 91
 				'dn' => $user->getDN(),
92
-				'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool)$input->getOption('short-date')),
93
-				'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool)$input->getOption('short-date')),
92
+				'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool) $input->getOption('short-date')),
93
+				'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool) $input->getOption('short-date')),
94 94
 				'homePath' => $user->getHomePath(),
95 95
 				'sharer' => $user->getHasActiveShares() ? 'Y' : 'N',
96 96
 			];
Please login to merge, or discard this patch.
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -36,73 +36,73 @@
 block discarded – undo
36 36
 use Symfony\Component\Console\Output\OutputInterface;
37 37
 
38 38
 class ShowRemnants extends Command {
39
-	/** @var \OCA\User_LDAP\User\DeletedUsersIndex */
40
-	protected $dui;
39
+    /** @var \OCA\User_LDAP\User\DeletedUsersIndex */
40
+    protected $dui;
41 41
 
42
-	/** @var \OCP\IDateTimeFormatter */
43
-	protected $dateFormatter;
42
+    /** @var \OCP\IDateTimeFormatter */
43
+    protected $dateFormatter;
44 44
 
45
-	/**
46
-	 * @param DeletedUsersIndex $dui
47
-	 * @param IDateTimeFormatter $dateFormatter
48
-	 */
49
-	public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) {
50
-		$this->dui = $dui;
51
-		$this->dateFormatter = $dateFormatter;
52
-		parent::__construct();
53
-	}
45
+    /**
46
+     * @param DeletedUsersIndex $dui
47
+     * @param IDateTimeFormatter $dateFormatter
48
+     */
49
+    public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) {
50
+        $this->dui = $dui;
51
+        $this->dateFormatter = $dateFormatter;
52
+        parent::__construct();
53
+    }
54 54
 
55
-	protected function configure() {
56
-		$this
57
-			->setName('ldap:show-remnants')
58
-			->setDescription('shows which users are not available on LDAP anymore, but have remnants in Nextcloud.')
59
-			->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.')
60
-			->addOption('short-date', null, InputOption::VALUE_NONE, 'show dates in Y-m-d format');
61
-	}
55
+    protected function configure() {
56
+        $this
57
+            ->setName('ldap:show-remnants')
58
+            ->setDescription('shows which users are not available on LDAP anymore, but have remnants in Nextcloud.')
59
+            ->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.')
60
+            ->addOption('short-date', null, InputOption::VALUE_NONE, 'show dates in Y-m-d format');
61
+    }
62 62
 
63
-	protected function formatDate(int $timestamp, string $default, bool $showShortDate) {
64
-		if (!($timestamp > 0)) {
65
-			return $default;
66
-		}
67
-		if ($showShortDate) {
68
-			return date('Y-m-d', $timestamp);
69
-		}
70
-		return $this->dateFormatter->formatDate($timestamp);
71
-	}
63
+    protected function formatDate(int $timestamp, string $default, bool $showShortDate) {
64
+        if (!($timestamp > 0)) {
65
+            return $default;
66
+        }
67
+        if ($showShortDate) {
68
+            return date('Y-m-d', $timestamp);
69
+        }
70
+        return $this->dateFormatter->formatDate($timestamp);
71
+    }
72 72
 
73
-	/**
74
-	 * executes the command, i.e. creates and outputs a table of LDAP users marked as deleted
75
-	 *
76
-	 * {@inheritdoc}
77
-	 */
78
-	protected function execute(InputInterface $input, OutputInterface $output): int {
79
-		/** @var \Symfony\Component\Console\Helper\Table $table */
80
-		$table = new Table($output);
81
-		$table->setHeaders([
82
-			'Nextcloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login',
83
-			'Detected on', 'Dir', 'Sharer'
84
-		]);
85
-		$rows = [];
86
-		$resultSet = $this->dui->getUsers();
87
-		foreach ($resultSet as $user) {
88
-			$rows[] = [
89
-				'ocName' => $user->getOCName(),
90
-				'displayName' => $user->getDisplayName(),
91
-				'uid' => $user->getUID(),
92
-				'dn' => $user->getDN(),
93
-				'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool)$input->getOption('short-date')),
94
-				'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool)$input->getOption('short-date')),
95
-				'homePath' => $user->getHomePath(),
96
-				'sharer' => $user->getHasActiveShares() ? 'Y' : 'N',
97
-			];
98
-		}
73
+    /**
74
+     * executes the command, i.e. creates and outputs a table of LDAP users marked as deleted
75
+     *
76
+     * {@inheritdoc}
77
+     */
78
+    protected function execute(InputInterface $input, OutputInterface $output): int {
79
+        /** @var \Symfony\Component\Console\Helper\Table $table */
80
+        $table = new Table($output);
81
+        $table->setHeaders([
82
+            'Nextcloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login',
83
+            'Detected on', 'Dir', 'Sharer'
84
+        ]);
85
+        $rows = [];
86
+        $resultSet = $this->dui->getUsers();
87
+        foreach ($resultSet as $user) {
88
+            $rows[] = [
89
+                'ocName' => $user->getOCName(),
90
+                'displayName' => $user->getDisplayName(),
91
+                'uid' => $user->getUID(),
92
+                'dn' => $user->getDN(),
93
+                'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool)$input->getOption('short-date')),
94
+                'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool)$input->getOption('short-date')),
95
+                'homePath' => $user->getHomePath(),
96
+                'sharer' => $user->getHasActiveShares() ? 'Y' : 'N',
97
+            ];
98
+        }
99 99
 
100
-		if ($input->getOption('json')) {
101
-			$output->writeln(json_encode($rows));
102
-		} else {
103
-			$table->setRows($rows);
104
-			$table->render();
105
-		}
106
-		return 0;
107
-	}
100
+        if ($input->getOption('json')) {
101
+            $output->writeln(json_encode($rows));
102
+        } else {
103
+            $table->setRows($rows);
104
+            $table->render();
105
+        }
106
+        return 0;
107
+    }
108 108
 }
Please login to merge, or discard this patch.
apps/dav/lib/Migration/ChunkCleanup.php 2 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -37,59 +37,59 @@
 block discarded – undo
37 37
 
38 38
 class ChunkCleanup implements IRepairStep {
39 39
 
40
-	/** @var IConfig */
41
-	private $config;
42
-	/** @var IUserManager */
43
-	private $userManager;
44
-	/** @var IRootFolder */
45
-	private $rootFolder;
46
-	/** @var IJobList */
47
-	private $jobList;
40
+    /** @var IConfig */
41
+    private $config;
42
+    /** @var IUserManager */
43
+    private $userManager;
44
+    /** @var IRootFolder */
45
+    private $rootFolder;
46
+    /** @var IJobList */
47
+    private $jobList;
48 48
 
49
-	public function __construct(IConfig $config,
50
-								IUserManager $userManager,
51
-								IRootFolder $rootFolder,
52
-								IJobList $jobList) {
53
-		$this->config = $config;
54
-		$this->userManager = $userManager;
55
-		$this->rootFolder = $rootFolder;
56
-		$this->jobList = $jobList;
57
-	}
49
+    public function __construct(IConfig $config,
50
+                                IUserManager $userManager,
51
+                                IRootFolder $rootFolder,
52
+                                IJobList $jobList) {
53
+        $this->config = $config;
54
+        $this->userManager = $userManager;
55
+        $this->rootFolder = $rootFolder;
56
+        $this->jobList = $jobList;
57
+    }
58 58
 
59
-	public function getName(): string {
60
-		return 'Chunk cleanup scheduler';
61
-	}
59
+    public function getName(): string {
60
+        return 'Chunk cleanup scheduler';
61
+    }
62 62
 
63
-	public function run(IOutput $output) {
64
-		// If we already ran this onec there is no need to run it again
65
-		if ($this->config->getAppValue('dav', 'chunks_migrated', '0') === '1') {
66
-			$output->info('Cleanup not required');
67
-		}
63
+    public function run(IOutput $output) {
64
+        // If we already ran this onec there is no need to run it again
65
+        if ($this->config->getAppValue('dav', 'chunks_migrated', '0') === '1') {
66
+            $output->info('Cleanup not required');
67
+        }
68 68
 
69
-		$output->startProgress();
70
-		// Loop over all seen users
71
-		$this->userManager->callForSeenUsers(function (IUser $user) use ($output) {
72
-			try {
73
-				$userFolder = $this->rootFolder->getUserFolder($user->getUID());
74
-				$userRoot = $userFolder->getParent();
75
-				/** @var Folder $uploadFolder */
76
-				$uploadFolder = $userRoot->get('uploads');
77
-			} catch (NotFoundException $e) {
78
-				// No folder so skipping
79
-				return;
80
-			}
69
+        $output->startProgress();
70
+        // Loop over all seen users
71
+        $this->userManager->callForSeenUsers(function (IUser $user) use ($output) {
72
+            try {
73
+                $userFolder = $this->rootFolder->getUserFolder($user->getUID());
74
+                $userRoot = $userFolder->getParent();
75
+                /** @var Folder $uploadFolder */
76
+                $uploadFolder = $userRoot->get('uploads');
77
+            } catch (NotFoundException $e) {
78
+                // No folder so skipping
79
+                return;
80
+            }
81 81
 
82
-			// Insert a cleanup job for each folder we find
83
-			$uploads = $uploadFolder->getDirectoryListing();
84
-			foreach ($uploads as $upload) {
85
-				$this->jobList->add(UploadCleanup::class, ['uid' => $user->getUID(), 'folder' => $upload->getName()]);
86
-			}
87
-			$output->advance();
88
-		});
89
-		$output->finishProgress();
82
+            // Insert a cleanup job for each folder we find
83
+            $uploads = $uploadFolder->getDirectoryListing();
84
+            foreach ($uploads as $upload) {
85
+                $this->jobList->add(UploadCleanup::class, ['uid' => $user->getUID(), 'folder' => $upload->getName()]);
86
+            }
87
+            $output->advance();
88
+        });
89
+        $output->finishProgress();
90 90
 
91 91
 
92
-		$this->config->setAppValue('dav', 'chunks_migrated', '1');
93
-	}
92
+        $this->config->setAppValue('dav', 'chunks_migrated', '1');
93
+    }
94 94
 
95 95
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@
 block discarded – undo
68 68
 
69 69
 		$output->startProgress();
70 70
 		// Loop over all seen users
71
-		$this->userManager->callForSeenUsers(function (IUser $user) use ($output) {
71
+		$this->userManager->callForSeenUsers(function(IUser $user) use ($output) {
72 72
 			try {
73 73
 				$userFolder = $this->rootFolder->getUserFolder($user->getUID());
74 74
 				$userRoot = $userFolder->getParent();
Please login to merge, or discard this patch.
apps/dav/lib/Upload/CleanupService.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -29,21 +29,21 @@
 block discarded – undo
29 29
 use OCP\IUserSession;
30 30
 
31 31
 class CleanupService {
32
-	/** @var IUserSession */
33
-	private $userSession;
34
-	/** @var IJobList */
35
-	private $jobList;
32
+    /** @var IUserSession */
33
+    private $userSession;
34
+    /** @var IJobList */
35
+    private $jobList;
36 36
 
37
-	public function __construct(IUserSession $userSession, IJobList $jobList) {
38
-		$this->userSession = $userSession;
39
-		$this->jobList = $jobList;
40
-	}
37
+    public function __construct(IUserSession $userSession, IJobList $jobList) {
38
+        $this->userSession = $userSession;
39
+        $this->jobList = $jobList;
40
+    }
41 41
 
42
-	public function addJob(string $folder) {
43
-		$this->jobList->add(UploadCleanup::class, ['uid' => $this->userSession->getUser()->getUID(), 'folder' => $folder]);
44
-	}
42
+    public function addJob(string $folder) {
43
+        $this->jobList->add(UploadCleanup::class, ['uid' => $this->userSession->getUser()->getUID(), 'folder' => $folder]);
44
+    }
45 45
 
46
-	public function removeJob(string $folder) {
47
-		$this->jobList->remove(UploadCleanup::class, ['uid' => $this->userSession->getUser()->getUID(), 'folder' => $folder]);
48
-	}
46
+    public function removeJob(string $folder) {
47
+        $this->jobList->remove(UploadCleanup::class, ['uid' => $this->userSession->getUser()->getUID(), 'folder' => $folder]);
48
+    }
49 49
 }
Please login to merge, or discard this patch.
apps/dav/lib/Migration/RemoveClassifiedEventActivity.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 			$delete->setParameter('owner', $this->getPrincipal($row['principaluri']))
79 79
 				->setParameter('type', 'calendar')
80 80
 				->setParameter('calendar_id', $row['calendarid'])
81
-				->setParameter('event_uid', '%' . $this->connection->escapeLikeParameter('{"id":"' . $row['uid'] . '"') . '%');
81
+				->setParameter('event_uid', '%'.$this->connection->escapeLikeParameter('{"id":"'.$row['uid'].'"').'%');
82 82
 			$deletedEvents += $delete->execute();
83 83
 		}
84 84
 		$result->closeCursor();
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 			$delete->setParameter('owner', $this->getPrincipal($row['principaluri']))
109 109
 				->setParameter('type', 'calendar')
110 110
 				->setParameter('calendar_id', $row['calendarid'])
111
-				->setParameter('event_uid', '%' . $this->connection->escapeLikeParameter('{"id":"' . $row['uid'] . '"') . '%')
112
-				->setParameter('filtered_name', '%' . $this->connection->escapeLikeParameter('{"id":"' . $row['uid'] . '","name":"Busy"') . '%');
111
+				->setParameter('event_uid', '%'.$this->connection->escapeLikeParameter('{"id":"'.$row['uid'].'"').'%')
112
+				->setParameter('filtered_name', '%'.$this->connection->escapeLikeParameter('{"id":"'.$row['uid'].'","name":"Busy"').'%');
113 113
 			$deletedEvents += $delete->execute();
114 114
 		}
115 115
 		$result->closeCursor();
Please login to merge, or discard this patch.
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -29,104 +29,104 @@
 block discarded – undo
29 29
 
30 30
 class RemoveClassifiedEventActivity implements IRepairStep {
31 31
 
32
-	/** @var IDBConnection */
33
-	private $connection;
34
-
35
-	public function __construct(IDBConnection $connection) {
36
-		$this->connection = $connection;
37
-	}
38
-
39
-	/**
40
-	 * @inheritdoc
41
-	 */
42
-	public function getName() {
43
-		return 'Remove activity entries of private events';
44
-	}
45
-
46
-	/**
47
-	 * @inheritdoc
48
-	 */
49
-	public function run(IOutput $output) {
50
-		if (!$this->connection->tableExists('activity')) {
51
-			return;
52
-		}
53
-
54
-		$deletedEvents = $this->removePrivateEventActivity();
55
-		$deletedEvents += $this->removeConfidentialUncensoredEventActivity();
56
-
57
-		$output->info("Removed $deletedEvents activity entries");
58
-	}
59
-
60
-	protected function removePrivateEventActivity(): int {
61
-		$deletedEvents = 0;
62
-
63
-		$delete = $this->connection->getQueryBuilder();
64
-		$delete->delete('activity')
65
-			->where($delete->expr()->neq('affecteduser', $delete->createParameter('owner')))
66
-			->andWhere($delete->expr()->eq('object_type', $delete->createParameter('type')))
67
-			->andWhere($delete->expr()->eq('object_id', $delete->createParameter('calendar_id')))
68
-			->andWhere($delete->expr()->like('subjectparams', $delete->createParameter('event_uid')));
69
-
70
-		$query = $this->connection->getQueryBuilder();
71
-		$query->select('c.principaluri', 'o.calendarid', 'o.uid')
72
-			->from('calendarobjects', 'o')
73
-			->leftJoin('o', 'calendars', 'c', $query->expr()->eq('c.id', 'o.calendarid'))
74
-			->where($query->expr()->eq('o.classification', $query->createNamedParameter(CalDavBackend::CLASSIFICATION_PRIVATE)));
75
-		$result = $query->execute();
76
-
77
-		while ($row = $result->fetch()) {
78
-			if ($row['principaluri'] === null) {
79
-				continue;
80
-			}
81
-
82
-			$delete->setParameter('owner', $this->getPrincipal($row['principaluri']))
83
-				->setParameter('type', 'calendar')
84
-				->setParameter('calendar_id', $row['calendarid'])
85
-				->setParameter('event_uid', '%' . $this->connection->escapeLikeParameter('{"id":"' . $row['uid'] . '"') . '%');
86
-			$deletedEvents += $delete->execute();
87
-		}
88
-		$result->closeCursor();
89
-
90
-		return $deletedEvents;
91
-	}
92
-
93
-	protected function removeConfidentialUncensoredEventActivity(): int {
94
-		$deletedEvents = 0;
95
-
96
-		$delete = $this->connection->getQueryBuilder();
97
-		$delete->delete('activity')
98
-			->where($delete->expr()->neq('affecteduser', $delete->createParameter('owner')))
99
-			->andWhere($delete->expr()->eq('object_type', $delete->createParameter('type')))
100
-			->andWhere($delete->expr()->eq('object_id', $delete->createParameter('calendar_id')))
101
-			->andWhere($delete->expr()->like('subjectparams', $delete->createParameter('event_uid')))
102
-			->andWhere($delete->expr()->notLike('subjectparams', $delete->createParameter('filtered_name')));
103
-
104
-		$query = $this->connection->getQueryBuilder();
105
-		$query->select('c.principaluri', 'o.calendarid', 'o.uid')
106
-			->from('calendarobjects', 'o')
107
-			->leftJoin('o', 'calendars', 'c', $query->expr()->eq('c.id', 'o.calendarid'))
108
-			->where($query->expr()->eq('o.classification', $query->createNamedParameter(CalDavBackend::CLASSIFICATION_CONFIDENTIAL)));
109
-		$result = $query->execute();
110
-
111
-		while ($row = $result->fetch()) {
112
-			if ($row['principaluri'] === null) {
113
-				continue;
114
-			}
115
-
116
-			$delete->setParameter('owner', $this->getPrincipal($row['principaluri']))
117
-				->setParameter('type', 'calendar')
118
-				->setParameter('calendar_id', $row['calendarid'])
119
-				->setParameter('event_uid', '%' . $this->connection->escapeLikeParameter('{"id":"' . $row['uid'] . '"') . '%')
120
-				->setParameter('filtered_name', '%' . $this->connection->escapeLikeParameter('{"id":"' . $row['uid'] . '","name":"Busy"') . '%');
121
-			$deletedEvents += $delete->execute();
122
-		}
123
-		$result->closeCursor();
124
-
125
-		return $deletedEvents;
126
-	}
127
-
128
-	protected function getPrincipal(string $principalUri): string {
129
-		$uri = explode('/', $principalUri);
130
-		return array_pop($uri);
131
-	}
32
+    /** @var IDBConnection */
33
+    private $connection;
34
+
35
+    public function __construct(IDBConnection $connection) {
36
+        $this->connection = $connection;
37
+    }
38
+
39
+    /**
40
+     * @inheritdoc
41
+     */
42
+    public function getName() {
43
+        return 'Remove activity entries of private events';
44
+    }
45
+
46
+    /**
47
+     * @inheritdoc
48
+     */
49
+    public function run(IOutput $output) {
50
+        if (!$this->connection->tableExists('activity')) {
51
+            return;
52
+        }
53
+
54
+        $deletedEvents = $this->removePrivateEventActivity();
55
+        $deletedEvents += $this->removeConfidentialUncensoredEventActivity();
56
+
57
+        $output->info("Removed $deletedEvents activity entries");
58
+    }
59
+
60
+    protected function removePrivateEventActivity(): int {
61
+        $deletedEvents = 0;
62
+
63
+        $delete = $this->connection->getQueryBuilder();
64
+        $delete->delete('activity')
65
+            ->where($delete->expr()->neq('affecteduser', $delete->createParameter('owner')))
66
+            ->andWhere($delete->expr()->eq('object_type', $delete->createParameter('type')))
67
+            ->andWhere($delete->expr()->eq('object_id', $delete->createParameter('calendar_id')))
68
+            ->andWhere($delete->expr()->like('subjectparams', $delete->createParameter('event_uid')));
69
+
70
+        $query = $this->connection->getQueryBuilder();
71
+        $query->select('c.principaluri', 'o.calendarid', 'o.uid')
72
+            ->from('calendarobjects', 'o')
73
+            ->leftJoin('o', 'calendars', 'c', $query->expr()->eq('c.id', 'o.calendarid'))
74
+            ->where($query->expr()->eq('o.classification', $query->createNamedParameter(CalDavBackend::CLASSIFICATION_PRIVATE)));
75
+        $result = $query->execute();
76
+
77
+        while ($row = $result->fetch()) {
78
+            if ($row['principaluri'] === null) {
79
+                continue;
80
+            }
81
+
82
+            $delete->setParameter('owner', $this->getPrincipal($row['principaluri']))
83
+                ->setParameter('type', 'calendar')
84
+                ->setParameter('calendar_id', $row['calendarid'])
85
+                ->setParameter('event_uid', '%' . $this->connection->escapeLikeParameter('{"id":"' . $row['uid'] . '"') . '%');
86
+            $deletedEvents += $delete->execute();
87
+        }
88
+        $result->closeCursor();
89
+
90
+        return $deletedEvents;
91
+    }
92
+
93
+    protected function removeConfidentialUncensoredEventActivity(): int {
94
+        $deletedEvents = 0;
95
+
96
+        $delete = $this->connection->getQueryBuilder();
97
+        $delete->delete('activity')
98
+            ->where($delete->expr()->neq('affecteduser', $delete->createParameter('owner')))
99
+            ->andWhere($delete->expr()->eq('object_type', $delete->createParameter('type')))
100
+            ->andWhere($delete->expr()->eq('object_id', $delete->createParameter('calendar_id')))
101
+            ->andWhere($delete->expr()->like('subjectparams', $delete->createParameter('event_uid')))
102
+            ->andWhere($delete->expr()->notLike('subjectparams', $delete->createParameter('filtered_name')));
103
+
104
+        $query = $this->connection->getQueryBuilder();
105
+        $query->select('c.principaluri', 'o.calendarid', 'o.uid')
106
+            ->from('calendarobjects', 'o')
107
+            ->leftJoin('o', 'calendars', 'c', $query->expr()->eq('c.id', 'o.calendarid'))
108
+            ->where($query->expr()->eq('o.classification', $query->createNamedParameter(CalDavBackend::CLASSIFICATION_CONFIDENTIAL)));
109
+        $result = $query->execute();
110
+
111
+        while ($row = $result->fetch()) {
112
+            if ($row['principaluri'] === null) {
113
+                continue;
114
+            }
115
+
116
+            $delete->setParameter('owner', $this->getPrincipal($row['principaluri']))
117
+                ->setParameter('type', 'calendar')
118
+                ->setParameter('calendar_id', $row['calendarid'])
119
+                ->setParameter('event_uid', '%' . $this->connection->escapeLikeParameter('{"id":"' . $row['uid'] . '"') . '%')
120
+                ->setParameter('filtered_name', '%' . $this->connection->escapeLikeParameter('{"id":"' . $row['uid'] . '","name":"Busy"') . '%');
121
+            $deletedEvents += $delete->execute();
122
+        }
123
+        $result->closeCursor();
124
+
125
+        return $deletedEvents;
126
+    }
127
+
128
+    protected function getPrincipal(string $principalUri): string {
129
+        $uri = explode('/', $principalUri);
130
+        return array_pop($uri);
131
+    }
132 132
 }
Please login to merge, or discard this patch.
lib/private/Files/ObjectStore/SwiftV2CachingAuthService.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -25,11 +25,11 @@
 block discarded – undo
25 25
 use OpenStack\Identity\v2\Service;
26 26
 
27 27
 class SwiftV2CachingAuthService extends Service {
28
-	public function authenticate(array $options = []): array {
29
-		if (!empty($options['v2cachedToken'])) {
30
-			return [$options['v2cachedToken'], $options['v2serviceUrl']];
31
-		} else {
32
-			return parent::authenticate($options);
33
-		}
34
-	}
28
+    public function authenticate(array $options = []): array {
29
+        if (!empty($options['v2cachedToken'])) {
30
+            return [$options['v2cachedToken'], $options['v2serviceUrl']];
31
+        } else {
32
+            return parent::authenticate($options);
33
+        }
34
+    }
35 35
 }
Please login to merge, or discard this patch.
lib/public/Group/ISubAdmin.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -32,68 +32,68 @@
 block discarded – undo
32 32
  */
33 33
 interface ISubAdmin {
34 34
 
35
-	/**
36
-	 * add a SubAdmin
37
-	 * @param IUser $user user to be SubAdmin
38
-	 * @param IGroup $group group $user becomes subadmin of
39
-	 *
40
-	 * @since 16.0.0
41
-	 */
42
-	public function createSubAdmin(IUser $user, IGroup $group): void;
35
+    /**
36
+     * add a SubAdmin
37
+     * @param IUser $user user to be SubAdmin
38
+     * @param IGroup $group group $user becomes subadmin of
39
+     *
40
+     * @since 16.0.0
41
+     */
42
+    public function createSubAdmin(IUser $user, IGroup $group): void;
43 43
 
44
-	/**
45
-	 * delete a SubAdmin
46
-	 * @param IUser $user the user that is the SubAdmin
47
-	 * @param IGroup $group the group
48
-	 *
49
-	 * @since 16.0.0
50
-	 */
51
-	public function deleteSubAdmin(IUser $user, IGroup $group): void;
44
+    /**
45
+     * delete a SubAdmin
46
+     * @param IUser $user the user that is the SubAdmin
47
+     * @param IGroup $group the group
48
+     *
49
+     * @since 16.0.0
50
+     */
51
+    public function deleteSubAdmin(IUser $user, IGroup $group): void;
52 52
 
53
-	/**
54
-	 * get groups of a SubAdmin
55
-	 * @param IUser $user the SubAdmin
56
-	 * @return IGroup[]
57
-	 *
58
-	 * @since 16.0.0
59
-	 */
60
-	public function getSubAdminsGroups(IUser $user): array;
53
+    /**
54
+     * get groups of a SubAdmin
55
+     * @param IUser $user the SubAdmin
56
+     * @return IGroup[]
57
+     *
58
+     * @since 16.0.0
59
+     */
60
+    public function getSubAdminsGroups(IUser $user): array;
61 61
 
62
-	/**
63
-	 * get SubAdmins of a group
64
-	 * @param IGroup $group the group
65
-	 * @return IUser[]
66
-	 *
67
-	 * @since 16.0.0
68
-	 */
69
-	public function getGroupsSubAdmins(IGroup $group): array;
62
+    /**
63
+     * get SubAdmins of a group
64
+     * @param IGroup $group the group
65
+     * @return IUser[]
66
+     *
67
+     * @since 16.0.0
68
+     */
69
+    public function getGroupsSubAdmins(IGroup $group): array;
70 70
 
71
-	/**
72
-	 * checks if a user is a SubAdmin of a group
73
-	 * @param IUser $user
74
-	 * @param IGroup $group
75
-	 * @return bool
76
-	 *
77
-	 * @since 16.0.0
78
-	 */
79
-	public function isSubAdminOfGroup(IUser $user, IGroup $group): bool;
71
+    /**
72
+     * checks if a user is a SubAdmin of a group
73
+     * @param IUser $user
74
+     * @param IGroup $group
75
+     * @return bool
76
+     *
77
+     * @since 16.0.0
78
+     */
79
+    public function isSubAdminOfGroup(IUser $user, IGroup $group): bool;
80 80
 
81
-	/**
82
-	 * checks if a user is a SubAdmin
83
-	 * @param IUser $user
84
-	 * @return bool
85
-	 *
86
-	 * @since 16.0.0
87
-	 */
88
-	public function isSubAdmin(IUser $user): bool;
81
+    /**
82
+     * checks if a user is a SubAdmin
83
+     * @param IUser $user
84
+     * @return bool
85
+     *
86
+     * @since 16.0.0
87
+     */
88
+    public function isSubAdmin(IUser $user): bool;
89 89
 
90
-	/**
91
-	 * checks if a user is a accessible by a subadmin
92
-	 * @param IUser $subadmin
93
-	 * @param IUser $user
94
-	 * @return bool
95
-	 *
96
-	 * @since 16.0.0
97
-	 */
98
-	public function isUserAccessible(IUser $subadmin, IUser $user): bool;
90
+    /**
91
+     * checks if a user is a accessible by a subadmin
92
+     * @param IUser $subadmin
93
+     * @param IUser $user
94
+     * @return bool
95
+     *
96
+     * @since 16.0.0
97
+     */
98
+    public function isUserAccessible(IUser $subadmin, IUser $user): bool;
99 99
 }
Please login to merge, or discard this patch.
apps/twofactor_backupcodes/lib/Settings/Personal.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,8 +28,8 @@
 block discarded – undo
28 28
 use OCP\Template;
29 29
 
30 30
 class Personal implements IPersonalProviderSettings {
31
-	public function getBody(): Template {
32
-		return new Template('twofactor_backupcodes', 'personal');
33
-	}
31
+    public function getBody(): Template {
32
+        return new Template('twofactor_backupcodes', 'personal');
33
+    }
34 34
 
35 35
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Trash/LegacyTrashBackend.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 	private function mapTrashItems(array $items, IUser $user, ITrashItem $parent = null): array {
53 53
 		$parentTrashPath = ($parent instanceof ITrashItem) ? $parent->getTrashPath() : '';
54 54
 		$isRoot = $parent === null;
55
-		return array_map(function (FileInfo $file) use ($parent, $parentTrashPath, $isRoot, $user) {
56
-			$originalLocation = $isRoot ? $file['extraData'] : $parent->getOriginalLocation() . '/' . $file->getName();
55
+		return array_map(function(FileInfo $file) use ($parent, $parentTrashPath, $isRoot, $user) {
56
+			$originalLocation = $isRoot ? $file['extraData'] : $parent->getOriginalLocation().'/'.$file->getName();
57 57
 			if (!$originalLocation) {
58 58
 				$originalLocation = $file->getName();
59 59
 			}
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 				$this,
62 62
 				$originalLocation,
63 63
 				$file->getMTime(),
64
-				$parentTrashPath . '/' . $file->getName() . ($isRoot ? '.d' . $file->getMtime() : ''),
64
+				$parentTrashPath.'/'.$file->getName().($isRoot ? '.d'.$file->getMtime() : ''),
65 65
 				$file,
66 66
 				$user
67 67
 			);
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	public function listTrashFolder(ITrashItem $folder): array {
77 77
 		$user = $folder->getUser();
78 78
 		$entries = Helper::getTrashFiles($folder->getTrashPath(), $user->getUID());
79
-		return $this->mapTrashItems($entries, $user ,$folder);
79
+		return $this->mapTrashItems($entries, $user, $folder);
80 80
 	}
81 81
 
82 82
 	public function restoreItem(ITrashItem $item) {
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	public function removeItem(ITrashItem $item) {
87 87
 		$user = $item->getUser();
88 88
 		if ($item->isRootItem()) {
89
-			$path = substr($item->getTrashPath(), 0, -strlen('.d' . $item->getDeletedTime()));
89
+			$path = substr($item->getTrashPath(), 0, -strlen('.d'.$item->getDeletedTime()));
90 90
 			Trashbin::delete($path, $user->getUID(), $item->getDeletedTime());
91 91
 		} else {
92 92
 			Trashbin::delete($item->getTrashPath(), $user->getUID(), null);
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 		if (!$storage instanceof Storage) {
99 99
 			return false;
100 100
 		}
101
-		$normalized = Filesystem::normalizePath($storage->getMountPoint() . '/' . $internalPath, true, false, true);
101
+		$normalized = Filesystem::normalizePath($storage->getMountPoint().'/'.$internalPath, true, false, true);
102 102
 		$view = Filesystem::getView();
103 103
 		if (!isset($this->deletedFiles[$normalized]) && $view instanceof View) {
104 104
 			$this->deletedFiles[$normalized] = $normalized;
Please login to merge, or discard this patch.
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -35,99 +35,99 @@
 block discarded – undo
35 35
 use OCP\IUser;
36 36
 
37 37
 class LegacyTrashBackend implements ITrashBackend {
38
-	/** @var array */
39
-	private $deletedFiles = [];
38
+    /** @var array */
39
+    private $deletedFiles = [];
40 40
 
41
-	/** @var IRootFolder */
42
-	private $rootFolder;
41
+    /** @var IRootFolder */
42
+    private $rootFolder;
43 43
 
44
-	public function __construct(IRootFolder $rootFolder) {
45
-		$this->rootFolder = $rootFolder;
46
-	}
44
+    public function __construct(IRootFolder $rootFolder) {
45
+        $this->rootFolder = $rootFolder;
46
+    }
47 47
 
48
-	/**
49
-	 * @param array $items
50
-	 * @param IUser $user
51
-	 * @param ITrashItem $parent
52
-	 * @return ITrashItem[]
53
-	 */
54
-	private function mapTrashItems(array $items, IUser $user, ITrashItem $parent = null): array {
55
-		$parentTrashPath = ($parent instanceof ITrashItem) ? $parent->getTrashPath() : '';
56
-		$isRoot = $parent === null;
57
-		return array_map(function (FileInfo $file) use ($parent, $parentTrashPath, $isRoot, $user) {
58
-			$originalLocation = $isRoot ? $file['extraData'] : $parent->getOriginalLocation() . '/' . $file->getName();
59
-			if (!$originalLocation) {
60
-				$originalLocation = $file->getName();
61
-			}
62
-			return new TrashItem(
63
-				$this,
64
-				$originalLocation,
65
-				$file->getMTime(),
66
-				$parentTrashPath . '/' . $file->getName() . ($isRoot ? '.d' . $file->getMtime() : ''),
67
-				$file,
68
-				$user
69
-			);
70
-		}, $items);
71
-	}
48
+    /**
49
+     * @param array $items
50
+     * @param IUser $user
51
+     * @param ITrashItem $parent
52
+     * @return ITrashItem[]
53
+     */
54
+    private function mapTrashItems(array $items, IUser $user, ITrashItem $parent = null): array {
55
+        $parentTrashPath = ($parent instanceof ITrashItem) ? $parent->getTrashPath() : '';
56
+        $isRoot = $parent === null;
57
+        return array_map(function (FileInfo $file) use ($parent, $parentTrashPath, $isRoot, $user) {
58
+            $originalLocation = $isRoot ? $file['extraData'] : $parent->getOriginalLocation() . '/' . $file->getName();
59
+            if (!$originalLocation) {
60
+                $originalLocation = $file->getName();
61
+            }
62
+            return new TrashItem(
63
+                $this,
64
+                $originalLocation,
65
+                $file->getMTime(),
66
+                $parentTrashPath . '/' . $file->getName() . ($isRoot ? '.d' . $file->getMtime() : ''),
67
+                $file,
68
+                $user
69
+            );
70
+        }, $items);
71
+    }
72 72
 
73
-	public function listTrashRoot(IUser $user): array {
74
-		$entries = Helper::getTrashFiles('/', $user->getUID());
75
-		return $this->mapTrashItems($entries, $user);
76
-	}
73
+    public function listTrashRoot(IUser $user): array {
74
+        $entries = Helper::getTrashFiles('/', $user->getUID());
75
+        return $this->mapTrashItems($entries, $user);
76
+    }
77 77
 
78
-	public function listTrashFolder(ITrashItem $folder): array {
79
-		$user = $folder->getUser();
80
-		$entries = Helper::getTrashFiles($folder->getTrashPath(), $user->getUID());
81
-		return $this->mapTrashItems($entries, $user ,$folder);
82
-	}
78
+    public function listTrashFolder(ITrashItem $folder): array {
79
+        $user = $folder->getUser();
80
+        $entries = Helper::getTrashFiles($folder->getTrashPath(), $user->getUID());
81
+        return $this->mapTrashItems($entries, $user ,$folder);
82
+    }
83 83
 
84
-	public function restoreItem(ITrashItem $item) {
85
-		Trashbin::restore($item->getTrashPath(), $item->getName(), $item->isRootItem() ? $item->getDeletedTime() : null);
86
-	}
84
+    public function restoreItem(ITrashItem $item) {
85
+        Trashbin::restore($item->getTrashPath(), $item->getName(), $item->isRootItem() ? $item->getDeletedTime() : null);
86
+    }
87 87
 
88
-	public function removeItem(ITrashItem $item) {
89
-		$user = $item->getUser();
90
-		if ($item->isRootItem()) {
91
-			$path = substr($item->getTrashPath(), 0, -strlen('.d' . $item->getDeletedTime()));
92
-			Trashbin::delete($path, $user->getUID(), $item->getDeletedTime());
93
-		} else {
94
-			Trashbin::delete($item->getTrashPath(), $user->getUID(), null);
95
-		}
96
-	}
88
+    public function removeItem(ITrashItem $item) {
89
+        $user = $item->getUser();
90
+        if ($item->isRootItem()) {
91
+            $path = substr($item->getTrashPath(), 0, -strlen('.d' . $item->getDeletedTime()));
92
+            Trashbin::delete($path, $user->getUID(), $item->getDeletedTime());
93
+        } else {
94
+            Trashbin::delete($item->getTrashPath(), $user->getUID(), null);
95
+        }
96
+    }
97 97
 
98
-	public function moveToTrash(IStorage $storage, string $internalPath): bool {
99
-		if (!$storage instanceof Storage) {
100
-			return false;
101
-		}
102
-		$normalized = Filesystem::normalizePath($storage->getMountPoint() . '/' . $internalPath, true, false, true);
103
-		$view = Filesystem::getView();
104
-		if (!isset($this->deletedFiles[$normalized]) && $view instanceof View) {
105
-			$this->deletedFiles[$normalized] = $normalized;
106
-			if ($filesPath = $view->getRelativePath($normalized)) {
107
-				$filesPath = trim($filesPath, '/');
108
-				$result = \OCA\Files_Trashbin\Trashbin::move2trash($filesPath);
109
-			} else {
110
-				$result = false;
111
-			}
112
-			unset($this->deletedFiles[$normalized]);
113
-		} else {
114
-			$result = false;
115
-		}
98
+    public function moveToTrash(IStorage $storage, string $internalPath): bool {
99
+        if (!$storage instanceof Storage) {
100
+            return false;
101
+        }
102
+        $normalized = Filesystem::normalizePath($storage->getMountPoint() . '/' . $internalPath, true, false, true);
103
+        $view = Filesystem::getView();
104
+        if (!isset($this->deletedFiles[$normalized]) && $view instanceof View) {
105
+            $this->deletedFiles[$normalized] = $normalized;
106
+            if ($filesPath = $view->getRelativePath($normalized)) {
107
+                $filesPath = trim($filesPath, '/');
108
+                $result = \OCA\Files_Trashbin\Trashbin::move2trash($filesPath);
109
+            } else {
110
+                $result = false;
111
+            }
112
+            unset($this->deletedFiles[$normalized]);
113
+        } else {
114
+            $result = false;
115
+        }
116 116
 
117
-		return $result;
118
-	}
117
+        return $result;
118
+    }
119 119
 
120
-	public function getTrashNodeById(IUser $user, int $fileId) {
121
-		try {
122
-			$userFolder = $this->rootFolder->getUserFolder($user->getUID());
123
-			$trash = $userFolder->getParent()->get('files_trashbin/files');
124
-			$trashFiles = $trash->getById($fileId);
125
-			if (!$trashFiles) {
126
-				return null;
127
-			}
128
-			return $trashFiles ? array_pop($trashFiles) : null;
129
-		} catch (NotFoundException $e) {
130
-			return null;
131
-		}
132
-	}
120
+    public function getTrashNodeById(IUser $user, int $fileId) {
121
+        try {
122
+            $userFolder = $this->rootFolder->getUserFolder($user->getUID());
123
+            $trash = $userFolder->getParent()->get('files_trashbin/files');
124
+            $trashFiles = $trash->getById($fileId);
125
+            if (!$trashFiles) {
126
+                return null;
127
+            }
128
+            return $trashFiles ? array_pop($trashFiles) : null;
129
+        } catch (NotFoundException $e) {
130
+            return null;
131
+        }
132
+    }
133 133
 }
Please login to merge, or discard this patch.
apps/files_versions/lib/Versions/LegacyVersionsBackend.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -55,12 +55,12 @@  discard block
 block discarded – undo
55 55
 		$file2 = array_pop($nodes);
56 56
 		$versions = Storage::getVersions($user->getUID(), $userFolder->getRelativePath($file2->getPath()));
57 57
 
58
-		return array_map(function (array $data) use ($file, $user) {
58
+		return array_map(function(array $data) use ($file, $user) {
59 59
 			return new Version(
60
-				(int)$data['version'],
61
-				(int)$data['version'],
60
+				(int) $data['version'],
61
+				(int) $data['version'],
62 62
 				$data['name'],
63
-				(int)$data['size'],
63
+				(int) $data['size'],
64 64
 				$data['mimetype'],
65 65
 				$data['path'],
66 66
 				$file,
@@ -73,16 +73,16 @@  discard block
 block discarded – undo
73 73
 	public function createVersion(IUser $user, FileInfo $file) {
74 74
 		$userFolder = $this->rootFolder->getUserFolder($user->getUID());
75 75
 		$relativePath = $userFolder->getRelativePath($file->getPath());
76
-		$userView = new View('/' . $user->getUID());
76
+		$userView = new View('/'.$user->getUID());
77 77
 		// create all parent folders
78 78
 		Storage::createMissingDirectories($relativePath, $userView);
79 79
 
80 80
 		Storage::scheduleExpire($user->getUID(), $relativePath);
81 81
 
82 82
 		// store a new version of a file
83
-		$userView->copy('files/' . $relativePath, 'files_versions/' . $relativePath . '.v' . $file->getMtime());
83
+		$userView->copy('files/'.$relativePath, 'files_versions/'.$relativePath.'.v'.$file->getMtime());
84 84
 		// ensure the file is scanned
85
-		$userView->getFileInfo('files_versions/' . $relativePath . '.v' . $file->getMtime());
85
+		$userView->getFileInfo('files_versions/'.$relativePath.'.v'.$file->getMtime());
86 86
 	}
87 87
 
88 88
 	public function rollback(IVersion $version) {
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	public function read(IVersion $version) {
105 105
 		$versions = $this->getVersionFolder($version->getUser());
106 106
 		/** @var File $file */
107
-		$file = $versions->get($version->getVersionPath() . '.v' . $version->getRevisionId());
107
+		$file = $versions->get($version->getVersionPath().'.v'.$version->getRevisionId());
108 108
 		return $file->fopen('r');
109 109
 	}
110 110
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 		$userFolder = $this->rootFolder->getUserFolder($user->getUID());
113 113
 		$versionFolder = $this->getVersionFolder($user);
114 114
 		/** @var File $file */
115
-		$file = $versionFolder->get($userFolder->getRelativePath($sourceFile->getPath()) . '.v' . $revision);
115
+		$file = $versionFolder->get($userFolder->getRelativePath($sourceFile->getPath()).'.v'.$revision);
116 116
 		return $file;
117 117
 	}
118 118
 }
Please login to merge, or discard this patch.
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -40,90 +40,90 @@
 block discarded – undo
40 40
 use OCP\IUserManager;
41 41
 
42 42
 class LegacyVersionsBackend implements IVersionBackend {
43
-	/** @var IRootFolder */
44
-	private $rootFolder;
45
-	/** @var IUserManager */
46
-	private $userManager;
47
-
48
-	public function __construct(IRootFolder $rootFolder, IUserManager $userManager) {
49
-		$this->rootFolder = $rootFolder;
50
-		$this->userManager = $userManager;
51
-	}
52
-
53
-	public function useBackendForStorage(IStorage $storage): bool {
54
-		return true;
55
-	}
56
-
57
-	public function getVersionsForFile(IUser $user, FileInfo $file): array {
58
-		$storage = $file->getStorage();
59
-		if ($storage->instanceOfStorage(SharedStorage::class)) {
60
-			$owner = $storage->getOwner('');
61
-			$user = $this->userManager->get($owner);
62
-		}
63
-
64
-		$userFolder = $this->rootFolder->getUserFolder($user->getUID());
65
-		$nodes = $userFolder->getById($file->getId());
66
-		$file2 = array_pop($nodes);
67
-		$versions = Storage::getVersions($user->getUID(), $userFolder->getRelativePath($file2->getPath()));
68
-
69
-		return array_map(function (array $data) use ($file, $user) {
70
-			return new Version(
71
-				(int)$data['version'],
72
-				(int)$data['version'],
73
-				$data['name'],
74
-				(int)$data['size'],
75
-				$data['mimetype'],
76
-				$data['path'],
77
-				$file,
78
-				$this,
79
-				$user
80
-			);
81
-		}, $versions);
82
-	}
83
-
84
-	public function createVersion(IUser $user, FileInfo $file) {
85
-		$userFolder = $this->rootFolder->getUserFolder($user->getUID());
86
-		$relativePath = $userFolder->getRelativePath($file->getPath());
87
-		$userView = new View('/' . $user->getUID());
88
-		// create all parent folders
89
-		Storage::createMissingDirectories($relativePath, $userView);
90
-
91
-		Storage::scheduleExpire($user->getUID(), $relativePath);
92
-
93
-		// store a new version of a file
94
-		$userView->copy('files/' . $relativePath, 'files_versions/' . $relativePath . '.v' . $file->getMtime());
95
-		// ensure the file is scanned
96
-		$userView->getFileInfo('files_versions/' . $relativePath . '.v' . $file->getMtime());
97
-	}
98
-
99
-	public function rollback(IVersion $version) {
100
-		return Storage::rollback($version->getVersionPath(), $version->getRevisionId(), $version->getUser());
101
-	}
102
-
103
-	private function getVersionFolder(IUser $user): Folder {
104
-		$userRoot = $this->rootFolder->getUserFolder($user->getUID())
105
-			->getParent();
106
-		try {
107
-			/** @var Folder $folder */
108
-			$folder = $userRoot->get('files_versions');
109
-			return $folder;
110
-		} catch (NotFoundException $e) {
111
-			return $userRoot->newFolder('files_versions');
112
-		}
113
-	}
114
-
115
-	public function read(IVersion $version) {
116
-		$versions = $this->getVersionFolder($version->getUser());
117
-		/** @var File $file */
118
-		$file = $versions->get($version->getVersionPath() . '.v' . $version->getRevisionId());
119
-		return $file->fopen('r');
120
-	}
121
-
122
-	public function getVersionFile(IUser $user, FileInfo $sourceFile, $revision): File {
123
-		$userFolder = $this->rootFolder->getUserFolder($user->getUID());
124
-		$versionFolder = $this->getVersionFolder($user);
125
-		/** @var File $file */
126
-		$file = $versionFolder->get($userFolder->getRelativePath($sourceFile->getPath()) . '.v' . $revision);
127
-		return $file;
128
-	}
43
+    /** @var IRootFolder */
44
+    private $rootFolder;
45
+    /** @var IUserManager */
46
+    private $userManager;
47
+
48
+    public function __construct(IRootFolder $rootFolder, IUserManager $userManager) {
49
+        $this->rootFolder = $rootFolder;
50
+        $this->userManager = $userManager;
51
+    }
52
+
53
+    public function useBackendForStorage(IStorage $storage): bool {
54
+        return true;
55
+    }
56
+
57
+    public function getVersionsForFile(IUser $user, FileInfo $file): array {
58
+        $storage = $file->getStorage();
59
+        if ($storage->instanceOfStorage(SharedStorage::class)) {
60
+            $owner = $storage->getOwner('');
61
+            $user = $this->userManager->get($owner);
62
+        }
63
+
64
+        $userFolder = $this->rootFolder->getUserFolder($user->getUID());
65
+        $nodes = $userFolder->getById($file->getId());
66
+        $file2 = array_pop($nodes);
67
+        $versions = Storage::getVersions($user->getUID(), $userFolder->getRelativePath($file2->getPath()));
68
+
69
+        return array_map(function (array $data) use ($file, $user) {
70
+            return new Version(
71
+                (int)$data['version'],
72
+                (int)$data['version'],
73
+                $data['name'],
74
+                (int)$data['size'],
75
+                $data['mimetype'],
76
+                $data['path'],
77
+                $file,
78
+                $this,
79
+                $user
80
+            );
81
+        }, $versions);
82
+    }
83
+
84
+    public function createVersion(IUser $user, FileInfo $file) {
85
+        $userFolder = $this->rootFolder->getUserFolder($user->getUID());
86
+        $relativePath = $userFolder->getRelativePath($file->getPath());
87
+        $userView = new View('/' . $user->getUID());
88
+        // create all parent folders
89
+        Storage::createMissingDirectories($relativePath, $userView);
90
+
91
+        Storage::scheduleExpire($user->getUID(), $relativePath);
92
+
93
+        // store a new version of a file
94
+        $userView->copy('files/' . $relativePath, 'files_versions/' . $relativePath . '.v' . $file->getMtime());
95
+        // ensure the file is scanned
96
+        $userView->getFileInfo('files_versions/' . $relativePath . '.v' . $file->getMtime());
97
+    }
98
+
99
+    public function rollback(IVersion $version) {
100
+        return Storage::rollback($version->getVersionPath(), $version->getRevisionId(), $version->getUser());
101
+    }
102
+
103
+    private function getVersionFolder(IUser $user): Folder {
104
+        $userRoot = $this->rootFolder->getUserFolder($user->getUID())
105
+            ->getParent();
106
+        try {
107
+            /** @var Folder $folder */
108
+            $folder = $userRoot->get('files_versions');
109
+            return $folder;
110
+        } catch (NotFoundException $e) {
111
+            return $userRoot->newFolder('files_versions');
112
+        }
113
+    }
114
+
115
+    public function read(IVersion $version) {
116
+        $versions = $this->getVersionFolder($version->getUser());
117
+        /** @var File $file */
118
+        $file = $versions->get($version->getVersionPath() . '.v' . $version->getRevisionId());
119
+        return $file->fopen('r');
120
+    }
121
+
122
+    public function getVersionFile(IUser $user, FileInfo $sourceFile, $revision): File {
123
+        $userFolder = $this->rootFolder->getUserFolder($user->getUID());
124
+        $versionFolder = $this->getVersionFolder($user);
125
+        /** @var File $file */
126
+        $file = $versionFolder->get($userFolder->getRelativePath($sourceFile->getPath()) . '.v' . $revision);
127
+        return $file;
128
+    }
129 129
 }
Please login to merge, or discard this patch.