Skip to content

Commit

Permalink
fixed logs, javascript, recipients format
Browse files Browse the repository at this point in the history
  • Loading branch information
ryssbowh committed Jan 8, 2022
1 parent a947b07 commit 3b5e2b8
Show file tree
Hide file tree
Showing 35 changed files with 1,219 additions and 263 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Once this plugin is installed, you'll be able to change, for each email :

### Logging

You can choose to save a log of each email sent in database for future reference. The logs are compressed in database so not to take too much space.
You can choose to save a log of each email sent in database for future reference. The logs are compressed in database so not to take too much space.
Enabling the logs will allow you to resend previously sent emails.

![Logs](/images/logs.png)

Expand Down Expand Up @@ -132,6 +133,7 @@ Send an email shot :
- See emails logs (applies to shot logs as well)
- Delete emails logs (applies to shot logs as well)
- Manage email shots
- Send emails

To add attachements users will need "View volume" and potentially "View files uploaded by other users" for one or several volumes.

Expand All @@ -147,4 +149,5 @@ Craft >= 3.5

## Roadmap

- Add a trigger system to send emails automatically when something happens on the system
- Add a trigger system to send emails automatically when something happens on the system
- mailchimp lists integration, as sources
Binary file modified images/list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/logs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/shot-logs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/shots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 8 additions & 5 deletions src/Emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ public function getCpNavItem ()
$item['subnav'] = [
'emails' => [
'url' => 'emails/list',
'label' => \Craft::t('themes', 'Emails'),
'label' => \Craft::t('emails', 'Emails'),
],
'shots' => [
'url' => 'emails/shots',
'label' => \Craft::t('themes', 'Email shots'),
'label' => \Craft::t('emails', 'Email shots'),
]
];
}
Expand Down Expand Up @@ -164,7 +164,7 @@ protected function registerEmailEvents()
Emails::$plugin->emails->modifyMessage($event->message);
});
Event::on(BaseMailer::class, BaseMailer::EVENT_AFTER_SEND, function ($event) {
Emails::$plugin->emails->afterSent($event->message, $event->isSuccessful);
Emails::$plugin->emails->afterSent($event->message);
});
}

