Нет описания

MailerError.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace MailPoet\Mailer;
  3. if (!defined('ABSPATH')) exit;
  4. use MailPoet\WP\Functions as WPFunctions;
  5. class MailerError {
  6. const OPERATION_CONNECT = 'connect';
  7. const OPERATION_SEND = 'send';
  8. const OPERATION_AUTHORIZATION = 'authorization';
  9. const OPERATION_INSUFFICIENT_PRIVILEGES = 'insufficient_privileges';
  10. const LEVEL_HARD = 'hard';
  11. const LEVEL_SOFT = 'soft';
  12. const MESSAGE_EMAIL_FORBIDDEN_ACTION = 'Key is valid, but the action is forbidden';
  13. const MESSAGE_EMAIL_INSUFFICIENT_PRIVILEGES = 'Insufficient privileges';
  14. const MESSAGE_EMAIL_NOT_AUTHORIZED = 'The email address is not authorized';
  15. /** @var string */
  16. private $operation;
  17. /** @var string */
  18. private $level;
  19. /** @var string|null */
  20. private $message;
  21. /** @var int|null */
  22. private $retryInterval;
  23. /** @var array */
  24. private $subscribersErrors = [];
  25. /**
  26. * @param string $operation
  27. * @param string $level
  28. * @param null|string $message
  29. * @param int|null $retryInterval
  30. * @param array $subscribersErrors
  31. */
  32. public function __construct(
  33. $operation,
  34. $level,
  35. $message = null,
  36. $retryInterval = null,
  37. array $subscribersErrors = []
  38. ) {
  39. $this->operation = $operation;
  40. $this->level = $level;
  41. $this->message = $message;
  42. $this->retryInterval = $retryInterval;
  43. $this->subscribersErrors = $subscribersErrors;
  44. }
  45. /**
  46. * @return string
  47. */
  48. public function getOperation() {
  49. return $this->operation;
  50. }
  51. /**
  52. * @return string
  53. */
  54. public function getLevel() {
  55. return $this->level;
  56. }
  57. /**
  58. * @return null|string
  59. */
  60. public function getMessage() {
  61. return $this->message;
  62. }
  63. /**
  64. * @return int|null
  65. */
  66. public function getRetryInterval() {
  67. return $this->retryInterval;
  68. }
  69. /**
  70. * @return SubscriberError[]
  71. */
  72. public function getSubscriberErrors() {
  73. return $this->subscribersErrors;
  74. }
  75. public function getMessageWithFailedSubscribers() {
  76. $message = $this->message ?: '';
  77. if (!$this->subscribersErrors) {
  78. return $message;
  79. }
  80. $message .= $this->message ? ' ' : '';
  81. if (count($this->subscribersErrors) === 1) {
  82. $message .= WPFunctions::get()->__('Unprocessed subscriber:', 'mailpoet') . ' ';
  83. } else {
  84. $message .= WPFunctions::get()->__('Unprocessed subscribers:', 'mailpoet') . ' ';
  85. }
  86. $message .= implode(
  87. ', ',
  88. array_map(function (SubscriberError $subscriberError) {
  89. return "($subscriberError)";
  90. }, $this->subscribersErrors)
  91. );
  92. return $message;
  93. }
  94. }