From 6a90ca9080d23e89983ba545d11a7f1c77003cf4 Mon Sep 17 00:00:00 2001 From: David Remer Date: Tue, 3 Oct 2023 09:28:52 +0300 Subject: [PATCH] Add CommentSubject and Payload [PREMIUM-248] --- .../WordPress/Payloads/CommentPayload.php | 31 ++++++++++++ .../WordPress/Subjects/CommentSubject.php | 50 +++++++++++++++++++ .../WordPress/WordPressIntegration.php | 9 +++- 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 mailpoet/lib/Automation/Integrations/WordPress/Payloads/CommentPayload.php create mode 100644 mailpoet/lib/Automation/Integrations/WordPress/Subjects/CommentSubject.php diff --git a/mailpoet/lib/Automation/Integrations/WordPress/Payloads/CommentPayload.php b/mailpoet/lib/Automation/Integrations/WordPress/Payloads/CommentPayload.php new file mode 100644 index 0000000000..55891ddbe0 --- /dev/null +++ b/mailpoet/lib/Automation/Integrations/WordPress/Payloads/CommentPayload.php @@ -0,0 +1,31 @@ +commentId = $commentId; + $this->wp = $wp; + } + + public function getCommentId(): int { + return $this->commentId; + } + + public function getComment(): ?\WP_Comment { + $comment = $this->wp->getComment($this->commentId); + return $comment instanceof \WP_Comment ? $comment : null; + } +} diff --git a/mailpoet/lib/Automation/Integrations/WordPress/Subjects/CommentSubject.php b/mailpoet/lib/Automation/Integrations/WordPress/Subjects/CommentSubject.php new file mode 100644 index 0000000000..11d17b1ce9 --- /dev/null +++ b/mailpoet/lib/Automation/Integrations/WordPress/Subjects/CommentSubject.php @@ -0,0 +1,50 @@ + + */ +class CommentSubject implements Subject { + const KEY = 'wordpress:comment'; + + /** @var WordPress */ + private $wp; + + public function __construct( + WordPress $wp + ) { + $this->wp = $wp; + } + + public function getKey(): string { + return self::KEY; + } + + public function getName(): string { + return __('Comment', 'mailpoet'); + } + + public function getArgsSchema(): ObjectSchema { + return Builder::object([ + 'comment_id' => Builder::integer()->required(), + ]); + } + + public function getFields(): array { + return []; + } + + public function getPayload(SubjectData $subjectData): Payload { + $commentId = (int)$subjectData->getArgs()['comment_id']; + return new CommentPayload($commentId, $this->wp); + } +} diff --git a/mailpoet/lib/Automation/Integrations/WordPress/WordPressIntegration.php b/mailpoet/lib/Automation/Integrations/WordPress/WordPressIntegration.php index b8ca03a832..9a24ac191c 100644 --- a/mailpoet/lib/Automation/Integrations/WordPress/WordPressIntegration.php +++ b/mailpoet/lib/Automation/Integrations/WordPress/WordPressIntegration.php @@ -3,19 +3,26 @@ namespace MailPoet\Automation\Integrations\WordPress; use MailPoet\Automation\Engine\Registry; +use MailPoet\Automation\Integrations\WordPress\Subjects\CommentSubject; use MailPoet\Automation\Integrations\WordPress\Subjects\UserSubject; class WordPressIntegration { /** @var UserSubject */ private $userSubject; + /** @var CommentSubject */ + private $commentSubject; + public function __construct( - UserSubject $userSubject + UserSubject $userSubject, + CommentSubject $commentSubject ) { $this->userSubject = $userSubject; + $this->commentSubject = $commentSubject; } public function register(Registry $registry): void { $registry->addSubject($this->userSubject); + $registry->addSubject($this->commentSubject); } }