Extract a helper method to group checks [ci skip]
This commit is contained in:
parent
e2d7f08893
commit
a6f378294c
|
@ -49,27 +49,14 @@ final class PushBlogPostToSocialMedia implements EventSubscriberInterface {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!$entity->isPublished()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$entity->shouldSendToSocialMedia()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If this post has already been sent to social media, do not send it again.
|
||||
if ($entity->hasBeenSentToSocialMedia()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($entity->isExternalPost()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$url = $this->config->get('post_tweet_webhook_url')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->shouldBePushed($entity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->client->post($url, [
|
||||
'form_params' => [
|
||||
'message' => $entity->toTweet(),
|
||||
|
@ -80,4 +67,25 @@ final class PushBlogPostToSocialMedia implements EventSubscriberInterface {
|
|||
$entity->save();
|
||||
}
|
||||
|
||||
private function shouldBePushed(Post $post): bool {
|
||||
if ($post->isExternalPost()) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!$post->isPublished()) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!$post->shouldSendToSocialMedia()) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ($post->hasBeenSentToSocialMedia()) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue