Completed
Push — master ( 80b21c...5129a7 )
by Joas
29:44 queued 15s
created
apps/contactsinteraction/composer/composer/autoload_real.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
     public static function loadClassLoader($class)
10 10
     {
11 11
         if ('Composer\Autoload\ClassLoader' === $class) {
12
-            require __DIR__ . '/ClassLoader.php';
12
+            require __DIR__.'/ClassLoader.php';
13 13
         }
14 14
     }
15 15
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
         self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
27 27
         spl_autoload_unregister(array('ComposerAutoloaderInitContactsInteraction', 'loadClassLoader'));
28 28
 
29
-        require __DIR__ . '/autoload_static.php';
29
+        require __DIR__.'/autoload_static.php';
30 30
         call_user_func(\Composer\Autoload\ComposerStaticInitContactsInteraction::getInitializer($loader));
31 31
 
32 32
         $loader->setClassMapAuthoritative(true);
Please login to merge, or discard this patch.
apps/encryption/composer/composer/autoload_real.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
     public static function loadClassLoader($class)
10 10
     {
11 11
         if ('Composer\Autoload\ClassLoader' === $class) {
12
-            require __DIR__ . '/ClassLoader.php';
12
+            require __DIR__.'/ClassLoader.php';
13 13
         }
14 14
     }
15 15
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
         self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
27 27
         spl_autoload_unregister(array('ComposerAutoloaderInitEncryption', 'loadClassLoader'));
28 28
 
29
-        require __DIR__ . '/autoload_static.php';
29
+        require __DIR__.'/autoload_static.php';
30 30
         call_user_func(\Composer\Autoload\ComposerStaticInitEncryption::getInitializer($loader));
31 31
 
32 32
         $loader->setClassMapAuthoritative(true);
Please login to merge, or discard this patch.
apps/files_trashbin/composer/composer/autoload_real.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
     public static function loadClassLoader($class)
10 10
     {
11 11
         if ('Composer\Autoload\ClassLoader' === $class) {
12
-            require __DIR__ . '/ClassLoader.php';
12
+            require __DIR__.'/ClassLoader.php';
13 13
         }
14 14
     }
15 15
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
         self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
27 27
         spl_autoload_unregister(array('ComposerAutoloaderInitFiles_Trashbin', 'loadClassLoader'));
28 28
 
29
-        require __DIR__ . '/autoload_static.php';
29
+        require __DIR__.'/autoload_static.php';
30 30
         call_user_func(\Composer\Autoload\ComposerStaticInitFiles_Trashbin::getInitializer($loader));
31 31
 
32 32
         $loader->setClassMapAuthoritative(true);
Please login to merge, or discard this patch.
apps/theming/lib/Themes/DyslexiaFont.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@
 block discarded – undo
53 53
 		$originalFontFace = $variables['--font-face'];
54 54
 
55 55
 		$variables = [
56
-			'--font-face' => 'OpenDyslexic, ' . $originalFontFace
56
+			'--font-face' => 'OpenDyslexic, '.$originalFontFace
57 57
 		];
58 58
 
59 59
 		return $variables;
Please login to merge, or discard this patch.
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -11,42 +11,42 @@  discard block
 block discarded – undo
11 11
 
12 12
 class DyslexiaFont extends DefaultTheme implements ITheme {
13 13
 
14
-	public function getId(): string {
15
-		return 'opendyslexic';
16
-	}
14
+    public function getId(): string {
15
+        return 'opendyslexic';
16
+    }
17 17
 
18
-	public function getType(): int {
19
-		return ITheme::TYPE_FONT;
20
-	}
18
+    public function getType(): int {
19
+        return ITheme::TYPE_FONT;
20
+    }
21 21
 
22
-	public function getTitle(): string {
23
-		return $this->l->t('Dyslexia font');
24
-	}
22
+    public function getTitle(): string {
23
+        return $this->l->t('Dyslexia font');
24
+    }
25 25
 
26
-	public function getEnableLabel(): string {
27
-		return $this->l->t('Enable dyslexia font');
28
-	}
26
+    public function getEnableLabel(): string {
27
+        return $this->l->t('Enable dyslexia font');
28
+    }
29 29
 
30
-	public function getDescription(): string {
31
-		return $this->l->t('OpenDyslexic is a free typeface/font designed to mitigate some of the common reading errors caused by dyslexia.');
32
-	}
30
+    public function getDescription(): string {
31
+        return $this->l->t('OpenDyslexic is a free typeface/font designed to mitigate some of the common reading errors caused by dyslexia.');
32
+    }
33 33
 
34
-	public function getCSSVariables(): array {
35
-		$variables = parent::getCSSVariables();
36
-		$originalFontFace = $variables['--font-face'];
34
+    public function getCSSVariables(): array {
35
+        $variables = parent::getCSSVariables();
36
+        $originalFontFace = $variables['--font-face'];
37 37
 
38
-		$variables = [
39
-			'--font-face' => 'OpenDyslexic, ' . $originalFontFace
40
-		];
38
+        $variables = [
39
+            '--font-face' => 'OpenDyslexic, ' . $originalFontFace
40
+        ];
41 41
 
42
-		return $variables;
43
-	}
42
+        return $variables;
43
+    }
44 44
 
45
-	public function getCustomCss(): string {
46
-		$fontPathOtf = $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Regular.otf');
47
-		$boldFontPathOtf = $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Bold.otf');
45
+    public function getCustomCss(): string {
46
+        $fontPathOtf = $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Regular.otf');
47
+        $boldFontPathOtf = $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Bold.otf');
48 48
 
49
-		return "
49
+        return "
50 50
 			@font-face {
51 51
 				font-family: 'OpenDyslexic';
52 52
 				font-style: normal;
@@ -61,5 +61,5 @@  discard block
 block discarded – undo
61 61
 				src: url('$boldFontPathOtf') format('opentype');
62 62
 			}
63 63
 		";
64
-	}
64
+    }
65 65
 }
