] * : user, plugin or cli. * * [--tool=] * : backfill, embeddings, settings, ... * * [--failed] * : Only entries that failed or skipped something. * * [--since=] * : From this day (Y-m-d, UTC). * * [--until=] * : Up to this day (Y-m-d, UTC). * * [--limit=] * : How many. Default 20. * * [--format=] * : table, csv, json or yaml. Default table. * * ## EXAMPLES * * wp aipcf activity list --tool=backfill --failed * * @param list $args * @param array $assoc */ public function list(array $args, array $assoc): void { $rows = []; foreach (ActivityLog::entries(self::filters($assoc), max(1, (int) ($assoc['limit'] ?? 20))) as $e) { $rows[] = [ 'id' => $e['id'], 'time' => $e['ts'], 'who' => Labels::who($e), 'tool' => $e['tool'], 'action' => $e['action'], 'status' => $e['status'], 'ok' => $e['items_ok'], 'failed' => $e['items_failed'], 'neurons' => round($e['neurons'], 2), 'message' => $e['message'], ]; } \WP_CLI\Utils\format_items($assoc['format'] ?? 'table', $rows, ['id', 'time', 'who', 'tool', 'action', 'status', 'ok', 'failed', 'neurons', 'message']); } /** * Writes the log as CSV, one row per change: the same file as Download CSV. * * ## OPTIONS * * [--who=] * : user, plugin or cli. * * [--tool=] * : backfill, embeddings, settings, ... * * [--failed] * : Only entries that failed or skipped something. * * [--since=] * : From this day (Y-m-d, UTC). * * [--until=] * : Up to this day (Y-m-d, UTC). * * [--file=] * : Write to this file instead of the screen. * * ## EXAMPLES * * wp aipcf activity export --tool=backfill --file=backfill.csv * * @param list $args * @param array $assoc */ public function export(array $args, array $assoc): void { $file = (string) ($assoc['file'] ?? ''); $out = $file !== '' ? fopen($file, 'w') : fopen('php://stdout', 'w'); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- a WP-CLI command writing where the operator asked if ($out === false) { \WP_CLI::error(sprintf('Cannot write to %s.', $file)); } $rows = Export::write($out, self::filters($assoc)); fclose($out); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose if ($file !== '') { \WP_CLI::success(sprintf($rows === 1 ? '%d row written to %s.' : '%d rows written to %s.', $rows, $file)); } } /** * @param array $assoc * @return array */ private static function filters(array $assoc): array { foreach (['since', 'until'] as $k) { if (isset($assoc[$k]) && ActivityLog::day((string) $assoc[$k]) === '') { \WP_CLI::error(sprintf('--%s must be a date like 2026-10-02.', $k)); } } return [ 'who' => (string) ($assoc['who'] ?? ''), 'tool' => (string) ($assoc['tool'] ?? ''), 'failed' => isset($assoc['failed']), 'since' => (string) ($assoc['since'] ?? ''), 'until' => (string) ($assoc['until'] ?? ''), ]; } }