*/ protected function input_properties(): array { return array( 'id' => array( 'type' => 'integer', 'description' => __( 'Variable product id.', 'acrossai-abilities-manager' ) ), 'apply' => array( 'type' => 'boolean', 'default' => false, 'description' => __( 'Create them. Without this the call only reports what it would do.', 'acrossai-abilities-manager' ) ), ); } /** * @since 0.0.34 * @return array */ protected function required_input(): array { return array( 'id' ); } /** * @since 0.0.34 * @return array */ protected function output_properties(): array { return array( 'dry_run' => array( 'type' => 'boolean' ), 'existing_count' => array( 'type' => 'integer' ), 'would_create' => array( 'type' => 'array', 'items' => array( 'type' => 'object', 'additionalProperties' => true ) ), 'would_create_count' => array( 'type' => 'integer' ), 'created' => array( 'type' => 'array', 'items' => array( 'type' => 'object', 'additionalProperties' => true ) ), 'note' => array( 'type' => 'string' ), ); } /** * @since 0.0.34 * @return array */ protected function annotations(): array { return array( 'readonly' => false, 'destructive' => false, 'idempotent' => false, ); } /** * @since 0.0.34 * @return bool */ protected function requires_confirmation(): bool { return true; } /** * @since 0.0.34 * @return string */ protected function confirmation_message(): string { return __( 'This creates a product record for every attribute combination, which can be a large number at once. Pass confirm: true together with apply: true to build them.', 'acrossai-abilities-manager' ); } /** * Only the real run asks. * * A dry run changes nothing, so demanding confirmation for it is pure friction — and worse, it * teaches a caller to pass confirm reflexively, which is exactly the habit the gate exists to * prevent. Measured: the first version asked for confirmation on a preview. * * @since 0.0.34 * @param array $input Input. * @return bool */ protected function needs_confirmation_for( array $input ): bool { return ! empty( $input['apply'] ); } /** * @since 0.0.34 * @param array $input Input. * @return array|WP_Error */ protected function run( array $input ) { return Product_Repository::generate_variations( (int) $input['id'], ! empty( $input['apply'] ) ); } }