Skip to content

Commit

Permalink
Take the send history into account in the transportState filter
Browse files Browse the repository at this point in the history
+ add/fix of router-link on createdAt column in frosh-mail-archive-index.twig
  • Loading branch information
flkasper committed Oct 1, 2024
1 parent b919c99 commit 6961ea8
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 76 deletions.
14 changes: 10 additions & 4 deletions src/Content/MailArchive/MailArchiveDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Shopware\Core\Checkout\Customer\CustomerDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Field\BoolField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ChildrenAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\AllowHtml;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\CascadeDelete;
Expand All @@ -15,6 +17,8 @@
use Shopware\Core\Framework\DataAbstractionLayer\Field\LongTextField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ParentAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ParentFkField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Shopware\Core\System\SalesChannel\SalesChannelDefinition;
Expand All @@ -39,6 +43,11 @@ protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new IdField('id', 'id'))->addFlags(new PrimaryKey(), new Required()),

new ParentFkField(self::class),
new ParentAssociationField(self::class, 'id'),
new ChildrenAssociationField(self::class),

(new JsonField('sender', 'sender'))->addFlags(new Required()),
(new JsonField('receiver', 'receiver'))->addFlags(new Required())->addFlags(new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)),
(new StringField('subject', 'subject', 998))->addFlags(new Required())->addFlags(new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)),
Expand All @@ -47,6 +56,7 @@ protected function defineFields(): FieldCollection
(new LongTextField('eml', 'eml'))->addFlags(new AllowHtml()),
(new StringField('eml_path', 'emlPath', 2048)),
(new StringField('transport_state', 'transportState'))->addFlags(new Required()),
new BoolField('history_last_mail', 'historyLastMail'),

(new OneToManyAssociationField('attachments', MailArchiveAttachmentDefinition::class, 'mail_archive_id', 'id'))->addFlags(new CascadeDelete()),

Expand All @@ -55,10 +65,6 @@ protected function defineFields(): FieldCollection

new FkField('customerId', 'customerId', CustomerDefinition::class),
new ManyToOneAssociationField('customer', 'customerId', CustomerDefinition::class, 'id', true),

new FkField('source_mail_id', 'sourceMailId', self::class),
new ManyToOneAssociationField('sourceMail', 'source_mail_id', self::class, 'id', false),
new OneToManyAssociationField('sourceMails', self::class, 'sourceMailId')
]);
}
}
55 changes: 35 additions & 20 deletions src/Content/MailArchive/MailArchiveEntity.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Frosh\MailArchive\Content\MailArchive;

Expand Down Expand Up @@ -26,6 +28,8 @@ class MailArchiveEntity extends Entity

protected ?string $transportState;

protected bool $historyLastMail;

/**
* @deprecated will not be filled anyone. Use emlPath instead
*/
Expand All @@ -44,11 +48,11 @@ class MailArchiveEntity extends Entity
/** @var EntityCollection<MailArchiveAttachmentEntity>|null $attachments */
protected ?EntityCollection $attachments = null;

protected ?string $sourceMailId;
protected ?string $parentId;

protected ?MailArchiveEntity $sourceMail;
protected ?self $parent = null;

protected ?MailArchiveCollection $sourceMails = null;
protected ?MailArchiveCollection $children = null;


