Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions inc/Abilities/Flow/GetFlowsAbility.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class GetFlowsAbility {

use FlowHelpers;

/**
* Default per_page for REST/chat callers. CLI defaults to 0 (all).
*/
private const DEFAULT_PER_PAGE = 20;

public function __construct() {
Expand Down Expand Up @@ -62,9 +65,8 @@ private function registerAbility(): void {
'per_page' => array(
'type' => 'integer',
'default' => self::DEFAULT_PER_PAGE,
'minimum' => 1,
'maximum' => 100,
'description' => __( 'Number of flows per page', 'data-machine' ),
'minimum' => 0,
'description' => __( 'Number of flows per page. 0 = return all flows (no pagination).', 'data-machine' ),
),
'offset' => array(
'type' => 'integer',
Expand Down Expand Up @@ -122,6 +124,9 @@ public function execute( array $input ): array {
$offset = (int) ( $input['offset'] ?? 0 );
$output_mode = $input['output_mode'] ?? 'full';

// per_page=0 means "return all" — used by CLI. Use PHP_INT_MAX to bypass pagination.
$effective_per_page = ( 0 === $per_page ) ? PHP_INT_MAX : $per_page;

if ( ! in_array( $output_mode, array( 'full', 'summary', 'ids' ), true ) ) {
$output_mode = 'full';
}
Expand Down Expand Up @@ -164,10 +169,10 @@ public function execute( array $input ): array {
$total = 0;

if ( $pipeline_id ) {
$flows = $this->db_flows->get_flows_for_pipeline_paginated( $pipeline_id, $per_page, $offset );
$flows = $this->db_flows->get_flows_for_pipeline_paginated( $pipeline_id, $effective_per_page, $offset );
$total = $this->db_flows->count_flows_for_pipeline( $pipeline_id );
} else {
$flows = $this->getAllFlowsPaginated( $per_page, $offset, $user_id, $agent_id );
$flows = $this->getAllFlowsPaginated( $effective_per_page, $offset, $user_id, $agent_id );
$total = $this->countAllFlows( $user_id, $agent_id );
}

Expand Down
13 changes: 5 additions & 8 deletions inc/Cli/Commands/Flows/FlowsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class FlowsCommand extends BaseCommand {
* : Filter flows using this handler slug (any step that uses this handler).
*
* [--per_page=<number>]
* : Number of flows to return.
* : Number of flows to return. 0 = all (default).
* ---
* default: 20
* default: 0
* ---
*
* [--offset=<number>]
Expand Down Expand Up @@ -287,15 +287,12 @@ public function __invoke( array $args, array $assoc_args ): void {
}

$handler_slug = $assoc_args['handler'] ?? null;
$per_page = (int) ( $assoc_args['per_page'] ?? 20 );
$per_page = (int) ( $assoc_args['per_page'] ?? 0 );
$offset = (int) ( $assoc_args['offset'] ?? 0 );
$format = $assoc_args['format'] ?? 'table';

if ( $per_page < 1 ) {
$per_page = 20;
}
if ( $per_page > 100 ) {
$per_page = 100;
if ( $per_page < 0 ) {
$per_page = 0;
}
if ( $offset < 0 ) {
$offset = 0;
Expand Down
Loading