Fix email message for new transactions

This commit is contained in:
James Cole
2019-08-18 11:16:33 +02:00
parent a7b2fbbf10
commit 98cff18efa
6 changed files with 114 additions and 58 deletions

View File

@@ -60,8 +60,8 @@ class RequestedReportOnJournals
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/** @var Collection The journals to report on. */
public $journals;
/** @var Collection The transaction groups to report on. */
public $groups;
/** @var int The ID of the user. */
public $userId;
@@ -69,13 +69,13 @@ class RequestedReportOnJournals
* Create a new event instance.
*
* @param int $userId
* @param Collection $journals
* @param Collection $groups
*/
public function __construct(int $userId, Collection $journals)
public function __construct(int $userId, Collection $groups)
{
Log::debug('In event RequestedReportOnJournals.');
$this->userId = $userId;
$this->journals = $journals;
$this->groups = $groups;
}
/**

View File

@@ -55,10 +55,10 @@ class AutomationHandler
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
$user = $repository->findNull($event->userId);
if (null !== $user && 0 !== $event->journals->count()) {
if (null !== $user && 0 !== $event->groups->count()) {
try {
Log::debug('Trying to mail...');
Mail::to($user->email)->send(new ReportNewJournalsMail($user->email, '127.0.0.1', $event->journals));
Mail::to($user->email)->send(new ReportNewJournalsMail($user->email, '127.0.0.1', $event->groups));
// @codeCoverageIgnoreStart
} catch (Exception $e) {
Log::debug('Send message failed! :(');

View File

@@ -105,7 +105,6 @@ class HomeController extends Controller
{
$types = config('firefly.accountTypesByIdentifier.asset');
$count = $repository->count($types);
Log::channel('audit')->info('User visits homepage.');
if (0 === $count) {
@@ -127,7 +126,6 @@ class HomeController extends Controller
/** @var BillRepositoryInterface $billRepository */
$billRepository = app(BillRepositoryInterface::class);
$billCount = $billRepository->getBills()->count();
foreach ($accounts as $account) {
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);

View File

@@ -22,6 +22,8 @@ declare(strict_types=1);
namespace FireflyIII\Mail;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Transformers\TransactionGroupTransformer;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
@@ -43,21 +45,24 @@ class ReportNewJournalsMail extends Mailable
/** @var string IP address of user (if known) */
public $ipAddress;
/** @var Collection A collection of journals */
public $journals;
/** @var Collection A collection of groups */
public $groups;
/** @var array All groups, transformed to array. */
public $transformed;
/**
* ConfirmEmailChangeMail constructor.
*
* @param string $email
* @param string $ipAddress
* @param Collection $journals
* @param Collection $groups
*/
public function __construct(string $email, string $ipAddress, Collection $journals)
public function __construct(string $email, string $ipAddress, Collection $groups)
{
$this->email = $email;
$this->ipAddress = $ipAddress;
$this->journals = $journals;
$this->groups = $groups;
}
/**
@@ -67,13 +72,25 @@ class ReportNewJournalsMail extends Mailable
*/
public function build(): self
{
$subject = 1 === $this->journals->count()
$subject = 1 === $this->groups->count()
? 'Firefly III has created a new transaction'
: sprintf(
'Firefly III has created new %d transactions', $this->journals->count()
'Firefly III has created new %d transactions', $this->groups->count()
);
$this->transform();
return $this->view('emails.report-new-journals-html')->text('emails.report-new-journals-text')
->subject($subject);
}
private function transform(): void
{
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
/** @var TransactionGroup $group */
foreach ($this->groups as $group) {
$this->transformed[] = $transformer->transformObject($group);
}
}
}