Methods
2 weeks ago
WordPress
8 months ago
Mailer.php
2 years ago
MailerError.php
2 years ago
MailerFactory.php
1 year ago
MailerLog.php
1 year ago
MetaInfo.php
2 months ago
SubscriberError.php
3 years ago
index.php
3 years ago
MailerError.php
115 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Mailer; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | class MailerError { |
| 9 | const OPERATION_CONNECT = 'connect'; |
| 10 | const OPERATION_SEND = 'send'; |
| 11 | const OPERATION_AUTHORIZATION = 'authorization'; |
| 12 | const OPERATION_DOMAIN_AUTHORIZATION = 'domain_authorization'; |
| 13 | const OPERATION_INSUFFICIENT_PRIVILEGES = 'insufficient_privileges'; |
| 14 | const OPERATION_SUBSCRIBER_LIMIT_REACHED = 'subscriber_limit_reached'; |
| 15 | const OPERATION_EMAIL_LIMIT_REACHED = 'email_limit_reached'; |
| 16 | const OPERATION_PENDING_APPROVAL = 'pending_approval'; |
| 17 | |
| 18 | const LEVEL_HARD = 'hard'; |
| 19 | const LEVEL_SOFT = 'soft'; |
| 20 | |
| 21 | /** @var string */ |
| 22 | private $operation; |
| 23 | |
| 24 | /** @var string */ |
| 25 | private $level; |
| 26 | |
| 27 | /** @var string|null */ |
| 28 | private $message; |
| 29 | |
| 30 | /** @var int|null */ |
| 31 | private $retryInterval; |
| 32 | |
| 33 | /** @var array */ |
| 34 | private $subscribersErrors = []; |
| 35 | |
| 36 | /** |
| 37 | * @param string $operation |
| 38 | * @param string $level |
| 39 | * @param null|string $message |
| 40 | * @param int|null $retryInterval |
| 41 | * @param array $subscribersErrors |
| 42 | */ |
| 43 | public function __construct( |
| 44 | $operation, |
| 45 | $level, |
| 46 | $message = null, |
| 47 | $retryInterval = null, |
| 48 | array $subscribersErrors = [] |
| 49 | ) { |
| 50 | $this->operation = $operation; |
| 51 | $this->level = $level; |
| 52 | $this->message = $message; |
| 53 | $this->retryInterval = $retryInterval; |
| 54 | $this->subscribersErrors = $subscribersErrors; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @return string |
| 59 | */ |
| 60 | public function getOperation() { |
| 61 | return $this->operation; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @return string |
| 66 | */ |
| 67 | public function getLevel() { |
| 68 | return $this->level; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @return null|string |
| 73 | */ |
| 74 | public function getMessage() { |
| 75 | return $this->message; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @return int|null |
| 80 | */ |
| 81 | public function getRetryInterval() { |
| 82 | return $this->retryInterval; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @return SubscriberError[] |
| 87 | */ |
| 88 | public function getSubscriberErrors() { |
| 89 | return $this->subscribersErrors; |
| 90 | } |
| 91 | |
| 92 | public function getMessageWithFailedSubscribers() { |
| 93 | $message = $this->message ?: ''; |
| 94 | if (!$this->subscribersErrors) { |
| 95 | return $message; |
| 96 | } |
| 97 | |
| 98 | $message .= $this->message ? ' ' : ''; |
| 99 | |
| 100 | if (count($this->subscribersErrors) === 1) { |
| 101 | $message .= __('Unprocessed subscriber:', 'mailpoet') . ' '; |
| 102 | } else { |
| 103 | $message .= __('Unprocessed subscribers:', 'mailpoet') . ' '; |
| 104 | } |
| 105 | |
| 106 | $message .= implode( |
| 107 | ', ', |
| 108 | array_map(function (SubscriberError $subscriberError) { |
| 109 | return "($subscriberError)"; |
| 110 | }, $this->subscribersErrors) |
| 111 | ); |
| 112 | return $message; |
| 113 | } |
| 114 | } |
| 115 |