/**
Expand Down Expand Up @@ -195,43 +199,54 @@ public function setAttachments(EntityCollection $attachments): void
$this->attachments = $attachments;
}

public function getSourceMailId(): ?string

public function getTransportState(): ?string
{
return $this->sourceMailId;
return $this->transportState;
}

public function setSourceMailId(string $sourceMailId): void
public function setTransportState(string $transportState): void
{
$this->sourceMailId = $sourceMailId;
$this->transportState = $transportState;
}

public function getSourceMail(): ?MailArchiveEntity
public function isHistoryLastMail(): bool
{
return $this->sourceMail;
return $this->historyLastMail;
}

public function setSourceMail(MailArchiveEntity $sourceMail): void
public function setHistoryLastMail(bool $historyLastMail): void
{
$this->sourceMail = $sourceMail;
$this->historyLastMail = $historyLastMail;
}

public function getTransportState(): ?string
public function getParentId(): ?string
{
return $this->transportState;
return $this->parentId;
}

public function setTransportState(string $transportState): void
public function setParentId(?string $parentId): void
{
$this->transportState = $transportState;
$this->parentId = $parentId;
}

public function getParent(): ?MailArchiveEntity
{
return $this->parent;
}

public function setParent(?MailArchiveEntity $parent): void
{
$this->parent = $parent;
}

public function getSourceMails(): ?MailArchiveCollection
public function getChildren(): ?MailArchiveCollection
{
return $this->sourceMails;
return $this->children;
}

public function setSourceMails(MailArchiveCollection $sourceMails): void
public function setChildren(MailArchiveCollection $children): void
{
$this->sourceMails = $sourceMails;
$this->children = $children;
}
}
54 changes: 54 additions & 0 deletions src/Migration/Migration1727448352AlterTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace Frosh\MailArchive\Migration;

use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Migration\MigrationStep;

class Migration1727448352AlterTable extends MigrationStep
{
public function getCreationTimestamp(): int
{
return 1727448352;
}

public function update(Connection $connection): void
{
$connection->executeStatement(
'ALTER TABLE `frosh_mail_archive` CHANGE `source_mail_id` `parent_id` binary(16) NULL AFTER `id`;'
);

$connection->executeStatement(
'ALTER TABLE `frosh_mail_archive` ADD `history_last_mail` TINYINT(1) NOT NULL DEFAULT 0 AFTER `transport_state`;'
);

// set history_last_mail column of last row of history
$result = $connection->executeQuery(
'SELECT `id` FROM `frosh_mail_archive` WHERE `parent_id` IS NULL'
);
foreach ($result->iterateColumn() as $id) {
$lastId = $connection->fetchOne(
'SELECT `id` FROM `frosh_mail_archive` WHERE `parent_id` = :parentId ORDER BY created_at DESC LIMIT 1',
['parentId' => $id]
);

if ($lastId === false) {
// mail was not resend
$criteria = ['id' => $id];
} else {
$criteria = ['id' => $lastId];
}
$connection->update(
'frosh_mail_archive',
['history_last_mail' => 1],
$criteria
);
}
}

public function updateDestructive(Connection $connection): void
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import template from './frosh-mail-resend-history.html.twig';

Shopware.Component.register('frosh-mail-resend-history', {
props: {
sourceMailId: {
parentMailId: {
required: true,
type: String
},
Expand Down Expand Up @@ -46,8 +46,8 @@ Shopware.Component.register('frosh-mail-resend-history', {
async loadMails() {
const criteria = new Criteria();
criteria.addFilter(Criteria.multi('OR', [
Criteria.equals('id', this.sourceMailId),
Criteria.equals('sourceMailId', this.sourceMailId)
Criteria.equals('id', this.parentMailId),
Criteria.equals('parentId', this.parentMailId)
]));
criteria.addSorting(Criteria.sort('createdAt', 'DESC'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@
v-if="archive.salesChannel" :disabled="true"
v-model="archive.salesChannel.name"></sw-text-field>
</sw-card>
<frosh-mail-resend-history :key="resendKey" :currentMailId="archive.id"
:sourceMailId="archive.sourceMailId ?? archive.id"/>

<frosh-mail-resend-history
:key="resendKey"
:currentMailId="archive.id"
:parentMailId="archive.parentId ?? archive.id"
/>

<sw-card
:title="$tc('frosh-mail-archive.detail.content.title')"
position-identifier="frosh-mail-archive-content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,25 @@
</template>

<template slot="column-createdAt" slot-scope="{ item }">
{{ item.createdAt | date({hour: '2-digit', minute: '2-digit', second: '2-digit'}) }}
<router-link :to="{ name: 'frosh.mail.archive.detail', params: { id: item.id } }">
{{ item.createdAt | date({hour: '2-digit', minute: '2-digit', second: '2-digit'}) }}
</router-link>
</template>

<template slot="column-transportState" slot-scope="{ item }">

{{ translateState(item.transportState) }}

<template v-if="item.transportState === 'failed'">
<sw-icon
name="regular-exclamation-triangle"
color="#f00"
class="frosh-mail-archive__data-grid-danger-icon"
v-tooltip="{
message: $tc('frosh-mail-archive.list.columns.transportFailed')
}"
small></sw-icon>
name="regular-exclamation-triangle"
color="#f00"
class="frosh-mail-archive__data-grid-danger-icon"
v-tooltip="{ message: $tc('frosh-mail-archive.list.columns.transportFailed') }"
small
></sw-icon>
</template>
{{ translateState(item.transportState) }}

</template>

<template slot="detail-action" slot-scope="{ item }">
Expand Down Expand Up @@ -73,6 +77,17 @@
:options="transportStateOptions"
></sw-single-select>

<sw-switch-field
{% if VUE3 %}
v-model:value="filter.onlyLastMailInHistory"
{% else %}
v-model="filter.onlyLastMailInHistory"
{% endif %}
:label="$tc('frosh-mail-archive.list.sidebar.filters.onlyLastMailInHistoryLabel')"
:helpText="$tc('frosh-mail-archive.list.sidebar.filters.onlyLastMailInHistoryHelpText')"
>
</sw-switch-field>

<sw-entity-single-select
v-model="filter.salesChannelId"
:label="$tc('frosh-mail-archive.list.sidebar.filters.salesChannel')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ Component.register('frosh-mail-archive-index', {
salesChannelId: null,
transportState: null,
customerId: null,
term: null
}
term: null,
onlyLastMailInHistory: false,
},
}
},

Expand Down Expand Up @@ -90,6 +91,7 @@ Component.register('frosh-mail-archive-index', {
translateState(state) {
return this.$tc(`frosh-mail-archive.state.${state}`);
},

getList() {
this.isLoading = true;

Expand All @@ -100,6 +102,10 @@ Component.register('frosh-mail-archive-index', {
criteria.addFilter(Criteria.equals('transportState', this.filter.transportState));
}

if (this.filter.onlyLastMailInHistory) {
criteria.addFilter(Criteria.equals('historyLastMail', true));
}

if (this.filter.salesChannelId) {
criteria.addFilter(Criteria.equals('salesChannelId', this.filter.salesChannelId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"salesChannel": "Verkaufskanal",
"transportStateLabel": "Status",
"transportStatePlaceholder": "Status auswählen",
"onlyLastMailInHistoryLabel": "Sendeverlauf berücksichtigen",
"onlyLastMailInHistoryHelpText": "Wenn aktiv, wird nur die letzte Mail des Sendungsverlaufs berücksichtigt",
"resetFilter": "Filter zurücksetzen"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"salesChannel": "Sales Channel",
"transportStateLabel": "State",
"transportStatePlaceholder": "Select state",
"onlyLastMailInHistoryLabel": "Consider (re)send history",
"onlyLastMailInHistoryHelpText": "If active, only the last email in the (re)send history is taken into consideration",
"resetFilter": "Reset filter"
}
}
Expand Down
Loading

0 comments on commit 6961ea8

Please sign in to comment.