11<?php
22
3+ declare (strict_types=1 );
4+
35/**
46 * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
57 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
1214use OCP \DB \QueryBuilder \IQueryBuilder ;
1315use OCP \Files \Cache \IPropagator ;
1416use OCP \Files \Storage \IReliableEtagStorage ;
17+ use OCP \Files \Storage \IStorage ;
1518use OCP \IDBConnection ;
1619use OCP \Server ;
20+ use Override ;
1721use Psr \Clock \ClockInterface ;
1822use Psr \Log \LoggerInterface ;
1923
20- /**
21- * Propagate etags and mtimes within the storage
22- */
2324class Propagator implements IPropagator {
2425 public const MAX_RETRIES = 3 ;
25- private $ inBatch = false ;
26-
27- private $ batch = [];
28-
29- /**
30- * @var \OC\Files\Storage\Storage
31- */
32- protected $ storage ;
33-
34- /**
35- * @var IDBConnection
36- */
37- private $ connection ;
38-
39- /**
40- * @var array
41- */
42- private $ ignore = [];
4326
27+ private bool $ inBatch = false ;
28+ private array $ batch = [];
4429 private ClockInterface $ clock ;
4530
46- public function __construct (\OC \Files \Storage \Storage $ storage , IDBConnection $ connection , array $ ignore = []) {
47- $ this ->storage = $ storage ;
48- $ this ->connection = $ connection ;
49- $ this ->ignore = $ ignore ;
31+ public function __construct (
32+ protected readonly IStorage $ storage ,
33+ private readonly IDBConnection $ connection ,
34+ private readonly array $ ignore = [],
35+ ) {
5036 $ this ->clock = Server::get (ClockInterface::class);
5137 }
5238
53- /**
54- * @param string $internalPath
55- * @param int $time
56- * @param int $sizeDifference number of bytes the file has grown
57- */
58- public function propagateChange ($ internalPath , $ time , $ sizeDifference = 0 ) {
39+ #[Override]
40+ public function propagateChange (string $ internalPath , int $ time , int $ sizeDifference = 0 ): void {
5941 // Do not propagate changes in ignored paths
6042 foreach ($ this ->ignore as $ ignore ) {
6143 if (str_starts_with ($ internalPath , $ ignore )) {
6244 return ;
6345 }
6446 }
6547
66- $ time = min (( int ) $ time , $ this ->clock ->now ()->getTimestamp ());
48+ $ time = min ($ time , $ this ->clock ->now ()->getTimestamp ());
6749
68- $ storageId = $ this ->storage ->getStorageCache ()->getNumericId ();
50+ $ storageId = $ this ->storage ->getCache ()->getNumericStorageId ();
6951
7052 $ parents = $ this ->getParents ($ internalPath );
7153
@@ -137,7 +119,10 @@ public function propagateChange($internalPath, $time, $sizeDifference = 0) {
137119 }
138120 }
139121
140- protected function getParents ($ path ) {
122+ /**
123+ * @return string[]
124+ */
125+ protected function getParents (string $ path ): array {
141126 $ parts = explode ('/ ' , $ path );
142127 $ parent = '' ;
143128 $ parents = [];
@@ -148,19 +133,12 @@ protected function getParents($path) {
148133 return $ parents ;
149134 }
150135
151- /**
152- * Mark the beginning of a propagation batch
153- *
154- * Note that not all cache setups support propagation in which case this will be a noop
155- *
156- * Batching for cache setups that do support it has to be explicit since the cache state is not fully consistent
157- * before the batch is committed.
158- */
159- public function beginBatch () {
136+ #[Override]
137+ public function beginBatch (): void {
160138 $ this ->inBatch = true ;
161139 }
162140
163- private function addToBatch ($ internalPath , $ time , $ sizeDifference ) {
141+ private function addToBatch (string $ internalPath , int $ time , int $ sizeDifference ): void {
164142 if (!isset ($ this ->batch [$ internalPath ])) {
165143 $ this ->batch [$ internalPath ] = [
166144 'hash ' => md5 ($ internalPath ),
@@ -175,10 +153,8 @@ private function addToBatch($internalPath, $time, $sizeDifference) {
175153 }
176154 }
177155
178- /**
179- * Commit the active propagation batch
180- */
181- public function commitBatch () {
156+ #[Override]
157+ public function commitBatch (): void {
182158 if (!$ this ->inBatch ) {
183159 throw new \BadMethodCallException ('Not in batch ' );
184160 }
@@ -187,7 +163,7 @@ public function commitBatch() {
187163 $ this ->connection ->beginTransaction ();
188164
189165 $ query = $ this ->connection ->getQueryBuilder ();
190- $ storageId = ( int ) $ this ->storage ->getStorageCache ()->getNumericId ();
166+ $ storageId = $ this ->storage ->getCache ()->getNumericStorageId ();
191167
192168 $ query ->update ('filecache ' )
193169 ->set ('mtime ' , $ query ->func ()->greatest ('mtime ' , $ query ->createParameter ('time ' )))
0 commit comments