Skip to content

Commit

Permalink
New: Save multiple sent dates
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnitto committed Sep 26, 2022
1 parent 9d34002 commit 8e81e6b
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 38 deletions.
1 change: 1 addition & 0 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ public function createAction(
}

$properties = [
"sent" => [],
"subject" => $subject,
"previewText" => $this->mauticService->cleanPreviewText($previewText),
"segments" => $convertedSegments,
Expand Down
22 changes: 0 additions & 22 deletions Classes/Domain/Model/MauticEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@ class MauticEmail
protected $dateModified;


/**
* @var DateTime
* @ORM\Column(nullable=true)
*/
protected $dateSent;

/**
* @var string
*/
Expand Down Expand Up @@ -226,22 +220,6 @@ public function setDateCreated(DateTime $dateCreated): void
$this->dateCreated = $dateCreated;
}

/**
* @return DateTime|null
*/
public function getDateSent(): ?DateTime
{
return $this->dateSent ?? null;
}

/**
* @param DateTime $dateSent
*/
public function setDateSent(DateTime $dateSent): void
{
$this->dateSent = $dateSent;
}

/**
* @return string
*/
Expand Down
6 changes: 5 additions & 1 deletion Classes/Service/MauticService.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ public function sendEmail(MauticEmail $email, $mauticIdentifier): void
$sentCount = (int) $stats['sentCount'];
$failedRecipients = (int) $stats['failedRecipients'];

$email->setDateSent(new DateTime());
// Add sent date to email
$sent = $email->getProperty('sent') || [];
$sent[] = time();
$email->setProperty('sent', $sent);

$this->mauticEmailRepository->update($email);

$eventSuccess = new MauticEmailSent($emailIdentifier, $mauticIdentifier, $success, $sentCount, $failedRecipients);
Expand Down
37 changes: 37 additions & 0 deletions Migrations/Mysql/Version20220926153231.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Neos\Flow\Persistence\Doctrine\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;


final class Version20220926153231 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MariaDb1027Platform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MariaDb1027Platform'."
);

$this->addSql('ALTER TABLE garagist_mautic_domain_model_mauticemail DROP datesent');
}

public function down(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MariaDb1027Platform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MariaDb1027Platform'."
);