Please login to merge, or discard this patch.
core/Migrations/Version24000Date20220425072957.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -32,22 +32,22 @@
 block discarded – undo
32 32
 use OCP\Migration\SimpleMigrationStep;
33 33
 
34 34
 class Version24000Date20220425072957 extends SimpleMigrationStep {
35
-	/**
36
-	 * @param IOutput $output
37
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
38
-	 * @param array $options
39
-	 * @return null|ISchemaWrapper
40
-	 */
41
-	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
42
-		/** @var ISchemaWrapper $schema */
43
-		$schema = $schemaClosure();
35
+    /**
36
+     * @param IOutput $output
37
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
38
+     * @param array $options
39
+     * @return null|ISchemaWrapper
40
+     */
41
+    public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
42
+        /** @var ISchemaWrapper $schema */
43
+        $schema = $schemaClosure();
44 44
 
45
-		$table = $schema->getTable('mounts');
46
-		if (!$table->hasIndex('mount_user_storage')) {
47
-			$table->addIndex(['storage_id', 'user_id'], 'mount_user_storage');
48
-			return $schema;
49
-		}
45
+        $table = $schema->getTable('mounts');
46
+        if (!$table->hasIndex('mount_user_storage')) {
47
+            $table->addIndex(['storage_id', 'user_id'], 'mount_user_storage');
48
+            return $schema;
49
+        }
50 50
 
51
-		return null;
52
-	}
51
+        return null;
52
+    }
53 53
 }
Please login to merge, or discard this patch.
lib/public/IEmojiHelper.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,13 +27,13 @@
 block discarded – undo
27 27
  * @since 24.0.0
28 28
  */
29 29
 interface IEmojiHelper {
30
-	/**
31
-	 * @since 24.0.0
32
-	 */
33
-	public function doesPlatformSupportEmoji(): bool;
30
+    /**
31
+     * @since 24.0.0
32
+     */
33
+    public function doesPlatformSupportEmoji(): bool;
34 34
 
35
-	/**
36
-	 * @since 24.0.0
37
-	 */
38
-	public function isValidSingleEmoji(string $emoji): bool;
35
+    /**
36
+     * @since 24.0.0
37
+     */
38
+    public function isValidSingleEmoji(string $emoji): bool;
39 39
 }
Please login to merge, or discard this patch.
lib/private/DateTimeZone.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		try {
66 66
 			return new \DateTimeZone($timeZone);
67 67
 		} catch (\Exception $e) {
68
-			\OC::$server->get(LoggerInterface::class)->debug('Failed to created DateTimeZone "' . $timeZone . '"', ['app' => 'datetimezone']);
68
+			\OC::$server->get(LoggerInterface::class)->debug('Failed to created DateTimeZone "'.$timeZone.'"', ['app' => 'datetimezone']);
69 69
 			return new \DateTimeZone($this->getDefaultTimeZone());
70 70
 		}
71 71
 	}
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
 			// so a positive offset means negative timeZone
87 87
 			// and the other way around.
88 88
 			if ($offset > 0) {
89
-				$timeZone = 'Etc/GMT-' . $offset;
89
+				$timeZone = 'Etc/GMT-'.$offset;
90 90
 			} else {
91
-				$timeZone = 'Etc/GMT+' . abs($offset);
91
+				$timeZone = 'Etc/GMT+'.abs($offset);
92 92
 			}
93 93
 
94 94
 			return new \DateTimeZone($timeZone);
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 			}
111 111
 
112 112
 			// No timezone found, fallback to UTC
113
-			\OC::$server->get(LoggerInterface::class)->debug('Failed to find DateTimeZone for offset "' . $offset . '"', ['app' => 'datetimezone']);
113
+			\OC::$server->get(LoggerInterface::class)->debug('Failed to find DateTimeZone for offset "'.$offset.'"', ['app' => 'datetimezone']);
114 114
 			return new \DateTimeZone($this->getDefaultTimeZone());
115 115
 		}
116 116
 	}
Please login to merge, or discard this patch.
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -13,100 +13,100 @@
 block discarded – undo
13 13
 use Psr\Log\LoggerInterface;
14 14
 
