Automattic\WooCommerce\Internal\PushNotifications\Services
StepLogQuery::count_outcomes
Counts rows per step and outcome, as step:outcome keys.
A failure is logged twice, as an error line and as an info step line, so each step line cancels one error line for the same notification, step and outcome, and the failure counts once.
Method of the class: StepLogQuery{}
No Hooks.
Returns
array<string, int>.
Usage
$result = StepLogQuery::count_outcomes( $rows ): array;
- $rows(array) (required)
- The rows.
StepLogQuery::count_outcomes() StepLogQuery::count outcomes code WC 11.3.0
private static function count_outcomes( array $rows ): array {
$step_lines = array();
foreach ( $rows as $row ) {
$failure = self::get_failure_key( $row );
if ( null !== $failure && 'info' === $row['level'] ) {
$step_lines[ $failure ] = ( $step_lines[ $failure ] ?? 0 ) + 1;
}
}
$counts = array();
foreach ( $rows as $row ) {
if ( ! isset( $row['context']['step'], $row['context']['outcome'] ) ) {
continue;
}
$failure = self::get_failure_key( $row );
if ( null !== $failure && 'info' !== $row['level'] && ( $step_lines[ $failure ] ?? 0 ) > 0 ) {
--$step_lines[ $failure ];
continue;
}
$key = $row['context']['step'] . ':' . $row['context']['outcome'];
$counts[ $key ] = ( $counts[ $key ] ?? 0 ) + 1;
}
return $counts;
}