plugin->shim(); if ($shim === null) { WP_CLI::error('server tier not configured'); } $shim->refreshRouteSet(); WP_CLI::success('route set flushed'); } /** * List the routes with a live server patch. * * ## EXAMPLES * * wp sarcio routes */ public function routes(): void { $shim = $this->plugin->shim(); if ($shim === null) { WP_CLI::error('server tier not configured'); } $routes = $shim->routeSet(); if ($routes === []) { WP_CLI::log('no patched routes'); return; } foreach ($routes as $route) { WP_CLI::log($route); } } /** * Show how the plugin is wired up and whether the sidecar answers. * * ## EXAMPLES * * wp sarcio status */ public function status(): void { $shim = $this->plugin->shim(); $dsn = (string) Options::get('sidecar_dsn'); $transport = Options::serverTransport(); $healthy = false; if ($transport === 'sidecar' && Autoloader::shimAvailable()) { $client = Client::connect($dsn, 1.0); $healthy = $client !== null && $client->health(1.0); $client?->close(); } $pull = Pull::status(); $lastPull = $pull === [] ? 'none yet' : sprintf('%s ago, %s', human_time_diff((int) $pull['at']), !empty($pull['ok']) ? 'ok' : 'failed (previous patches kept)'); $rows = [ ['setting' => 'shim', 'value' => Autoloader::shimAvailable() ? 'bundled' : 'missing'], ['setting' => 'site key', 'value' => (string) Options::get('site_key') ?: '(unset)'], ['setting' => 'control plane', 'value' => Options::apiUrl()], ['setting' => 'widget', 'value' => Options::get('widget_enabled') ? (string) Options::get('widget_audience') : 'disabled'], ['setting' => 'server scope', 'value' => (string) Options::get('server_scope')], ['setting' => 'server transport', 'value' => $transport], ['setting' => 'sidecar dsn', 'value' => $dsn ?: '(unset)'], ['setting' => 'sidecar', 'value' => $transport !== 'sidecar' ? 'not in use' : ($healthy ? 'reachable' : 'unreachable')], ['setting' => 'last pull', 'value' => $transport === 'pull' ? $lastPull : 'n/a'], ['setting' => 'route cache', 'value' => $this->plugin->cacheBackend()], ['setting' => 'patched routes', 'value' => $shim === null ? 'n/a' : (string) count($shim->routeSet())], ]; WP_CLI\Utils\format_items('table', $rows, ['setting', 'value']); } /** * Fetch the site's signed fixes from Sarcio now (direct mode), instead of * waiting for the refresh window or WP-Cron. * * ## EXAMPLES * * wp sarcio pull */ public function pull(): void { if (Options::serverTransport() !== 'pull') { WP_CLI::error('direct mode is not in use (set the secret key and no sidecar address)'); } $ok = (new Pull($this->plugin))->run(); if (!$ok) { WP_CLI::warning('pull failed; the previously verified patches are kept'); return; } WP_CLI::success(sprintf('pulled; %d patched route(s)', count($this->plugin->shim()?->routeSet() ?? []))); } }