Initial commit: CloudOps infrastructure platform

This commit is contained in:
root
2026-04-09 19:58:57 +02:00
commit 1166a52f26
7762 changed files with 839452 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
<?php
namespace Mautic\EmailBundle\Event;
use Mautic\CoreBundle\Event\BuilderEvent;
use Mautic\EmailBundle\Entity\Email;
class EmailBuilderEvent extends BuilderEvent
{
/**
* @return Email|null
*/
public function getEmail()
{
return $this->entity;
}
}

View File

@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
namespace Mautic\EmailBundle\Event;
use Mautic\CoreBundle\Event\CommonEvent;
use Mautic\EmailBundle\Entity\Email;
class EmailEditSubmitEvent extends CommonEvent
{
public function __construct(
private Email $previousEmail,
private Email $currentEmail,
private bool $saveAndClose,
private bool $apply,
private bool $saveAsDraft,
private bool $applyDraft,
private bool $discardDraft,
) {
}
public function getPreviousEmail(): Email
{
return $this->previousEmail;
}
public function getCurrentEmail(): Email
{
return $this->currentEmail;
}
public function isSaveAndClose(): bool
{
return $this->saveAndClose;
}
public function isApply(): bool
{
return $this->apply;
}
public function isSaveAsDraft(): bool
{
return $this->saveAsDraft;
}
public function isApplyDraft(): bool
{
return $this->applyDraft;
}
public function isDiscardDraft(): bool
{
return $this->discardDraft;
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Mautic\EmailBundle\Event;
use Mautic\CoreBundle\Event\CommonEvent;
use Mautic\EmailBundle\Entity\Email;
class EmailEvent extends CommonEvent
{
/**
* @param bool $isNew
*/
public function __construct(Email &$email, $isNew = false)
{
$this->entity = &$email;
$this->isNew = $isNew;
}
/**
* Returns the Email entity.
*
* @return Email
*/
public function getEmail()
{
return $this->entity;
}
/**
* Sets the Email entity.
*/
public function setEmail(Email $email): void
{
$this->entity = $email;
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace Mautic\EmailBundle\Event;
use Mautic\CoreBundle\Event\CommonEvent;
use Mautic\EmailBundle\Entity\Email;
use Mautic\EmailBundle\Entity\Stat;
use Symfony\Component\HttpFoundation\Request;
class EmailOpenEvent extends CommonEvent
{
private ?Email $email;
/**
* @param Request $request
* @param bool $firstTime
*/
public function __construct(
Stat $stat,
private $request,
private $firstTime = false,
) {
$this->entity = $stat;
$this->email = $stat->getEmail();
}
/**
* Returns the Email entity.
*
* @return Email
*/
public function getEmail()
{
return $this->email;
}
/**
* Get email request.
*
* @return string
*/
public function getRequest()
{
return $this->request;
}
/**
* @return Stat
*/
public function getStat()
{
return $this->entity;
}
/**
* Returns if this is first time the email is read.
*
* @return bool
*/
public function isFirstTime()
{
return $this->firstTime;
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Mautic\EmailBundle\Event;
use Mautic\EmailBundle\Entity\Email;
use Mautic\EmailBundle\Entity\Stat;
use Symfony\Contracts\EventDispatcher\Event;
class EmailReplyEvent extends Event
{
private ?Email $email;
public function __construct(
private Stat $stat,
) {
$this->email = $stat->getEmail();
}
/**
* Returns the Email entity.
*
* @return Email
*/
public function getEmail()
{
return $this->email;
}
/**
* @return Stat
*/
public function getStat()
{
return $this->stat;
}
}

View File

@@ -0,0 +1,387 @@
<?php
namespace Mautic\EmailBundle\Event;
use Mautic\CoreBundle\Event\CommonEvent;
use Mautic\EmailBundle\Entity\Email;
use Mautic\EmailBundle\Helper\MailHelper;
use Mautic\EmailBundle\Helper\PlainTextHelper;
use Mautic\LeadBundle\Entity\Lead;
class EmailSendEvent extends CommonEvent
{
/**
* @var Email|null
*/
private $email;
private string $content = '';
private string $plainText = '';
private string $subject = '';
/**
* @var string|null
*/
private $idHash;
/**
* @var Lead|mixed[]|null
*/
private $lead;
/**
* @var array
*/
private $source;
private array $tokens = [];
/**
* @var bool
*/
private $internalSend = false;
private array $textHeaders = [];
private bool $fatal = false;
private bool $skip = false;
/**
* @var array<string>
*/
private array $errors = [];
/**
* @param array $args
* @param bool $isDynamicContentParsing
*/
public function __construct(
private ?MailHelper $helper = null,
$args = [],
private $isDynamicContentParsing = false,
) {
$this->content = $args['content'] ?? '';
$this->plainText = $args['plainText'] ?? '';
$this->subject = $args['subject'] ?? '';
$this->email = $args['email'] ?? null;
$this->idHash = $args['idHash'] ?? null;
$this->lead = $args['lead'] ?? null;
$this->source = $args['source'] ?? [];
$this->tokens = $args['tokens'] ?? [];
$this->textHeaders = $args['textHeaders'] ?? [];
$this->errors = $args['errors'] ?? [];
$this->fatal = $args['fatal'] ?? false;
$this->skip = $args['skip'] ?? false;
if (!$this->subject && $this->email instanceof Email) {
$this->subject = (string) $args['email']->getSubject();
}
if (isset($args['internalSend'])) {
$this->internalSend = $args['internalSend'];
} elseif (null !== $helper) {
$this->internalSend = $helper->isInternalSend();
}
}
/**
* Check if this email is an internal send or to the lead; if an internal send, don't append lead tracking.
*
* @return bool
*/
public function isInternalSend()
{
return $this->internalSend;
}
/**
* Return if the transport and mailer is in batch mode (tokenized emails).
*/
public function inTokenizationMode(): bool
{
return null !== $this->helper && $this->helper->inTokenizationMode();
}
/**
* Returns the Email entity.
*
* @return ?Email
*/
public function getEmail()
{
return (null !== $this->helper) ? $this->helper->getEmail() : $this->email;
}
/**
* Get email content.
*
* @return string
*/
public function getContent($replaceTokens = false)
{
if (null !== $this->helper) {
$content = $this->helper->getBody();
} else {
$content = $this->content;
}
return ($replaceTokens) ? str_replace(array_keys($this->getTokens()), $this->getTokens(), $content) : $content;
}
/**
* Set email content.
*/
public function setContent($content): void
{
if (null !== $this->helper) {
$this->helper->setBody($content, 'text/html', null, true);
} else {
$this->content = $content;
}
$this->setGeneratedPlainText();
}
/**
* Get email content.
*
* @return string
*/
public function getPlainText()
{
if (null !== $this->helper) {
return $this->helper->getPlainText();
} else {
return $this->plainText;
}
}
public function setPlainText($content): void
{
if (null !== $this->helper) {
$this->helper->setPlainText($content);
} else {
$this->plainText = $content;
}
$this->setGeneratedPlainText();
}
/**
* Check if plain text is empty. If yes, generate it.
*/
private function setGeneratedPlainText(): void
{
$htmlContent = $this->getContent();
if ('' === $this->getPlainText() && '' !== $htmlContent) {
$parser = new PlainTextHelper();
$generatedPlainText = $parser->setHtml($htmlContent)->getText();
if ('' !== $generatedPlainText) {
$this->setPlainText($generatedPlainText);
}
}
}
/**
* @return string
*/
public function getSubject()
{
if (null !== $this->helper) {
return $this->helper->getSubject();
} else {
return $this->subject;
}
}
/**
* @param string $subject
*/
public function setSubject($subject): void
{
if (null !== $this->helper) {
$this->helper->setSubject($subject);
} else {
$this->subject = $subject;
}
}
/**
* Get the MailHelper object.
*
* @return MailHelper
*/
public function getHelper()
{
return $this->helper;
}
/**
* @return array|Lead|null
*/
public function getLead()
{
return (null !== $this->helper) ? $this->helper->getLead() : $this->lead;
}
/**
* @return string
*/
public function getIdHash()
{
return (null !== $this->helper) ? $this->helper->getIdHash() : $this->idHash;
}
/**
* @return array
*/
public function getSource()
{
return (null !== $this->helper) ? $this->helper->getSource() : $this->source;
}
public function addTokens(array $tokens): void
{
$this->tokens = array_merge($this->tokens, $tokens);
}
public function addToken($key, $value): void
{
$this->tokens[$key] = $value;
}
/**
* Get token array.
*/
public function getTokens($includeGlobal = true): array
{
$tokens = $this->tokens;
if ($includeGlobal && null !== $this->helper) {
$tokens = array_merge($this->helper->getGlobalTokens(), $tokens);
}
return $tokens;
}
public function addTextHeader($name, $value): void
{
if (null !== $this->helper) {
$this->helper->addCustomHeader($name, $value);
} else {
$this->textHeaders[$name] = $value;
}
}
public function getTextHeaders(): array
{
return (null !== $this->helper) ? $this->helper->getCustomHeaders() : $this->textHeaders;
}
/**
* Check if the listener should append it's own clickthrough in URLs or if the email tracking URL conversion process should take care of it.
*/
public function shouldAppendClickthrough(): bool
{
return !$this->isInternalSend() && null === $this->getEmail();
}
/**
* Generate a clickthrough array for URLs.
*/
public function generateClickthrough(): array
{
$source = $this->getSource();
$email = $this->getEmail();
$clickthrough = [
// what entity is sending the email?
'source' => $source,
// the email being sent to be logged in page hit if applicable
'email' => (null != $email) ? $email->getId() : null,
'stat' => $this->getIdHash(),
'sent_time' => time(),
];
$lead = $this->getLead();
if (null !== $lead) {
$clickthrough['lead'] = $lead['id'];
}
return $clickthrough;
}
/**
* Get the content hash to note if the content has been changed.
*
* @return string
*/
public function getContentHash()
{
if (null !== $this->helper) {
return $this->helper->getContentHash();
} else {
return md5($this->getContent().$this->getPlainText());
}
}
/**
* @return bool
*/
public function isDynamicContentParsing()
{
return $this->isDynamicContentParsing;
}
public function getCombinedContent(): string
{
$content = $this->getSubject();
$content .= $this->getContent();
$content .= $this->getPlainText();
$content .= $this->getEmail() ? $this->getEmail()->getCustomHtml() : '';
return $content.implode(' ', $this->getTextHeaders());
}
public function disableSkip(): void
{
$this->skip = false;
}
public function enableSkip(): void
{
$this->skip = true;
}
public function isSkip(): bool
{
return $this->skip;
}
public function enableFatal(): void
{
$this->fatal = true;
}
public function disableFatal(): void
{
$this->fatal = false;
}
public function isFatal(): bool
{
return $this->fatal;
}
public function addError(string $error): void
{
$this->errors[] = $error;
}
/**
* @return array<string>
*/
public function getErrors(): array
{
return $this->errors;
}
}

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Mautic\EmailBundle\Event;
use Mautic\EmailBundle\Entity\Stat;
use Symfony\Contracts\EventDispatcher\Event;
final class EmailStatEvent extends Event
{
/**
* @param Stat[] $stats
*/
public function __construct(
private array $stats,
) {
}
/**
* @return Stat[]
*/
public function getStats(): array
{
return $this->stats;
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace Mautic\EmailBundle\Event;
use Symfony\Contracts\EventDispatcher\Event;
class EmailValidationEvent extends Event
{
/**
* @var bool
*/
protected $isValid = true;
/**
* @var string|null
*/
protected $invalidReason;
/**
* @param string $address
*/
public function __construct(
protected $address,
) {
}
/**
* @return string
*/
public function getAddress()
{
return $this->address;
}
public function setInvalid($reason): void
{
$this->isValid = false;
$this->invalidReason = $reason;
$this->stopPropagation();
}
/**
* @return bool
*/
public function isValid()
{
return $this->isValid;
}
/**
* @return string|null
*/
public function getInvalidReason()
{
return $this->invalidReason;
}
}

View File

@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Mautic\EmailBundle\Event;
use Mautic\EmailBundle\Entity\Email;
use Symfony\Contracts\EventDispatcher\Event;
final class ManualWinnerEvent extends Event
{
public function __construct(private Email $email)
{
}
public function getEmail(): Email
{
return $this->email;
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace Mautic\EmailBundle\Event;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\EventDispatcher\Event;
class MonitoredEmailEvent extends Event
{
private array $folders = [];
public function __construct(
private FormBuilderInterface $formBuilder,
private array $data,
) {
}
/**
* Get the FormBuilder for monitored_mailboxes FormType.
*
* @return FormBuilderInterface
*/
public function getFormBuilder()
{
return $this->formBuilder;
}
/**
* Insert a folder to configure.
*
* @param string $default
*/
public function addFolder($bundleKey, $folderKey, $label, $default = ''): void
{
$keyName = ($folderKey) ? $bundleKey.'_'.$folderKey : $bundleKey;
$this->folders[$keyName] = [
'label' => $label,
'default' => $default,
];
}
/**
* Get the value set for a specific bundle/folder.
*
* @return string
*/
public function getData($bundleKey, $folderKey, $default = '')
{
$keyName = $bundleKey.'_'.$folderKey;
return $this->data[$keyName] ?? $default;
}
/**
* Get array of folders.
*
* @return array
*/
public function getFolders()
{
return $this->folders;
}
}

View File

@@ -0,0 +1,125 @@
<?php
namespace Mautic\EmailBundle\Event;
use Symfony\Contracts\EventDispatcher\Event;
class ParseEmailEvent extends Event
{
/**
* @var mixed[]
*/
private array $criteriaRequests = [];
/**
* @var mixed[]
*/
private array $markAsSeen = [];
/**
* @param mixed[] $keys
*/
public function __construct(
private array $messages = [],
private array $keys = [],
) {
}
/**
* Get the array of messages.
*
* @return \Mautic\EmailBundle\MonitoredEmail\Message[]
*/
public function getMessages()
{
return $this->messages;
}
/**
* @return $this
*/
public function setMessages($messages)
{
$this->messages = $messages;
return $this;
}
/**
* @return array
*/
public function getKeys()
{
return $this->keys;
}
/**
* @param array $keys
*
* @return $this
*/
public function setKeys($keys)
{
$this->keys = $keys;
return $this;
}
/**
* Check if the set of messages is applicable and should be processed by the listener.
*/
public function isApplicable($bundleKey, $folderKeys): bool
{
if (!is_array($folderKeys)) {
$folderKeys = [$folderKeys];
}
foreach ($folderKeys as $folderKey) {
$key = $bundleKey.'_'.$folderKey;
if (in_array($key, $this->keys)) {
return true;
}
}
return false;
}
/**
* Set a criteria request for filtering fetched mail.
*
* @param string $bundleKey
* @param string $folderKeys
* @param string $criteria Should be a string using combinations of Mautic\EmailBundle\MonitoredEmail\Mailbox::CRITERIA_* constants
* @param bool $markAsSeen Mark the message as read after being processed
*/
public function setCriteriaRequest($bundleKey, $folderKeys, $criteria, $markAsSeen = true): void
{
if (!is_array($folderKeys)) {
$folderKeys = [$folderKeys];
}
foreach ($folderKeys as $folderKey) {
$key = $bundleKey.'_'.$folderKey;
$this->criteriaRequests[$key] = $criteria;
$this->markAsSeen[$key] = $markAsSeen;
}
}
/**
* @return array
*/
public function getCriteriaRequests()
{
return $this->criteriaRequests;
}
/**
* @return array
*/
public function getMarkAsSeenInstructions()
{
return $this->markAsSeen;
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Mautic\EmailBundle\Event;
use Mautic\EmailBundle\Mailer\Message\MauticMessage;
use Symfony\Contracts\EventDispatcher\Event;
class QueueEmailEvent extends Event
{
private bool $retry = false;
public function __construct(
private MauticMessage $message,
) {
}
/**
* @return MauticMessage
*/
public function getMessage()
{
return $this->message;
}
/**
* Sets whether the sending of the message should be tried again.
*/
public function tryAgain(): void
{
$this->retry = true;
}
public function shouldTryAgain(): bool
{
return $this->retry;
}
}

View File

@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace Mautic\EmailBundle\Event;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\EventDispatcher\Event;
/**
* Event triggered when a transport service send Mautic a webhook request.
*/
final class TransportWebhookEvent extends Event
{
private ?Response $response = null;
public function __construct(
private Request $request,
) {
}
public function getRequest(): Request
{
return $this->request;
}
public function getResponse(): ?Response
{
return $this->response;
}
public function setResponse(Response $response): void
{
$this->response = $response;
}
}