15 15
 class DateTimeZone implements IDateTimeZone {
16
-	/** @var IConfig */
17
-	protected $config;
16
+    /** @var IConfig */
17
+    protected $config;
18 18
 
19
-	/** @var ISession */
20
-	protected $session;
19
+    /** @var ISession */
20
+    protected $session;
21 21
 
22
-	/**
23
-	 * Constructor
24
-	 *
25
-	 * @param IConfig $config
26
-	 * @param ISession $session
27
-	 */
28
-	public function __construct(IConfig $config, ISession $session) {
29
-		$this->config = $config;
30
-		$this->session = $session;
31
-	}
22
+    /**
23
+     * Constructor
24
+     *
25
+     * @param IConfig $config
26
+     * @param ISession $session
27
+     */
28
+    public function __construct(IConfig $config, ISession $session) {
29
+        $this->config = $config;
30
+        $this->session = $session;
31
+    }
32 32
 
33
-	/**
34
-	 * Get the timezone of the current user, based on their session information and config data
35
-	 *
36
-	 * @param bool|int $timestamp
37
-	 * @return \DateTimeZone
38
-	 */
39
-	public function getTimeZone($timestamp = false) {
40
-		$timeZone = $this->config->getUserValue($this->session->get('user_id'), 'core', 'timezone', null);
41
-		if ($timeZone === null) {
42
-			if ($this->session->exists('timezone')) {
43
-				return $this->guessTimeZoneFromOffset($this->session->get('timezone'), $timestamp);
44
-			}
45
-			$timeZone = $this->getDefaultTimeZone();
46
-		}
33
+    /**
34
+     * Get the timezone of the current user, based on their session information and config data
35
+     *
36
+     * @param bool|int $timestamp
37
+     * @return \DateTimeZone
38
+     */
39
+    public function getTimeZone($timestamp = false) {
40
+        $timeZone = $this->config->getUserValue($this->session->get('user_id'), 'core', 'timezone', null);
41
+        if ($timeZone === null) {
42
+            if ($this->session->exists('timezone')) {
43
+                return $this->guessTimeZoneFromOffset($this->session->get('timezone'), $timestamp);
44
+            }
45
+            $timeZone = $this->getDefaultTimeZone();
46
+        }
47 47
 
48
-		try {
49
-			return new \DateTimeZone($timeZone);
50
-		} catch (\Exception $e) {
51
-			\OC::$server->get(LoggerInterface::class)->debug('Failed to created DateTimeZone "' . $timeZone . '"', ['app' => 'datetimezone']);
52
-			return new \DateTimeZone($this->getDefaultTimeZone());
53
-		}
54
-	}
48
+        try {
49
+            return new \DateTimeZone($timeZone);
50
+        } catch (\Exception $e) {
51
+            \OC::$server->get(LoggerInterface::class)->debug('Failed to created DateTimeZone "' . $timeZone . '"', ['app' => 'datetimezone']);
52
+            return new \DateTimeZone($this->getDefaultTimeZone());
53
+        }
54
+    }
55 55
 
56
-	/**
57
-	 * Guess the DateTimeZone for a given offset
58
-	 *
59
-	 * We first try to find a Etc/GMT* timezone, if that does not exist,
60
-	 * we try to find it manually, before falling back to UTC.
61
-	 *
62
-	 * @param mixed $offset
63
-	 * @param bool|int $timestamp
64
-	 * @return \DateTimeZone
65
-	 */
66
-	protected function guessTimeZoneFromOffset($offset, $timestamp) {
67
-		try {
68
-			// Note: the timeZone name is the inverse to the offset,
69
-			// so a positive offset means negative timeZone
70
-			// and the other way around.
71
-			if ($offset > 0) {
72
-				$timeZone = 'Etc/GMT-' . $offset;
73
-			} else {
74
-				$timeZone = 'Etc/GMT+' . abs($offset);
75
-			}
56
+    /**
57
+     * Guess the DateTimeZone for a given offset
58
+     *
59
+     * We first try to find a Etc/GMT* timezone, if that does not exist,
60
+     * we try to find it manually, before falling back to UTC.
61
+     *
62
+     * @param mixed $offset
63
+     * @param bool|int $timestamp
64
+     * @return \DateTimeZone
65
+     */
66
+    protected function guessTimeZoneFromOffset($offset, $timestamp) {
67
+        try {
68
+            // Note: the timeZone name is the inverse to the offset,
69
+            // so a positive offset means negative timeZone
70
+            // and the other way around.
71
+            if ($offset > 0) {
72
+                $timeZone = 'Etc/GMT-' . $offset;
73
+            } else {
74
+                $timeZone = 'Etc/GMT+' . abs($offset);
75
+            }
76 76
 
77
-			return new \DateTimeZone($timeZone);
78
-		} catch (\Exception $e) {
79
-			// If the offset has no Etc/GMT* timezone,
80
-			// we try to guess one timezone that has the same offset
81
-			foreach (\DateTimeZone::listIdentifiers() as $timeZone) {
82
-				$dtz = new \DateTimeZone($timeZone);
83
-				$dateTime = new \DateTime();
77
+            return new \DateTimeZone($timeZone);
78
+        } catch (\Exception $e) {
79
+            // If the offset has no Etc/GMT* timezone,
80
+            // we try to guess one timezone that has the same offset
81
+            foreach (\DateTimeZone::listIdentifiers() as $timeZone) {
82
+                $dtz = new \DateTimeZone($timeZone);
83
+                $dateTime = new \DateTime();
84 84
 
85
-				if ($timestamp !== false) {
86
-					$dateTime->setTimestamp($timestamp);
87
-				}
85
+                if ($timestamp !== false) {
86
+                    $dateTime->setTimestamp($timestamp);
87
+                }
88 88
 
89
-				$dtOffset = $dtz->getOffset($dateTime);
90
-				if ($dtOffset == 3600 * $offset) {
91
-					return $dtz;
92
-				}
93
-			}
89
+                $dtOffset = $dtz->getOffset($dateTime);
90
+                if ($dtOffset == 3600 * $offset) {
91
+                    return $dtz;
92
+                }
93
+            }
94 94
 
95
-			// No timezone found, fallback to UTC
96
-			\OC::$server->get(LoggerInterface::class)->debug('Failed to find DateTimeZone for offset "' . $offset . '"', ['app' => 'datetimezone']);
97
-			return new \DateTimeZone($this->getDefaultTimeZone());
98
-		}
99
-	}
95
+            // No timezone found, fallback to UTC
96
+            \OC::$server->get(LoggerInterface::class)->debug('Failed to find DateTimeZone for offset "' . $offset . '"', ['app' => 'datetimezone']);
97
+            return new \DateTimeZone($this->getDefaultTimeZone());
98
+        }
99
+    }
100 100
 
101
-	/**
102
-	 * Get the default timezone of the server
103
-	 *
104
-	 * Falls back to UTC if it is not yet set.
105
-	 *
106
-	 * @return string
107
-	 */
108
-	protected function getDefaultTimeZone() {
109
-		$serverTimeZone = date_default_timezone_get();
110
-		return $serverTimeZone ?: 'UTC';
111
-	}
101
+    /**
102
+     * Get the default timezone of the server
103
+     *
104
+     * Falls back to UTC if it is not yet set.
105
+     *
106
+     * @return string
107
+     */
108
+    protected function getDefaultTimeZone() {
109
+        $serverTimeZone = date_default_timezone_get();
110
+        return $serverTimeZone ?: 'UTC';
111
+    }
112 112
 }
