|null, move: array|null, moved_from: array|null, last_run: int, last_message: string, last_error: string, done: int, failed: int} */ public static function get(): array { $s = get_option(self::OPTION, []); $s = is_array($s) ? $s : []; return [ 'generation' => max(1, (int) ($s['generation'] ?? 1)), 'previous_index' => (string) ($s['previous_index'] ?? ''), 'previous_model' => (string) ($s['previous_model'] ?? ''), 'index_model' => (string) ($s['index_model'] ?? ''), 'paused' => (string) ($s['paused'] ?? ''), 'reconcile' => is_array($s['reconcile'] ?? null) ? $s['reconcile'] : null, 'move' => is_array($s['move'] ?? null) ? $s['move'] : null, 'moved_from' => is_array($s['moved_from'] ?? null) ? $s['moved_from'] : null, 'last_run' => (int) ($s['last_run'] ?? 0), 'last_message' => (string) ($s['last_message'] ?? ''), 'last_error' => (string) ($s['last_error'] ?? ''), 'done' => (int) ($s['done'] ?? 0), 'failed' => (int) ($s['failed'] ?? 0), ]; } /** * @param array $changes */ public static function update(array $changes): void { update_option(self::OPTION, array_merge(self::get(), $changes), false); } public static function generation(): int { return self::get()['generation']; } /** * A store name with the generation appended from the second generation on * ("name-g2"), kept within $max bytes. */ public static function suffixed(string $base, int $max, string $separator = '-'): string { $gen = self::generation(); if ($gen <= 1) { return substr($base, 0, $max); } $suffix = $separator . 'g' . $gen; return rtrim(substr($base, 0, $max - strlen($suffix)), '-_') . $suffix; } public static function pause(string $reason): void { self::update(['paused' => $reason, 'last_error' => $reason]); } public static function resume(): void { self::update(['paused' => '']); } }