Skip to content

Commit

Permalink
Merge pull request #4 from TheDoctor0/feature-track-email-subjects
Browse files Browse the repository at this point in the history
Add feature subject.
  • Loading branch information
akhan619 authored Apr 5, 2023
2 parents a5ce237 + 1c3bccd commit 39f0e03
Show file tree
Hide file tree
Showing 26 changed files with 80 additions and 22 deletions.
1 change: 1 addition & 0 deletions database/factories/EmailFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function definition()
'message_id' => $this->faker->uuid(),
'email' => $this->faker->unique()->safeEmail(),
'name' => $this->faker->name(),
'subject' => $this->faker->sentence(),
];
}

Expand Down
32 changes: 32 additions & 0 deletions database/migrations/add_subject_to_emails_table.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table(config('laravel-ses-event-manager.database_name_prefix') . '_emails', function (Blueprint $table) {
$table->string('subject')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table(config('laravel-ses-event-manager.database_name_prefix') . '_emails', function (Blueprint $table) {
$table->dropColumn('subject');
});
}
};
2 changes: 2 additions & 0 deletions src/App/Models/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected static function newFactory()
'message_id',
'email',
'name',
'subject',
'has_send',
'has_rendering_failure',
'has_reject',
Expand All @@ -64,6 +65,7 @@ protected static function newFactory()
'message_id' => 'string',
'email' => 'string',
'name' => 'string',
'subject' => 'string',
'has_send' => 'boolean',
'has_rendering_failure' => 'boolean',
'has_reject' => 'boolean',
Expand Down
3 changes: 2 additions & 1 deletion src/Implementations/SesMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function isMessageSent($result): bool
}

/**
* Save the email in the databse.
* Save the email in the database.
*
* @return void
*/
Expand All @@ -149,6 +149,7 @@ public function createEmailRecord($result): void
'message_id' => $result->getOriginalMessage()->getHeaders()->get('X-SES-Message-ID')->getValue(),
'email' => current($result->getOriginalMessage()->getTo())->getAddress(),
'name' => current($result->getOriginalMessage()->getTo())->getName(),
'subject' => $result->getOriginalMessage()->getSubject(),
]);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/LaravelSesEventManagerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ protected function bootForConsole(): void
__DIR__.'/../database/migrations/create_email_rendering_failures_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', now()->addSeconds(8)->timestamp).'_create_'.config('laravel-ses-event-manager.database_name_prefix').'_email_rendering_failures_table.php'),
__DIR__.'/../database/migrations/create_email_delivery_delays_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', now()->addSeconds(9)->timestamp).'_create_'.config('laravel-ses-event-manager.database_name_prefix').'_email_delivery_delays_table.php'),
__DIR__.'/../database/migrations/create_email_subscriptions_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', now()->addSeconds(10)->timestamp).'_create_'.config('laravel-ses-event-manager.database_name_prefix').'_email_subscriptions_table.php'),
__DIR__.'/../database/migrations/add_subject_to_emails_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', now()->addSeconds(11)->timestamp).'_create_'.config('laravel-ses-event-manager.database_name_prefix').'_add_subject_to_emails_table.php'),
], self::PREFIX.'-migrations');
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/Implementations/EventManagerBounceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_bounces_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';
$this->emailTable = config('laravel-ses-event-manager.database_name_prefix').'_emails';
$this->bounceTable = config('laravel-ses-event-manager.database_name_prefix').'_email_bounces';

Expand All @@ -35,7 +36,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/Implementations/EventManagerClickTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_clicks_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';
$this->emailTable = config('laravel-ses-event-manager.database_name_prefix').'_emails';
$this->clickTable = config('laravel-ses-event-manager.database_name_prefix').'_email_clicks';

Expand All @@ -35,7 +36,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/Implementations/EventManagerComplaintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_complaints_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';
$this->emailTable = config('laravel-ses-event-manager.database_name_prefix').'_emails';
$this->complaintTable = config('laravel-ses-event-manager.database_name_prefix').'_email_complaints';

Expand All @@ -35,7 +36,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_delivery_delays_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';
$this->emailTable = config('laravel-ses-event-manager.database_name_prefix').'_emails';
$this->delayTable = config('laravel-ses-event-manager.database_name_prefix').'_email_delivery_delays';

Expand All @@ -35,7 +36,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/Implementations/EventManagerDeliveryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_deliveries_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';
$this->emailTable = config('laravel-ses-event-manager.database_name_prefix').'_emails';
$this->deliveryTable = config('laravel-ses-event-manager.database_name_prefix').'_email_deliveries';

Expand All @@ -35,7 +36,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/Implementations/EventManagerOpenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_opens_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';
$this->emailTable = config('laravel-ses-event-manager.database_name_prefix').'_emails';
$this->openTable = config('laravel-ses-event-manager.database_name_prefix').'_email_opens';

Expand All @@ -35,7 +36,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/Implementations/EventManagerRejectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_rejects_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';
$this->emailTable = config('laravel-ses-event-manager.database_name_prefix').'_emails';
$this->rejectTable = config('laravel-ses-event-manager.database_name_prefix').'_email_rejects';

Expand All @@ -35,7 +36,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_rendering_failures_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';
$this->emailTable = config('laravel-ses-event-manager.database_name_prefix').'_emails';
$this->renderingTable = config('laravel-ses-event-manager.database_name_prefix').'_email_rendering_failures';

Expand All @@ -35,7 +36,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/Implementations/EventManagerSendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_sends_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';
$this->emailTable = config('laravel-ses-event-manager.database_name_prefix').'_emails';
$this->sendTable = config('laravel-ses-event-manager.database_name_prefix').'_email_sends';

Expand All @@ -35,7 +36,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_subscriptions_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';
$this->emailTable = config('laravel-ses-event-manager.database_name_prefix').'_emails';
$this->subscriptionTable = config('laravel-ses-event-manager.database_name_prefix').'_email_subscriptions';

Expand All @@ -35,7 +36,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Models/EmailBounceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_bounces_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';

foreach ($this->tables as $table) {
$table->up();
Expand All @@ -27,7 +28,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Models/EmailClickTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_clicks_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';

foreach ($this->tables as $table) {
$table->up();
Expand All @@ -27,7 +28,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Models/EmailComplaintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_complaints_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';

foreach ($this->tables as $table) {
$table->up();
Expand All @@ -27,7 +28,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Models/EmailDeliveryDelayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_delivery_delays_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';

foreach ($this->tables as $table) {
$table->up();
Expand All @@ -27,7 +28,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Models/EmailDeliveryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_deliveries_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';

foreach ($this->tables as $table) {
$table->up();
Expand All @@ -27,7 +28,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Models/EmailOpenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_opens_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';

foreach ($this->tables as $table) {
$table->up();
Expand All @@ -27,7 +28,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Models/EmailRejectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_rejects_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';

foreach ($this->tables as $table) {
$table->up();
Expand All @@ -27,7 +28,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Models/EmailRenderingFailureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protected function setUp(): void
$this->tables = [];
$this->tables[] = include __DIR__.'/../../../database/migrations/create_emails_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/create_email_rendering_failures_table.php.stub';
$this->tables[] = include __DIR__.'/../../../database/migrations/add_subject_to_emails_table.php.stub';

foreach ($this->tables as $table) {
$table->up();
Expand All @@ -27,7 +28,7 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->tables as $table) {
foreach (array_reverse($this->tables) as $table) {
$table->down();
}

Expand Down
Loading

0 comments on commit 39f0e03

Please sign in to comment.