true, 'message' => '', ); } } return array( 'success' => false, 'message' => self::firstReason( $items ) ?? $fallback_message, ); } /** * How many items produced usable content: the items that did not fail. * Only these count as generated in the usage feed (owner decision * 2026-11-25), as the Description generator already counts its * successes; a request with none records no generated event. * * @param array $items Per-item result rows of one generate request. */ public static function succeededCount( array $items ): int { $count = 0; foreach ( $items as $item ) { if ( is_array( $item ) && ! self::failed( $item ) ) { ++$count; } } return $count; } /** * The product of the first item that produced content: the product the * usage feed row names, so a generated row never names a product whose * item failed. 0 when no item produced content or that item names no * product. * * @param array $items Per-item result rows of one generate request. */ public static function firstSucceededProductId( array $items ): int { foreach ( $items as $item ) { if ( is_array( $item ) && ! self::failed( $item ) ) { return (int) ( $item['product_id'] ?? 0 ); } } return 0; } /** * An item failed when it reports an error, or when its content was * generated but never reached the review queue (applying it locally * would bypass review). * * @param array $item One result row. */ private static function failed( array $item ): bool { return ! empty( $item['api_error'] ) || ! empty( $item['error'] ) || ! empty( $item['review_stage_failed'] ); } /** * @param array $items Per-item result rows. * @return string|null The first non-blank reason any item carries. */ private static function firstReason( array $items ): ?string { foreach ( $items as $item ) { if ( ! is_array( $item ) ) { continue; } foreach ( self::REASON_KEYS as $key ) { if ( isset( $item[ $key ] ) && is_string( $item[ $key ] ) && '' !== trim( $item[ $key ] ) ) { return $item[ $key ]; } } } return null; } }