| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Public contract for redirect CRUD, conditions, regex matching, and cleanup operations. |
| 9 |
* |
| 10 |
* Extracted from DataAccess in Phase 2 of the DataAccess refactor. Callers that |
| 11 |
* need redirect lookups, mutations, scheduled cleanup, or condition management |
| 12 |
* program against this interface. |
| 13 |
*/ |
| 14 |
interface ABJ_404_Solution_RedirectsRepositoryInterface { |
| 15 |
|
| 16 |
// ========================================================================= |
| 17 |
// Redirect CRUD (from DataAccessTrait_Redirects) |
| 18 |
// ========================================================================= |
| 19 |
|
| 20 |
/** |
| 21 |
* @param int|string $id |
| 22 |
* @return void |
| 23 |
*/ |
| 24 |
public function deleteRedirect($id); |
| 25 |
|
| 26 |
/** |
| 27 |
* Store a redirect for future use. |
| 28 |
* |
| 29 |
* @param string $fromURL |
| 30 |
* @param string $status ABJ404_STATUS_MANUAL etc |
| 31 |
* @param string $type ABJ404_TYPE_POST, ABJ404_TYPE_CAT, ABJ404_TYPE_TAG, etc. |
| 32 |
* @param string $final_dest |
| 33 |
* @param string $code |
| 34 |
* @param int $disabled |
| 35 |
* @param string|null $engine |
| 36 |
* @param float|null $score |
| 37 |
* @return int |
| 38 |
*/ |
| 39 |
public function setupRedirect($fromURL, $status, $type, $final_dest, $code, $disabled = 0, $engine = null, $score = null); |
| 40 |
|
| 41 |
/** |
| 42 |
* @param string $url |
| 43 |
* @param bool $degradedMode |
| 44 |
* @return array<string, mixed> |
| 45 |
*/ |
| 46 |
public function getActiveRedirectForURL($url, $degradedMode = false); |
| 47 |
|
| 48 |
/** |
| 49 |
* @param string $url |
| 50 |
* @return array<string, mixed> |
| 51 |
*/ |
| 52 |
public function getExistingRedirectForURL($url); |
| 53 |
|
| 54 |
/** @return string */ |
| 55 |
public function deleteSpecifiedRedirects(); |
| 56 |
|
| 57 |
// ========================================================================= |
| 58 |
// Redirect conditions (from DataAccessTrait_Redirects) |
| 59 |
// ========================================================================= |
| 60 |
|
| 61 |
/** |
| 62 |
* @param int $redirectId |
| 63 |
* @return array<int, array<string, mixed>> |
| 64 |
*/ |
| 65 |
public function getRedirectConditions(int $redirectId): array; |
| 66 |
|
| 67 |
/** |
| 68 |
* @param int $redirectId |
| 69 |
* @param array<int, array<string, mixed>> $conditions |
| 70 |
* @return void |
| 71 |
*/ |
| 72 |
public function saveRedirectConditions(int $redirectId, array $conditions): void; |
| 73 |
|
| 74 |
// ========================================================================= |
| 75 |
// Redirect updates (from DataAccessTrait_Stats) |
| 76 |
// ========================================================================= |
| 77 |
|
| 78 |
/** |
| 79 |
* @param string $type |
| 80 |
* @param string $dest |
| 81 |
* @param string $fromURL |
| 82 |
* @param int $idForUpdate |
| 83 |
* @param string $redirectCode |
| 84 |
* @param string $statusType |
| 85 |
* @param int|null $startTs |
| 86 |
* @param int|null $endTs |
| 87 |
* @return string |
| 88 |
*/ |
| 89 |
public function updateRedirect($type, $dest, $fromURL, $idForUpdate, $redirectCode, $statusType, $startTs = null, $endTs = null); |
| 90 |
|
| 91 |
/** |
| 92 |
* @param array<int, int|string> $ids |
| 93 |
* @return array<int, array<string, mixed>> |
| 94 |
*/ |
| 95 |
public function getRedirectsByIDs($ids); |
| 96 |
|
| 97 |
/** |
| 98 |
* @param int $id |
| 99 |
* @param string $newstatus |
| 100 |
* @return string |
| 101 |
*/ |
| 102 |
public function updateRedirectTypeStatus($id, $newstatus); |
| 103 |
|
| 104 |
/** |
| 105 |
* @param int $id |
| 106 |
* @param int $trash |
| 107 |
* @return string |
| 108 |
*/ |
| 109 |
public function moveRedirectsToTrash($id, $trash); |
| 110 |
|
| 111 |
// ========================================================================= |
| 112 |
// Cron maintenance (from DataAccessTrait_Redirects) |
| 113 |
// ========================================================================= |
| 114 |
|
| 115 |
/** @return int */ |
| 116 |
public function cleanupOrphanedAutoRedirects(): int; |
| 117 |
|
| 118 |
/** @return string */ |
| 119 |
public function deleteOldRedirectsCron(); |
| 120 |
|
| 121 |
/** @return int */ |
| 122 |
public function removeDuplicatesCron(): int; |
| 123 |
|
| 124 |
/** @return bool */ |
| 125 |
public function limitDebugFileSize(): bool; |
| 126 |
|
| 127 |
/** |
| 128 |
* @param array<string, mixed> $options |
| 129 |
* @return int |
| 130 |
*/ |
| 131 |
public function autoTrashJunkCapturedUrls(array $options): int; |
| 132 |
|
| 133 |
// ========================================================================= |
| 134 |
// Redirect maintenance (from DataAccessTrait_Maintenance, Phase 5) |
| 135 |
// ========================================================================= |
| 136 |
|
| 137 |
/** |
| 138 |
* Flag redirects whose destination URL appears in the 404 log as a recent 404. |
| 139 |
* |
| 140 |
* @return void |
| 141 |
*/ |
| 142 |
public function flagDeadDestinationRedirects(): void; |
| 143 |
|
| 144 |
/** |
| 145 |
* Move auto-created redirects to trash if they are older than the configured expiration. |
| 146 |
* |
| 147 |
* @return int Number of redirects moved to trash |
| 148 |
*/ |
| 149 |
public function expireOldAutoRedirects(): int; |
| 150 |
|
| 151 |
// ========================================================================= |
| 152 |
// Regex cache (from DataAccess static state) |
| 153 |
// ========================================================================= |
| 154 |
|
| 155 |
/** @return void */ |
| 156 |
public function clearRegexRedirectsCache(): void; |
| 157 |
|
| 158 |
// ========================================================================= |
| 159 |
// Static utilities (from DataAccessTrait_Redirects) |
| 160 |
// ========================================================================= |
| 161 |
|
| 162 |
/** |
| 163 |
* @param mixed $url |
| 164 |
* @return string |
| 165 |
*/ |
| 166 |
public static function computeRedirectsCanonicalUrl($url): string; |
| 167 |
|
| 168 |
/** |
| 169 |
* @param string $columnExpr |
| 170 |
* @return string |
| 171 |
*/ |
| 172 |
public static function hitsCanonicalUrlSqlExpression(string $columnExpr): string; |
| 173 |
} |
| 174 |
|