| 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 |
|