Skip to content

Commit 57d391f

Browse files
committed
Add ExportStartedEvent and ExportCompletedEvent, add ability to set filename of export
1 parent 973e91d commit 57d391f

4 files changed

Lines changed: 53 additions & 2 deletions

File tree

src/Export/Jobs/CollateExportsAndUploadToDisk.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Coreproc\NovaDataSync\Enum\Status;
66
use Coreproc\NovaDataSync\Export\Models\Export;
7+
use Coreproc\NovaDataSync\Import\Events\ExportCompletedEvent;
78
use Illuminate\Bus\Queueable;
89
use Illuminate\Contracts\Queue\ShouldQueue;
910
use Illuminate\Foundation\Bus\Dispatchable;
@@ -46,7 +47,7 @@ public function handle(): void
4647
'files' => $files,
4748
]);
4849

49-
$collatedFileName = $this->exportName . '-' . now()->format('YmdHis') . '.csv';
50+
$collatedFileName = $this->exportName . '.csv';
5051
$collatedFilePath = $this->storagePath($collatedFileName);
5152
$collatedFileWriter = SimpleExcelWriter::create($collatedFilePath);
5253

@@ -82,6 +83,8 @@ public function handle(): void
8283
'status' => Status::COMPLETED,
8384
'completed_at' => now(),
8485
]);
86+
87+
event(new ExportCompletedEvent($this->export));
8588
}
8689

8790
protected function storagePath($path = ''): string

src/Export/Jobs/ExportProcessor.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Coreproc\NovaDataSync\Enum\Status;
66
use Coreproc\NovaDataSync\Export\Models\Export;
7+
use Coreproc\NovaDataSync\Import\Events\ExportStartedEvent;
78
use Illuminate\Bus\Batch;
89
use Illuminate\Bus\Queueable;
910
use Illuminate\Contracts\Auth\Authenticatable;
@@ -87,6 +88,8 @@ public function handle(): void
8788
$export->update([
8889
'status' => Status::IN_PROGRESS->value,
8990
]);
91+
92+
event(new ExportStartedEvent($export));
9093
})
9194
->then(function (Batch $batch) use ($export, $batchUuid, $exportDisk, $exportName, $exportDirectory) {
9295
// Collate and upload to disk job
@@ -110,11 +113,14 @@ public static function chunkSize(): int
110113
return config('nova-data-sync.exports.chunk_size', 1000);
111114
}
112115

116+
/**
117+
* Override this method to set the name of the export. Make sure it is unique to avoid conflicts with other files
118+
*/
113119
protected function name(): string
114120
{
115121
if (empty($this->name)) {
116122
// return the base name of the class
117-
return class_basename($this);
123+
return class_basename($this) . '-' . now()->format('YmdHis');
118124
}
119125

120126
return $this->name;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Coreproc\NovaDataSync\Import\Events;
4+
5+
use Coreproc\NovaDataSync\Export\Models\Export;
6+
use Illuminate\Broadcasting\InteractsWithSockets;
7+
use Illuminate\Foundation\Events\Dispatchable;
8+
use Illuminate\Queue\SerializesModels;
9+
10+
class ExportCompletedEvent
11+
{
12+
use Dispatchable, InteractsWithSockets, SerializesModels;
13+
14+
/**
15+
* Create a new event instance.
16+
*/
17+
public function __construct(public Export $export)
18+
{
19+
//
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Coreproc\NovaDataSync\Import\Events;
4+
5+
use Coreproc\NovaDataSync\Export\Models\Export;
6+
use Illuminate\Broadcasting\InteractsWithSockets;
7+
use Illuminate\Foundation\Events\Dispatchable;
8+
use Illuminate\Queue\SerializesModels;
9+
10+
class ExportStartedEvent
11+
{
12+
use Dispatchable, InteractsWithSockets, SerializesModels;
13+
14+
/**
15+
* Create a new event instance.
16+
*/
17+
public function __construct(public Export $export)
18+
{
19+
//
20+
}
21+
}

0 commit comments

Comments
 (0)