om = $om; $this->repository = $repo; } public function create(ApiApplication $application, WebhookEvent $event) { $delivery = new WebhookEventDelivery(); $delivery->setThirdPartyApplication($application); $delivery->setWebhookEvent($event); $this->update($delivery); return $delivery; } public function delete(WebhookEventDelivery $delivery) { $this->om->remove($delivery); $this->om->flush(); } public function update(WebhookEventDelivery $delivery) { $this->om->persist($delivery); $this->om->flush(); } public function deliverySuccess(WebhookEventDelivery $delivery) { $delivery->setDelivered(true); $delivery->setDeliverTries($delivery->getDeliveryTries() + 1); $this->update($delivery); } public function deliveryFailure(WebhookEventDelivery $delivery) { $delivery->setDelivered(false); $delivery->setDeliverTries($delivery->getDeliveryTries() + 1); $this->update($delivery); } public function isWebhookDeactivate(ApiApplication $apiApplication) { $r = $this->repository->findUndeliveredEventsFromLastAppUpdate($apiApplication); // if failed to deliver webhook to the url in 5 different events // calculation based after app update ( any change on api application ) // so deactivate the webhook if (count($r) >= 5) { $apiApplication->setWebhookActive(false); $this->om->persist($apiApplication); $this->om->flush(); return true; } return false; } }