Skip to content

Commit 4efa937

Browse files
committed
Email: queued_at field (populated if email is queued by email composer)
1 parent 429975f commit 4efa937

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class AddQueuedAtToEmailsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
if (Schema::hasColumn('emails', 'queued_at')) {
17+
return;
18+
}
19+
20+
Schema::table('emails', function (Blueprint $table) {
21+
$table->timestamp('queued_at')->after('encrypted')->nullable();
22+
});
23+
}
24+
25+
/**
26+
* Reverse the migrations.
27+
*
28+
* @return void
29+
*/
30+
public function down()
31+
{
32+
//
33+
}
34+
}

src/Email.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* @property $failed
2424
* @property $error
2525
* @property $encrypted
26+
* @property $queued_at
2627
* @property $scheduled_at
2728
* @property $sent_at
2829
* @property $delivered_at
@@ -277,6 +278,30 @@ public function getAttempts()
277278
return $this->attempts;
278279
}
279280

281+
/**
282+
* Get the queued date.
283+
*
284+
* @return mixed
285+
*/
286+
public function getQueuedDate()
287+
{
288+
return $this->queued_at;
289+
}
290+
291+
/**
292+
* Get the queued date as a Carbon instance.
293+
*
294+
* @return Carbon
295+
*/
296+
public function getQueuedDateAsCarbon()
297+
{
298+
if ($this->queued_at instanceof Carbon) {
299+
return $this->queued_at;
300+
}
301+
302+
return Carbon::parse($this->queued_at);
303+
}
304+
280305
/**
281306
* Get the scheduled date.
282307
*

src/Preparer.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public function prepare(EmailComposer $composer)
3636
$this->prepareScheduled($composer);
3737

3838
$this->prepareImmediately($composer);
39+
40+
$this->prepareQueued($composer);
3941
}
4042

4143
/**
@@ -235,4 +237,19 @@ private function prepareImmediately(EmailComposer $composer)
235237
$composer->getEmail()->fill(['sending' => 1]);
236238
}
237239
}
240+
241+
/**
242+
* Prepare the queued date.
243+
*
244+
* @param EmailComposer $composer
245+
*/
246+
private function prepareQueued(EmailComposer $composer)
247+
{
248+
if ($this->getData('queued', false) === true) {
249+
$composer->getEmail()->fill([
250+
'queued_at' => Carbon::now()->toDateTimeString(),
251+
]);
252+
}
253+
}
254+
238255
}

src/Store.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function getQueue()
1919
return $query
2020
->whereNull('deleted_at')
2121
->whereNull('sent_at')
22+
->whereNull('queued_at')
2223
->where(function ($query) {
2324
$query->whereNull('scheduled_at')
2425
->orWhere('scheduled_at', '<=', Carbon::now()->toDateTimeString());

0 commit comments

Comments
 (0)