Please login to merge, or discard this patch.
lib/public/Lock/ILockingProvider.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -36,47 +36,47 @@
 block discarded – undo
36 36
  * @since 8.1.0
37 37
  */
38 38
 interface ILockingProvider {
39
-	/**
40
-	 * @since 8.1.0
41
-	 */
42
-	public const LOCK_SHARED = 1;
43
-	/**
44
-	 * @since 8.1.0
45
-	 */
46
-	public const LOCK_EXCLUSIVE = 2;
39
+    /**
40
+     * @since 8.1.0
41
+     */
42
+    public const LOCK_SHARED = 1;
43
+    /**
44
+     * @since 8.1.0
45
+     */
46
+    public const LOCK_EXCLUSIVE = 2;
47 47
 
48
-	/**
49
-	 * @psalm-param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type
50
-	 * @since 8.1.0
51
-	 */
52
-	public function isLocked(string $path, int $type): bool;
48
+    /**
49
+     * @psalm-param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type
50
+     * @since 8.1.0
51
+     */
52
+    public function isLocked(string $path, int $type): bool;
53 53
 
54
-	/**
55
-	 * @psalm-param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type
56
-	 * @param ?string $readablePath A human-readable path to use in error messages, since 20.0.0
57
-	 * @throws LockedException
58
-	 * @since 8.1.0
59
-	 */
60
-	public function acquireLock(string $path, int $type, ?string $readablePath = null): void;
54
+    /**
55
+     * @psalm-param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type
56
+     * @param ?string $readablePath A human-readable path to use in error messages, since 20.0.0
57
+     * @throws LockedException
58
+     * @since 8.1.0
59
+     */
60
+    public function acquireLock(string $path, int $type, ?string $readablePath = null): void;
61 61
 
62
-	/**
63
-	 * @psalm-param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type
64
-	 * @since 8.1.0
65
-	 */
66
-	public function releaseLock(string $path, int $type): void;
62
+    /**
63
+     * @psalm-param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type
64
+     * @since 8.1.0
65
+     */
66
+    public function releaseLock(string $path, int $type): void;
67 67
 
68
-	/**
69
-	 * Change the target type of an existing lock
70
-	 *
71
-	 * @psalm-param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $targetType
72
-	 * @throws LockedException
73
-	 * @since 8.1.0
74
-	 */
75
-	public function changeLock(string $path, int $targetType): void;
68
+    /**
69
+     * Change the target type of an existing lock
70
+     *
71
+     * @psalm-param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $targetType
72
+     * @throws LockedException
73
+     * @since 8.1.0
74
+     */
75
+    public function changeLock(string $path, int $targetType): void;
76 76
 
77
-	/**
78
-	 * Release all lock acquired by this instance
79
-	 * @since 8.1.0
80
-	 */
81
-	public function releaseAll(): void;
77
+    /**
78
+     * Release all lock acquired by this instance
79
+     * @since 8.1.0
80
+     */
81
+    public function releaseAll(): void;
82 82
 }
Please login to merge, or discard this patch.
lib/private/Lock/DBLockingProvider.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 			->from('file_locks')
114 114
 			->where($query->expr()->eq('key', $query->createNamedParameter($path)));
