36
36
use OCA \FilesLock \Exceptions \LockNotFoundException ;
37
37
use OCA \FilesLock \Exceptions \UnauthorizedUnlockException ;
38
38
use OCA \FilesLock \Model \FileLock ;
39
- use OCA \FilesLock \Tools \Traits \TLogger ;
40
39
use OCA \FilesLock \Tools \Traits \TStringTools ;
41
40
use OCP \App \IAppManager ;
42
41
use OCP \EventDispatcher \IEventDispatcher ;
49
48
use OCP \IRequest ;
50
49
use OCP \IUserManager ;
51
50
use OCP \IUserSession ;
51
+ use Psr \Log \LoggerInterface ;
52
52
53
53
class LockService {
54
54
public const PREFIX = 'files_lock ' ;
55
55
56
56
57
57
use TStringTools;
58
- use TLogger;
59
-
60
58
61
59
private IUserManager $ userManager ;
62
60
private IL10N $ l10n ;
@@ -67,6 +65,7 @@ class LockService {
67
65
private IEventDispatcher $ eventDispatcher ;
68
66
private IUserSession $ userSession ;
69
67
private IRequest $ request ;
68
+ private LoggerInterface $ logger ;
70
69
71
70
72
71
private array $ locks = [];
@@ -86,6 +85,7 @@ public function __construct(
86
85
IEventDispatcher $ eventDispatcher ,
87
86
IUserSession $ userSession ,
88
87
IRequest $ request ,
88
+ LoggerInterface $ logger ,
89
89
) {
90
90
$ this ->l10n = $ l10n ;
91
91
$ this ->userManager = $ userManager ;
@@ -96,8 +96,7 @@ public function __construct(
96
96
$ this ->eventDispatcher = $ eventDispatcher ;
97
97
$ this ->userSession = $ userSession ;
98
98
$ this ->request = $ request ;
99
-
100
- $ this ->setup ('app ' , 'files_lock ' );
99
+ $ this ->logger = $ logger ;
101
100
}
102
101
103
102
/**
@@ -175,7 +174,7 @@ public function lock(LockContext $lockScope): FileLock {
175
174
$ known ->setTimeout (
176
175
$ known ->getETA () !== FileLock::ETA_INFINITE ? $ known ->getTimeout () - $ known ->getETA () + $ this ->configService ->getTimeoutSeconds () : 0
177
176
);
178
- $ this ->notice ('extending existing lock ' , false , ['fileLock ' => $ known ]);
177
+ $ this ->logger -> notice ('extending existing lock ' , ['fileLock ' => $ known ]);
179
178
$ this ->locksRequest ->update ($ known );
180
179
$ this ->injectMetadata ($ known );
181
180
return $ known ;
@@ -187,7 +186,7 @@ public function lock(LockContext $lockScope): FileLock {
187
186
$ lock = FileLock::fromLockScope ($ lockScope , $ this ->configService ->getTimeoutSeconds ());
188
187
$ this ->generateToken ($ lock );
189
188
$ lock ->setCreation (time ());
190
- $ this ->notice ('locking file ' , false , ['fileLock ' => $ lock ]);
189
+ $ this ->logger -> notice ('locking file ' , ['fileLock ' => $ lock ]);
191
190
$ this ->injectMetadata ($ lock );
192
191
$ this ->locksRequest ->save ($ lock );
193
192
$ this ->propagateEtag ($ lockScope );
@@ -211,7 +210,7 @@ public function getAppName(string $appId): ?string {
211
210
* @throws UnauthorizedUnlockException
212
211
*/
213
212
public function unlock (LockContext $ lock , bool $ force = false ): FileLock {
214
- $ this ->notice ('unlocking file ' , false , ['fileLock ' => $ lock ]);
213
+ $ this ->logger -> notice ('unlocking file ' , ['fileLock ' => $ lock ]);
215
214
216
215
$ known = $ this ->getLockFromFileId ($ lock ->getNode ()->getId ());
217
216
if (!$ force ) {
@@ -302,15 +301,16 @@ public function unlockFile(int $fileId, string $userId, bool $force = false, int
302
301
public function getDeprecatedLocks (): array {
303
302
$ timeout = (int )$ this ->configService ->getAppValue (ConfigService::LOCK_TIMEOUT );
304
303
if ($ timeout === 0 ) {
305
- $ this ->notice (
306
- 'ConfigService::LOCK_TIMEOUT is not numerical, using default ' , true , ['current ' => $ timeout ]
304
+ $ this ->logger -> notice (
305
+ 'ConfigService::LOCK_TIMEOUT is not numerical, using default ' , ['current ' => $ timeout, ' exception ' => new \ Exception () ]
307
306
);
308
307
$ timeout = (int )$ this ->configService ->defaults [ConfigService::LOCK_TIMEOUT ];
309
308
}
310
309
311
310
try {
312
311
$ locks = $ this ->locksRequest ->getLocksOlderThan ($ timeout );
313
312
} catch (Exception $ e ) {
313
+ $ this ->logger ->warning ('Failed to get locks older then timeout ' , ['exception ' => $ e ]);
314
314
return [];
315
315
}
316
316
@@ -398,7 +398,7 @@ function (FileLock $lock) {
398
398
}, $ locks
399
399
);
400
400
401
- $ this ->notice ('removing locks ' , false , ['ids ' => $ ids ]);
401
+ $ this ->logger -> notice ('removing locks ' , ['ids ' => $ ids ]);
402
402
403
403
$ this ->locksRequest ->removeIds ($ ids );
404
404
}
0 commit comments