public function list_events($args, $assoc_args)
{
$events = $this->get_events($args, $assoc_args);
// Prevent one from requesting a page that doesn't exist
// Shouldn't error when first page is requested, though, as that is handled below and is an odd behaviour otherwise
if ($events['page'] > $events['total_pages'] && $events['page'] > 1) {
\WP_CLI::error(__('Invalid page requested', 'automattic-cron-control'));
}
// Output in the requested format
if (isset($assoc_args['format']) && 'ids' === $assoc_args['format']) {
echo implode(' ', wp_list_pluck($events['items'], 'ID'));
} else {
// Lest someone think the `completed` record should be...complete
if (isset($assoc_args['status']) && 'completed' === $assoc_args['status']) {
\WP_CLI::warning(__('Entries are purged automatically, so this cannot be relied upon as a record of past event execution.', 'automattic-cron-control'));
}
// Not much to do
if (0 === $events['total_items'] || empty($events['items'])) {
\WP_CLI::warning(__('No events to display', 'automattic-cron-control'));
return;
}
// Prepare events for display
$events_for_display = $this->format_events($events['items']);
$total_events_to_display = count($events_for_display);
// Count, noting if showing fewer than all
if ($events['total_items'] <= $total_events_to_display) {
\WP_CLI::line(sprintf(_n('Displaying one entry', 'Displaying all %s entries', $total_events_to_display, 'automattic-cron-control'), number_format_i18n($total_events_to_display)));
} else {
\WP_CLI::line(sprintf(__('Displaying %1$s of %2$s entries, page %3$s of %4$s', 'automattic-cron-control'), number_format_i18n($total_events_to_display), number_format_i18n($events['total_items']), number_format_i18n($events['page']), number_format_i18n($events['total_pages'])));
}
// And reformat
$format = 'table';
if (isset($assoc_args['format'])) {
$format = $assoc_args['format'];
}
\WP_CLI\Utils\format_items($format, $events_for_display, array('ID', 'action', 'instance', 'next_run_gmt', 'next_run_relative', 'last_updated_gmt', 'recurrence', 'internal_event', 'schedule_name', 'event_args'));
}
}