getModel()->getSearchInterface(); $deliveryAssemblyService = DeliveryAssemblyService::singleton(); $queryBuilder = $search->query(); $query = $search->searchType($queryBuilder, $deliveryAssemblyService->getRootClass()->getUri(), true); $queryBuilder->setCriteria($query); $searchResult = $search->getGateway()->search($queryBuilder); $failedDeliveries = []; /** @var \core_kernel_classes_Resource $instance */ foreach ($searchResult as $instance) { try { $value = DeliveryAssemblyService::singleton()->getRuntime($instance); if (is_null($value)) { $failedDeliveries[] = $instance; } } catch (\common_Exception $e) { $failedDeliveries[] = $instance; } } /** @var \core_kernel_classes_Resource $failedDelivery */ foreach ($failedDeliveries as $failedDelivery) { $failedDelivery->delete(true); $report->add(common_report_Report::createSuccess('Delivery deleted:' . $failedDelivery->getUri())); } return $report; } }