PluginProbe
404 Solution / trunk
404 Solution vtrunk
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / gsc / GscFetchLockStore.php

GscFetchLockStore.php in 404 Solution trunk, at includes/gsc/GscFetchLockStore.php

65 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // allow-no-test-found: exercised through GscFetchPipelineTest lock lifecycle and migration scenarios
4
5 if (!defined('ABSPATH')) {
6 exit;
7 }
8
9 require_once __DIR__ . '/GscConfig.php';
10
11 /** Persistence adapter for the GSC fetch lock and its migration marker. */
12 final class ABJ_404_Solution_GscFetchLockStore {
13
14 /** @return mixed */
15 public function atomicReadyAt() {
16 return get_option(ABJ_404_Solution_GscConfig::ATOMIC_LOCK_READY_OPTION, false);
17 }
18
19 public function persistAtomicReadyAt(int $readyAt): bool {
20 return update_option(
21 ABJ_404_Solution_GscConfig::ATOMIC_LOCK_READY_OPTION,
22 (string)$readyAt,
23 false
24 );
25 }
26
27 /** @return mixed */
28 public function legacyOwner() {
29 return get_transient(ABJ_404_Solution_GscConfig::LOCK_TRANSIENT_KEY);
30 }
31
32 /** @param array{value: string} $claim */
33 public function claim(array $claim): bool {
34 return $this->row()->claim(array(
35 'optionName' => ABJ_404_Solution_GscConfig::LOCK_TRANSIENT_KEY,
36 'value' => $claim['value'],
37 ));
38 }
39
40 public function owner(): string {
41 return $this->row()->valueOf(ABJ_404_Solution_GscConfig::LOCK_TRANSIENT_KEY);
42 }
43
44 /** @param array{value: string} $release */
45 public function release(array $release): bool {
46 return $this->row()->releaseIfValueIs(array(
47 'optionName' => ABJ_404_Solution_GscConfig::LOCK_TRANSIENT_KEY,
48 'value' => $release['value'],
49 ));
50 }
51
52 /** @param array{currentValue: string, replacementValue: string} $renewal */
53 public function renew(array $renewal): bool {
54 return $this->row()->replaceValueIfMatches(array(
55 'optionName' => ABJ_404_Solution_GscConfig::LOCK_TRANSIENT_KEY,
56 'currentValue' => $renewal['currentValue'],
57 'replacementValue' => $renewal['replacementValue'],
58 ));
59 }
60
61 private function row(): ABJ_404_Solution_ExclusiveOptionRow {
62 return new ABJ_404_Solution_ExclusiveOptionRow();
63 }
64 }
65