runs->find_open_for_subject( $subject_type, $subject_id ) as $run ) { $this->maybe_cancel( $run, $event ); $id = $run->id(); if ( null !== $id ) { $seen[ $id ] = true; } } if ( null === $customer_id || $customer_id < 1 ) { return; } foreach ( $this->runs->find_open_for_customer( $customer_id ) as $run ) { $rid = $run->id(); if ( null !== $rid && isset( $seen[ $rid ] ) ) { continue; } $this->maybe_cancel( $run, $event ); } } /** * Cancel one run if the automation listens for the event. * * @param \Bookline\Domain\Automation\AutomationRun $run Run. * @param string $event Event. */ private function maybe_cancel( \Bookline\Domain\Automation\AutomationRun $run, string $event ): void { $automation = $this->automations->find_by_id( $run->automation_id() ); if ( null === $automation ) { return; } $cancel = $automation->cancel_if(); if ( null === $cancel || ! $cancel->matches( $event ) ) { return; } $this->executor->cancel_run( $run, SkipReason::CancelIf ); } }