$this->addSql('ALTER TABLE garagist_mautic_domain_model_mauticemail ADD datesent DATETIME DEFAULT NULL');
}
}
23 changes: 12 additions & 11 deletions Resources/Private/Modules/Component/EmailData.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ prototype(Garagist.Mautic:Component.EmailData) < prototype(Neos.Fusion:Component
name = ${props.email.name}
dateCreated = ${Date.format(props.email.dateCreated, 'd.m.Y H:m:s')}
emailIdentifier = ${props.email.emailIdentifier}

properties = ${props.email.properties}
subject = ${this.properties ? this.properties.subject : null}
previewText = ${this.properties ? this.properties.previewText : null}
segments = ${this.properties ? this.properties.segments : null}
dateSent = ${props.email.dateSent ? Date.format(props.email.dateSent, 'd.m.Y H:m:s') : '–'}
subject = ${this.properties.subject}
previewText = ${this.properties.previewText}
segments = ${this.properties.segments}
sent = ${Array.sort(props.email.properties.sent)}
hrefArguments = Neos.Fusion:DataStructure {
node = ${props.node}
email = ${props.email}
Expand All @@ -22,17 +23,17 @@ prototype(Garagist.Mautic:Component.EmailData) < prototype(Neos.Fusion:Component
task = ${props.email.task}

isIdle = ${props.email.task == 'idle'}
isSended = ${props.email.dateSent}
canPublish = ${this.isIdle && (props.email.dateModified != null && props.email.dateSend == null && !props.email.published)}
canUnpublish = ${this.isIdle && (props.email.dateSent == null && props.email.published)}
isSended = ${Carbon.Array.check(props.email.properties.sent)}
canPublish = ${this.isIdle && (props.email.dateModified != null && !this.isSended && !props.email.published)}
canUnpublish = ${this.isIdle && (!this.isSended && props.email.published)}
canTest = ${this.canPublish || this.canUnpublish}
canEdit = ${this.canPublish}
canSend = ${this.isIdle && (props.email.dateSent == null && props.email.published)}
canUpdate = ${this.isIdle && this.properties && (props.email.dateSent == null && !props.email.published)}
canSend = ${this.isIdle && (!this.isSended && props.email.published)}
canUpdate = ${this.isIdle && this.properties && (!this.isSended && !props.email.published)}
canResend = ${this.isIdle && this.isSended}
canDelete= ${this.isIdle}
canPublishAndSend = ${this.isIdle && (props.email.dateModified != null && props.email.dateSend == null)}
canUnpublishAndUpdate = ${this.isIdle && (props.email.dateSent == null)}
canPublishAndSend = ${this.isIdle && (props.email.dateModified != null && !this.isSended)}
canUnpublishAndUpdate = ${this.isIdle && !this.isSended}

isRunning = ${props.email.task != 'idle' && props.email.task != 'failed'}
isFailed = ${props.email.task == 'failed'}
Expand Down
7 changes: 6 additions & 1 deletion Resources/Private/Modules/Views/Detail.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ Garagist.Mautic.BackendController.detail = Neos.Fusion:Component {
</tr>
<tr @if={props.emailData.isSended}>
<td>{props._i18n.id('sentOn').translate()}</td>
<td>{props.emailData.dateSent}</td>
<td>
<Neos.Fusion:Loop items={props.emailData.sent}>
{props._i18n.id('dateAndTime').arguments([Date.format(item, 'd.m.Y'), Date.format(item, 'H:m:s')]).translate()}
<br @if={!iterator.isLast} />
</Neos.Fusion:Loop>
</td>
</tr>
<tr>
<td>{props._i18n.id('subject').translate()}</td>
Expand Down
13 changes: 10 additions & 3 deletions Resources/Private/Modules/Views/Node.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,18 @@ Garagist.Mautic.BackendController.node = Neos.Fusion:Component {
{props.title}
</td>
<td>{item.dateCreated}</td>
<td>{item.dateSent}</td>
<td>{item.properties ? item.properties.recipients : ''}</td>
<td>
<Neos.Fusion:Loop items={item.sent}>
<span aria-label={props._i18n.id('dateAndTime').arguments([Date.format(item, 'd.m.Y'), Date.format(item, 'H:m:s')]).translate()}>
{Date.format(item, 'd.m.Y')}
</span>
{iterator.isLast ? '' : ', '}
</Neos.Fusion:Loop>
</td>
<td>{item.properties.recipients}</td>
<td class="neos-action">
<div
x-data={"actions(" + (item.properties ? "2" : "1") + ")"}
x-data="actions(2)"
class="neos-pull-right"
>
<Garagist.Mautic:Component.EmailActionButtons {...item} />
Expand Down
4 changes: 4 additions & 0 deletions Resources/Private/Translations/de/Module.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
<source>Show pages without emails</source>
<target>Zeige Seiten ohne E-Mails</target>
</trans-unit>
<trans-unit id="dateAndTime" xml:space="preserve">
<source>{0} at {1}</source>
<target>{0} um {1} Uhr</target>
</trans-unit>
<trans-unit id="email.publish" xml:space="preserve">
<source>Publish email</source>
<target>E-Mail veröffentlichen</target>
Expand Down
3 changes: 3 additions & 0 deletions Resources/Private/Translations/en/Module.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<trans-unit id="showPagesWithoutEmails" xml:space="preserve">
<source>Show pages without emails</source>
</trans-unit>
<trans-unit id="dateAndTime" xml:space="preserve">
<source>{0} at {1}</source>
</trans-unit>
<trans-unit id="email.publish" xml:space="preserve">
<source>Publish email</source>
</trans-unit>
Expand Down

0 comments on commit 8e81e6b

Please sign in to comment.