PluginProbe
404 Solution / 4.3.0
404 Solution v4.3.0
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 / database / upgrades / DatabaseUpgradeComponent.php

DatabaseUpgradeComponent.php in 404 Solution 4.3.0, at includes/database/upgrades/DatabaseUpgradeComponent.php

185 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 /**
8 * Shared dependency carrier for DatabaseUpgradesEtc delegates.
9 */
10 abstract class ABJ_404_Solution_DatabaseUpgradeComponent {
11
12 /** @var ABJ_404_Solution_DatabaseUpgradeCoordinator */
13 private $owner;
14
15 /** @var ABJ_404_Solution_DataAccess */
16 protected $dao;
17
18 /** @var ABJ_404_Solution_DatabaseCore */
19 protected $dbCore;
20
21 /** @var ABJ_404_Solution_ContentRepositoryInterface */
22 protected $contentRepo;
23
24 /** @var ABJ_404_Solution_ViewReadServiceInterface */
25 protected $viewRead;
26
27 /** @var ABJ_404_Solution_LogsRepositoryInterface */
28 protected $logsRepo;
29
30 /** @var ABJ_404_Solution_PluginUpdateMetadataRepository */
31 protected $pluginUpdateRepo;
32
33 /** @var ABJ_404_Solution_Logging */
34 protected $logger;
35
36 /** @var ABJ_404_Solution_Functions */
37 protected $f;
38
39 /** @var ABJ_404_Solution_PermalinkCache */
40 protected $permalinkCache;
41
42 /** @var ABJ_404_Solution_SynchronizationUtils */
43 protected $syncUtils;
44
45 /** @var ABJ_404_Solution_PluginLogicInterface */
46 protected $logic;
47
48 /** @var ABJ_404_Solution_NGramFilter */
49 protected $ngramFilter;
50
51 /** @var mixed */
52 protected $ngramExtractor;
53
54 /** @var mixed */
55 protected $ngramCacheRepository;
56
57 /** @var mixed */
58 protected $ngramCoveragePolicy;
59
60 /** @var mixed */
61 protected $ngramRebuilder;
62
63 /** @var ABJ_404_Solution_CronScheduler|null Optional injected cron scheduler; null falls back to abj_cron_scheduler(). */
64 protected $cronScheduler;
65
66 /**
67 * @param array<string, mixed> $deps
68 */
69 public function __construct(ABJ_404_Solution_DatabaseUpgradeCoordinator $owner, array $deps) {
70 $this->owner = $owner;
71 $this->replaceDatabaseUpgradeDependencies($deps);
72 }
73
74 /**
75 * @param array<string, mixed> $deps
76 * @return void
77 */
78 public function replaceDatabaseUpgradeDependencies(array $deps) {
79 foreach ($deps as $name => $value) {
80 $this->$name = $value;
81 }
82 }
83
84 protected function upgrades(): ABJ_404_Solution_DatabaseUpgradeCoordinator {
85 return $this->owner;
86 }
87
88 /**
89 * Case-insensitive "does this column exist" probe. Delegates to the
90 * canonical-url backfill component's implementation so the SHOW COLUMNS
91 * probe has a single source of truth. Components that own the real probe
92 * (the canonical-url backfill) override this; every other component inherits
93 * this shared delegator.
94 *
95 * @param string $tableName Fully-qualified table name.
96 * @param string $columnName Column to look for.
97 * @return bool
98 */
99 public function columnExists(string $tableName, string $columnName): bool {
100 return $this->upgrades()->canonicalUrlBackfillUpgrade()->columnExists($tableName, $columnName);
101 }
102
103 /**
104 * Read a resumable id cursor from a WordPress option, clamped to a
105 * non-negative int. Shared by the chunked backfill drains so the cursor I/O
106 * has one definition.
107 *
108 * @param string $option
109 * @return int
110 */
111 protected function readCursorOption(string $option): int {
112 if ($option === '' || !function_exists('get_option')) {
113 return 0;
114 }
115 $raw = get_option($option, 0);
116 return max(0, is_scalar($raw) ? (int)$raw : 0);
117 }
118
119 /**
120 * Persist a resumable id cursor to a WordPress option (autoload=false,
121 * non-negative). Shared by the chunked backfill drains.
122 *
123 * @param string $option
124 * @param int $cursor
125 * @return void
126 */
127 protected function writeCursorOption(string $option, int $cursor): void {
128 if ($option === '' || !function_exists('update_option')) {
129 return;
130 }
131 update_option($option, (string)max(0, $cursor), false);
132 }
133
134 /** @return string|null */
135 protected function getUpgradeRuntimeId() {
136 return ABJ_404_Solution_DatabaseUpgradeRuntimeState::getRuntimeId();
137 }
138
139 protected function getCanonicalUrlBackfillChunkSize(): int {
140 return ABJ_404_Solution_DatabaseUpgradeRuntimeState::CANONICAL_URL_BACKFILL_CHUNK_SIZE;
141 }
142
143 protected function getCanonicalUrlBackfillTimeBudgetSec(): float {
144 return ABJ_404_Solution_DatabaseUpgradeRuntimeState::CANONICAL_URL_BACKFILL_TIME_BUDGET_SEC;
145 }
146
147 protected function getLogsv2CanonicalUrlBackfillTimeBudgetSec(): float {
148 return ABJ_404_Solution_DatabaseUpgradeRuntimeState::LOGSV2_CANONICAL_URL_BACKFILL_TIME_BUDGET_SEC;
149 }
150
151 protected function getLogsv2CanonicalUrlBackfillCompleteOption(): string {
152 return ABJ_404_Solution_DatabaseUpgradeRuntimeState::LOGSV2_CANONICAL_URL_BACKFILL_COMPLETE_OPTION;
153 }
154
155 protected function getRedirectsCanonicalUrlBackfillCompleteOption(): string {
156 return ABJ_404_Solution_DatabaseUpgradeRuntimeState::REDIRECTS_CANONICAL_URL_BACKFILL_COMPLETE_OPTION;
157 }
158
159 protected function getRedirectsDenormBackfillChunkSize(): int {
160 return ABJ_404_Solution_DatabaseUpgradeRuntimeState::REDIRECTS_DENORM_BACKFILL_CHUNK_SIZE;
161 }
162
163 protected function getRedirectsDenormBackfillTimeBudgetSec(): float {
164 return ABJ_404_Solution_DatabaseUpgradeRuntimeState::REDIRECTS_DENORM_BACKFILL_TIME_BUDGET_SEC;
165 }
166
167 protected function getRedirectsDenormReconcileChunkSize(): int {
168 return ABJ_404_Solution_DatabaseUpgradeRuntimeState::REDIRECTS_DENORM_RECONCILE_CHUNK_SIZE;
169 }
170
171 protected function getRedirectsDenormReconcileTimeBudgetSec(): float {
172 return ABJ_404_Solution_DatabaseUpgradeRuntimeState::REDIRECTS_DENORM_RECONCILE_TIME_BUDGET_SEC;
173 }
174
175 protected function getRedirectsDenormReconcileCursorOption(): string {
176 return ABJ_404_Solution_DatabaseUpgradeRuntimeState::REDIRECTS_DENORM_RECONCILE_CURSOR_OPTION;
177 }
178
179 /** @return array<int, string> */
180 protected function getPluginTableSuffixes(): array {
181 return ABJ_404_Solution_DatabaseUpgradeRuntimeState::getPluginTableSuffixes();
182 }
183
184 }
185