115 115
 		$result = $query->executeQuery();
116
-		$lockValue = (int)$result->fetchOne();
116
+		$lockValue = (int) $result->fetchOne();
117 117
 		if ($type === self::LOCK_SHARED) {
118 118
 			if ($this->isLocallyLocked($path)) {
119 119
 				// if we have a shared lock we kept open locally but it's released we always have at least 1 shared lock in the db
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 		}
248 248
 		// since we keep shared locks we need to manually clean those
249 249
 		$lockedPaths = array_keys($this->sharedLocks);
250
-		$lockedPaths = array_filter($lockedPaths, function ($path) {
250
+		$lockedPaths = array_filter($lockedPaths, function($path) {
251 251
 			return $this->sharedLocks[$path];
252 252
 		});
253 253
 
Please login to merge, or discard this patch.
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -18,223 +18,223 @@
 block discarded – undo
18 18
  * Locking provider that stores the locks in the database
19 19
  */
20 20
 class DBLockingProvider extends AbstractLockingProvider {
21
-	private array $sharedLocks = [];
22
-
23
-	public function __construct(
24
-		private IDBConnection $connection,
25
-		private ITimeFactory $timeFactory,
26
-		int $ttl = 3600,
27
-		private bool $cacheSharedLocks = true,
28
-	) {
29
-		parent::__construct($ttl);
30
-	}
31
-
32
-	/**
33
-	 * Check if we have an open shared lock for a path
34
-	 */
35
-	protected function isLocallyLocked(string $path): bool {
36
-		return isset($this->sharedLocks[$path]) && $this->sharedLocks[$path];
37
-	}
38
-
39
-	/** @inheritDoc */
40
-	protected function markAcquire(string $path, int $targetType): void {
41
-		parent::markAcquire($path, $targetType);
42
-		if ($this->cacheSharedLocks) {
43
-			if ($targetType === self::LOCK_SHARED) {
44
-				$this->sharedLocks[$path] = true;
45
-			}
46
-		}
47
-	}
48
-
49
-	/**
50
-	 * Change the type of an existing tracked lock
51
-	 */
52
-	protected function markChange(string $path, int $targetType): void {
53
-		parent::markChange($path, $targetType);
54
-		if ($this->cacheSharedLocks) {
55
-			if ($targetType === self::LOCK_SHARED) {
56
-				$this->sharedLocks[$path] = true;
57
-			} elseif ($targetType === self::LOCK_EXCLUSIVE) {
58
-				$this->sharedLocks[$path] = false;
59
-			}
60
-		}
61
-	}
62
-
63
-	/**
64
-	 * Insert a file locking row if it does not exists.
65
-	 */
66
-	protected function initLockField(string $path, int $lock = 0): int {
67
-		$expire = $this->getExpireTime();
68
-		return $this->connection->insertIgnoreConflict('file_locks', [
69
-			'key' => $path,
70
-			'lock' => $lock,
71
-			'ttl' => $expire
72
-		]);
73
-	}
74
-
75
-	protected function getExpireTime(): int {
76
-		return $this->timeFactory->getTime() + $this->ttl;
77
-	}
78
-
79
-	/** @inheritDoc */
80
-	public function isLocked(string $path, int $type): bool {
81
-		if ($this->hasAcquiredLock($path, $type)) {
82
-			return true;
83
-		}
84
-		$query = $this->connection->getQueryBuilder();
85
-		$query->select('lock')
86
-			->from('file_locks')
87
-			->where($query->expr()->eq('key', $query->createNamedParameter($path)));
88
-		$result = $query->executeQuery();
89
-		$lockValue = (int)$result->fetchOne();
90
-		if ($type === self::LOCK_SHARED) {
91
-			if ($this->isLocallyLocked($path)) {
92
-				// if we have a shared lock we kept open locally but it's released we always have at least 1 shared lock in the db
93
-				return $lockValue > 1;
94
-			} else {
95
-				return $lockValue > 0;
96
-			}
97
-		} elseif ($type === self::LOCK_EXCLUSIVE) {
98
-			return $lockValue === -1;
99
-		} else {
100
-			return false;
101
-		}
102
-	}
103
-
104
-	/** @inheritDoc */
105
-	public function acquireLock(string $path, int $type, ?string $readablePath = null): void {
106
-		$expire = $this->getExpireTime();
107
-		if ($type === self::LOCK_SHARED) {
108
-			if (!$this->isLocallyLocked($path)) {
109
-				$result = $this->initLockField($path, 1);
110
-				if ($result <= 0) {
111
-					$query = $this->connection->getQueryBuilder();
112
-					$query->update('file_locks')
113
-						->set('lock', $query->func()->add('lock', $query->createNamedParameter(1, IQueryBuilder::PARAM_INT)))
114
-						->set('ttl', $query->createNamedParameter($expire))
115
-						->where($query->expr()->eq('key', $query->createNamedParameter($path)))
116
-						->andWhere($query->expr()->gte('lock', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
117
-					$result = $query->executeStatement();
118
-				}
119
-			} else {
120
-				$result = 1;
121
-			}
122
-		} else {
123
-			$existing = 0;
124
-			if ($this->hasAcquiredLock($path, ILockingProvider::LOCK_SHARED) === false && $this->isLocallyLocked($path)) {
125
-				$existing = 1;
126
-			}
127
-			$result = $this->initLockField($path, -1);
128
-			if ($result <= 0) {
129
-				$query = $this->connection->getQueryBuilder();
130
-				$query->update('file_locks')
131
-					->set('lock', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT))
132
-					->set('ttl', $query->createNamedParameter($expire, IQueryBuilder::PARAM_INT))
133
-					->where($query->expr()->eq('key', $query->createNamedParameter($path)))
134
-					->andWhere($query->expr()->eq('lock', $query->createNamedParameter($existing)));
135
-				$result = $query->executeStatement();
136
-			}
137
-		}
138
-		if ($result !== 1) {
139
-			throw new LockedException($path, null, null, $readablePath);
140
-		}
141
-		$this->markAcquire($path, $type);
142
-	}
143
-
144
-	/** @inheritDoc */
145
-	public function releaseLock(string $path, int $type): void {
146
-		$this->markRelease($path, $type);
147
-
148
-		// we keep shared locks till the end of the request so we can re-use them
149
-		if ($type === self::LOCK_EXCLUSIVE) {
150
-			$qb = $this->connection->getQueryBuilder();
151
-			$qb->update('file_locks')
152
-				->set('lock', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT))
153
-				->where($qb->expr()->eq('key', $qb->createNamedParameter($path)))
154
-				->andWhere($qb->expr()->eq('lock', $qb->createNamedParameter(-1, IQueryBuilder::PARAM_INT)));
155
-			$qb->executeStatement();
156
-		} elseif (!$this->cacheSharedLocks) {
157
-			$qb = $this->connection->getQueryBuilder();
158
-			$qb->update('file_locks')
159
-				->set('lock', $qb->func()->subtract('lock', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)))
160
-				->where($qb->expr()->eq('key', $qb->createNamedParameter($path)))
161
-				->andWhere($qb->expr()->gt('lock', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
162
-			$qb->executeStatement();
163
-		}
164
-	}
165
-
166
-	/** @inheritDoc */
167
-	public function changeLock(string $path, int $targetType): void {
168
-		$expire = $this->getExpireTime();
169
-		if ($targetType === self::LOCK_SHARED) {
170
-			$qb = $this->connection->getQueryBuilder();
171
-			$result = $qb->update('file_locks')
172
-				->set('lock', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT))
173
-				->set('ttl', $qb->createNamedParameter($expire, IQueryBuilder::PARAM_INT))
174
-				->where($qb->expr()->andX(
175
-					$qb->expr()->eq('key', $qb->createNamedParameter($path)),
176
-					$qb->expr()->eq('lock', $qb->createNamedParameter(-1, IQueryBuilder::PARAM_INT))
177
-				))->executeStatement();
178
-		} else {
179
-			// since we only keep one shared lock in the db we need to check if we have more then one shared lock locally manually
180
-			if (isset($this->acquiredLocks['shared'][$path]) && $this->acquiredLocks['shared'][$path] > 1) {
181
-				throw new LockedException($path);
182
-			}
183
-			$qb = $this->connection->getQueryBuilder();
184
-			$result = $qb->update('file_locks')
185
-				->set('lock', $qb->createNamedParameter(-1, IQueryBuilder::PARAM_INT))
186
-				->set('ttl', $qb->createNamedParameter($expire, IQueryBuilder::PARAM_INT))
187
-				->where($qb->expr()->andX(
188
-					$qb->expr()->eq('key', $qb->createNamedParameter($path)),
189
-					$qb->expr()->eq('lock', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT))
190
-				))->executeStatement();
191
-		}
192
-		if ($result !== 1) {
193
-			throw new LockedException($path);
194
-		}
195
-		$this->markChange($path, $targetType);
196
-	}
197
-
198
-	/** @inheritDoc */
199
-	public function cleanExpiredLocks(): void {
200
-		$expire = $this->timeFactory->getTime();
201
-		try {
202
-			$qb = $this->connection->getQueryBuilder();
203
-			$qb->delete('file_locks')
204
-				->where($qb->expr()->lt('ttl', $qb->createNamedParameter($expire, IQueryBuilder::PARAM_INT)))
205
-				->executeStatement();
206
-		} catch (\Exception $e) {
207
-			// If the table is missing, the clean up was successful
208
-			if ($this->connection->tableExists('file_locks')) {
209
-				throw $e;
210
-			}
211
-		}
212
-	}
213
-
214
-	/** @inheritDoc */
215
-	public function releaseAll(): void {
216
-		parent::releaseAll();
217
-
218
-		if (!$this->cacheSharedLocks) {
219
-			return;
220
-		}
221
-		// since we keep shared locks we need to manually clean those
222
-		$lockedPaths = array_keys($this->sharedLocks);
223
-		$lockedPaths = array_filter($lockedPaths, function ($path) {
224
-			return $this->sharedLocks[$path];
225
-		});
226
-
227
-		$chunkedPaths = array_chunk($lockedPaths, 100);
228
-
229
-		$qb = $this->connection->getQueryBuilder();
230
-		$qb->update('file_locks')
231
-			->set('lock', $qb->func()->subtract('lock', $qb->expr()->literal(1)))
232
-			->where($qb->expr()->in('key', $qb->createParameter('chunk')))
233
-			->andWhere($qb->expr()->gt('lock', new Literal(0)));
234
-
235
-		foreach ($chunkedPaths as $chunk) {
236
-			$qb->setParameter('chunk', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
237
-			$qb->executeStatement();
238
-		}
239
-	}
21
+    private array $sharedLocks = [];
22
+
23
+    public function __construct(
24
+        private IDBConnection $connection,
25
+        private ITimeFactory $timeFactory,
26
+        int $ttl = 3600,
27
+        private bool $cacheSharedLocks = true,
28
+    ) {
29
+        parent::__construct($ttl);
30
+    }
31
+
32
+    /**
33
+     * Check if we have an open shared lock for a path
34
+     */
35
+    protected function isLocallyLocked(string $path): bool {
36
+        return isset($this->sharedLocks[$path]) && $this->sharedLocks[$path];
37
+    }
38
+
39
+    /** @inheritDoc */
40
+    protected function markAcquire(string $path, int $targetType): void {
41
+        parent::markAcquire($path, $targetType);
42
+        if ($this->cacheSharedLocks) {
43
+            if ($targetType === self::LOCK_SHARED) {
44
+                $this->sharedLocks[$path] = true;
45
+            }
46
+        }
47
+    }
48
+
49
+    /**
50
+     * Change the type of an existing tracked lock
51
+     */
52
+    protected function markChange(string $path, int $targetType): void {
53
+        parent::markChange($path, $targetType);
54
+        if ($this->cacheSharedLocks) {
55
+            if ($targetType === self::LOCK_SHARED) {
56
+                $this->sharedLocks[$path] = true;
57
+            } elseif ($targetType === self::LOCK_EXCLUSIVE) {
58
+                $this->sharedLocks[$path] = false;
59
+            }
60
+        }
61
+    }
62
+
63
+    /**
64
+     * Insert a file locking row if it does not exists.
65
+     */
66
+    protected function initLockField(string $path, int $lock = 0): int {
67
+        $expire = $this->getExpireTime();
68
+        return $this->connection->insertIgnoreConflict('file_locks', [
69
+            'key' => $path,
70
+            'lock' => $lock,
71
+            'ttl' => $expire
72
+        ]);
73
+    }
74
+
75
+    protected function getExpireTime(): int {
76
+        return $this->timeFactory->getTime() + $this->ttl;
77
+    }
78
+
79
+    /** @inheritDoc */
80
+    public function isLocked(string $path, int $type): bool {
81
+        if ($this->hasAcquiredLock($path, $type)) {
82
+            return true;
83
+        }
84
+        $query = $this->connection->getQueryBuilder();
85
+        $query->select('lock')
86
+            ->from('file_locks')
87
+            ->where($query->expr()->eq('key', $query->createNamedParameter($path)));
88
+        $result = $query->executeQuery();
89
+        $lockValue = (int)$result->fetchOne();
90
+        if ($type === self::LOCK_SHARED) {
91
+            if ($this->isLocallyLocked($path)) {
92
+                // if we have a shared lock we kept open locally but it's released we always have at least 1 shared lock in the db
93
+                return $lockValue > 1;
94
+            } else {
95
+                return $lockValue > 0;
96
+            }
97
+        } elseif ($type === self::LOCK_EXCLUSIVE) {
98
+            return $lockValue === -1;
99
+        } else {
100
+            return false;
101
+        }
102
+    }
103
+
104
+    /** @inheritDoc */
105
+    public function acquireLock(string $path, int $type, ?string $readablePath = null): void {
106
+        $expire = $this->getExpireTime();
107
+        if ($type === self::LOCK_SHARED) {
108
+            if (!$this->isLocallyLocked($path)) {
109
+                $result = $this->initLockField($path, 1);
110
+                if ($result <= 0) {
111
+                    $query = $this->connection->getQueryBuilder();
112
+                    $query->update('file_locks')
113
+                        ->set('lock', $query->func()->add('lock', $query->createNamedParameter(1, IQueryBuilder::PARAM_INT)))
114
+                        ->set('ttl', $query->createNamedParameter($expire))
115
+                        ->where($query->expr()->eq('key', $query->createNamedParameter($path)))
116
+                        ->andWhere($query->expr()->gte('lock', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
117
+                    $result = $query->executeStatement();
118
+                }
119
+            } else {
120
+                $result = 1;
121
+            }
122
+        } else {
123
+            $existing = 0;
124
+            if ($this->hasAcquiredLock($path, ILockingProvider::LOCK_SHARED) === false && $this->isLocallyLocked($path)) {
125
+                $existing = 1;
126
+            }
127
+            $result = $this->initLockField($path, -1);
128
+            if ($result <= 0) {
129
+                $query = $this->connection->getQueryBuilder();
130
+                $query->update('file_locks')
131
+                    ->set('lock', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT))
132
+                    ->set('ttl', $query->createNamedParameter($expire, IQueryBuilder::PARAM_INT))
133
+                    ->where($query->expr()->eq('key', $query->createNamedParameter($path)))
134
+                    ->andWhere($query->expr()->eq('lock', $query->createNamedParameter($existing)));
135
+                $result = $query->executeStatement();
136
+            }
137
+        }
138
+        if ($result !== 1) {
139
+            throw new LockedException($path, null, null, $readablePath);
140
+        }
141
+        $this->markAcquire($path, $type);
142
+    }
143
+
144
+    /** @inheritDoc */
145
+    public function releaseLock(string $path, int $type): void {
146
+        $this->markRelease($path, $type);
147
+
148
+        // we keep shared locks till the end of the request so we can re-use them
149
+        if ($type === self::LOCK_EXCLUSIVE) {
150
+            $qb = $this->connection->getQueryBuilder();
151
+            $qb->update('file_locks')
152
+                ->set('lock', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT))
153
+                ->where($qb->expr()->eq('key', $qb->createNamedParameter($path)))
154
+                ->andWhere($qb->expr()->eq('lock', $qb->createNamedParameter(-1, IQueryBuilder::PARAM_INT)));
155
+            $qb->executeStatement();
156
+        } elseif (!$this->cacheSharedLocks) {
157
+            $qb = $this->connection->getQueryBuilder();
158
+            $qb->update('file_locks')
159
+                ->set('lock', $qb->func()->subtract('lock', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)))
160
+                ->where($qb->expr()->eq('key', $qb->createNamedParameter($path)))
161
+                ->andWhere($qb->expr()->gt('lock', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
162
+            $qb->executeStatement();
163
+        }
164
+    }
165
+
166
+    /** @inheritDoc */
167
+    public function changeLock(string $path, int $targetType): void {
168
+        $expire = $this->getExpireTime();
169
+        if ($targetType === self::LOCK_SHARED) {
170
+            $qb = $this->connection->getQueryBuilder();
171
+            $result = $qb->update('file_locks')
172
+                ->set('lock', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT))
173
+                ->set('ttl', $qb->createNamedParameter($expire, IQueryBuilder::PARAM_INT))
174
+                ->where($qb->expr()->andX(
175
+                    $qb->expr()->eq('key', $qb->createNamedParameter($path)),
176
+                    $qb->expr()->eq('lock', $qb->createNamedParameter(-1, IQueryBuilder::PARAM_INT))
177
+                ))->executeStatement();
178
+        } else {
179
+            // since we only keep one shared lock in the db we need to check if we have more then one shared lock locally manually
180
+            if (isset($this->acquiredLocks['shared'][$path]) && $this->acquiredLocks['shared'][$path] > 1) {
181
+                throw new LockedException($path);
182
+            }
183
+            $qb = $this->connection->getQueryBuilder();
184
+            $result = $qb->update('file_locks')
185
+                ->set('lock', $qb->createNamedParameter(-1, IQueryBuilder::PARAM_INT))
186
+                ->set('ttl', $qb->createNamedParameter($expire, IQueryBuilder::PARAM_INT))
187
+                ->where($qb->expr()->andX(
188
+                    $qb->expr()->eq('key', $qb->createNamedParameter($path)),
189
+                    $qb->expr()->eq('lock', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT))
190
+                ))->executeStatement();
191
+        }
192
+        if ($result !== 1) {
193
+            throw new LockedException($path);
194
+        }
195
+        $this->markChange($path, $targetType);
196
+    }
197
+
198
+    /** @inheritDoc */
199
+    public function cleanExpiredLocks(): void {
200
+        $expire = $this->timeFactory->getTime();
201
+        try {
202
+            $qb = $this->connection->getQueryBuilder();
203
+            $qb->delete('file_locks')
204
+                ->where($qb->expr()->lt('ttl', $qb->createNamedParameter($expire, IQueryBuilder::PARAM_INT)))
205
+                ->executeStatement();
206
+        } catch (\Exception $e) {
207
+            // If the table is missing, the clean up was successful
208
+            if ($this->connection->tableExists('file_locks')) {
209
+                throw $e;
210
+            }
211
+        }
212
+    }
213
+
214
+    /** @inheritDoc */
215
+    public function releaseAll(): void {
216
+        parent::releaseAll();
217
+
218
+        if (!$this->cacheSharedLocks) {
219
+            return;
220
+        }
221
+        // since we keep shared locks we need to manually clean those
222
+        $lockedPaths = array_keys($this->sharedLocks);
223
+        $lockedPaths = array_filter($lockedPaths, function ($path) {
224
+            return $this->sharedLocks[$path];
225
+        });
226
+
227
+        $chunkedPaths = array_chunk($lockedPaths, 100);
228
+
229
+        $qb = $this->connection->getQueryBuilder();
230
+        $qb->update('file_locks')
231
+            ->set('lock', $qb->func()->subtract('lock', $qb->expr()->literal(1)))
232
+            ->where($qb->expr()->in('key', $qb->createParameter('chunk')))
233
+            ->andWhere($qb->expr()->gt('lock', new Literal(0)));
234
+
235
+        foreach ($chunkedPaths as $chunk) {
236
+            $qb->setParameter('chunk', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
237
+            $qb->executeStatement();
238
+        }
239
+    }
240 240
 }
Please login to merge, or discard this patch.