Expand Down Expand Up @@ -197,7 +197,7 @@ protected function registerPermissions()
function (RegisterUserPermissionsEvent $event) {
$event->permissions[\Craft::t('emails', 'Emails')] = [
'addDeleteEmailTemplates' => [
'label' => \Craft::t('emails', 'Add and delete email templates')
'label' => \Craft::t('emails', 'Add and delete emails')
],
'modifyEmailContent' => [
'label' => \Craft::t('emails', 'Modify emails content')
Expand All @@ -211,8 +211,11 @@ function (RegisterUserPermissionsEvent $event) {
'deleteEmailLogs' => [
'label' => \Craft::t('emails', 'Delete emails logs')
],
'sendEmails' => [
'label' => \Craft::t('emails', 'Send emails')
],
'manageEmailShots' => [
'label' => \Craft::t('emails', 'Manage and send email shots')
'label' => \Craft::t('emails', 'Manage email shots')
]
];
}
Expand Down
303 changes: 294 additions & 9 deletions src/Models/EmailLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,317 @@

namespace Ryssbowh\CraftEmails\Models;

use Ryssbowh\CraftEmails\Emails;
use Ryssbowh\CraftEmails\Records\Email as EmailRecord;
use craft\base\Model;
use craft\elements\Asset;
use craft\elements\User;

class EmailLog extends Model
{
public $id;
public $uid;
/**
* @var int
*/
public $id;

/**
* @var string
*/
public $uid;

/**
* @var \DateTime
*/
public $dateCreated;

/**
* @var \DateTime
*/
public $dateUpdated;

/**
* @var int
*/
public $email_id;
public $email;

/**
* @var int
*/
public $user_id;

/**
* @var string
*/
public $subject;
public $bcc;
public $cc;

/**
* @var string
*/
public $content;

/**
* @var boolean
*/
public $is_console;

/**
* @var array
*/
protected $_attachements;

/**
* @var array
*/
protected $_from;

/**
* @var array
*/
protected $_replyTo;

/**
* @var array
*/
protected $_bcc;

/**
* @var array
*/
protected $_cc;

/**
* @var array
*/
protected $_to;

public function defineRules(): array
{
return [
[['id', 'email_id', 'uid', 'dateCreated', 'dateUpdated'], 'safe'],
[['email', 'bcc', 'content', 'subject', 'cc'], 'string']
[['id', 'email_id', 'uid', 'dateCreated', 'dateUpdated', 'attachements', 'from'], 'safe'],
[['email', 'bcc', 'content', 'subject', 'cc', 'replyTo'], 'string']
];
}

public function getUncompressedContent()
/**
* User getter
*
* @return ?User
*/
public function getUser(): ?User
{
if (!$this->user_id) {
return null;
}
return User::find()->id($this->user_id)->one();
}

/**
* Get attachements as elements (assets)
*
* @return array
*/
public function getAttachementsElements(): array
{
if (!$this->attachements) {
return [];
}
return Asset::find()->id($this->attachements)->all();
}

/**
* Attachements setter
*
* @param array|string $attachements
*/
public function setAttachements($attachements)
{
if (is_string($attachements)) {
$attachements = json_decode($attachements, true);
}
if (is_null($attachements)) {
$attachements = [];
}
$this->_attachements = $attachements;
}

/**
* From setter
*
* @param array|string $from
*/
public function setFrom($from)
{
if (is_string($from)) {
$from = json_decode($from, true);
}
$this->_from = $from;
}

/**
* To setter
*
* @param array|string $to
*/
public function setTo($to)
{
if (is_string($to)) {
$to = json_decode($to, true);
}
$this->_to = $to;
}

/**
* Bcc setter
*
* @param array|string $bcc
*/
public function setBcc($bcc)
{
if (is_string($bcc)) {
$bcc = json_decode($bcc, true);
}
if (is_null($bcc)) {
$bcc = [];
}
$this->_bcc = $bcc;
}

/**
* Cc setter
*
* @param array|string $cc
*/
public function setCc($cc)
{
if (is_string($cc)) {
$cc = json_decode($cc, true);
}
if (is_null($cc)) {
$cc = [];
}
$this->_cc = $cc;
}

/**
* Reply to setter
*
* @param array|string $to
*/
public function setReplyTo($to)
{
if (is_string($to)) {
$to = json_decode($to, true);
}
$this->_replyTo = $to;
}

/**
* From getter
*
* @return array
*/
public function getFrom(): array
{
return $this->_from;
}

/**
* To getter
*
* @return array
*/
public function getTo(): array
{
return $this->_to;
}

/**
* Attachements getter
*
* @return array
*/
public function getAttachements(): array
{
return $this->_attachements;
}

/**
* Reply to getter
*
* @return array
*/
public function getReplyTo(): array
{
return $this->_replyTo;
}

/**
* Bcc getter
*
* @return array
*/
public function getBcc(): array
{
return $this->_bcc;
}

/**
* Cc getter
*
* @return array
*/
public function getCc(): array
{
return $this->_cc;
}

/**
* Get content uncompressed
*
* @return string
*/
public function getUncompressedContent(): string
{
if (Emails::$plugin->settings->compressLogs) {
return gzinflate($this->content);
}
return $this->content;
}

/**
* Email getter
*
* @return ?Email
*/
public function getEmail(): ?Email
{
if ($this->email_id) {
return Emails::$plugin->emails->getById($this->email_id);
}
return null;
}

/**
* @inheritDoc
*/
public function fields()
{
return ['subject', 'to', 'from', 'replyTo', 'bcc', 'cc', 'from', 'uncompressedContent'];
}

/**
* @inheritDoc
*/
public function toArray(array $fields = [], array $expand = [], $recursive = true)
{
return gzinflate($this->content);
$array = parent::toArray($fields, $expand, $recursive);
$array['attachements'] = [];
foreach ($this->attachementsElements as $asset) {
$array['attachements'][] = [
'url' => $asset->url,
'title' => $asset->title
];
}
return $array;
}
}
Loading

0 comments on commit 3b5e2b8

Please sign in to comment.