Skip to content

Commit 12a1228

Browse files
committedApr 4, 2025
Import/Export to new bucket
1 parent 1cc16bb commit 12a1228

File tree

10 files changed

+41
-181
lines changed

10 files changed

+41
-181
lines changed
 

‎app/Http/Controllers/Campaign/ExportController.php

+1-21
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace App\Http\Controllers\Campaign;
44

5-
use App\Facades\Datagrid;
65
use App\Http\Controllers\Controller;
76
use App\Models\Campaign;
87
use App\Services\Campaign\ExportService;
@@ -21,26 +20,7 @@ public function __construct(ExportService $exportService)
2120
public function index(Campaign $campaign)
2221
{
2322
$this->authorize('setting', $campaign);
24-
25-
Datagrid::layout(\App\Renderers\Layouts\Campaign\CampaignExport::class);
26-
27-
$rows = $campaign->campaignExports()
28-
->sort(request()->only(['o', 'k']))
29-
->with(['user', 'campaign'])
30-
->orderBy('updated_at', 'DESC')
31-
->paginate();
32-
33-
// Ajax Datagrid
34-
if (request()->ajax()) {
35-
$html = view('layouts.datagrid._table')->with('rows', $rows)->render();
36-
37-
return response()->json([
38-
'success' => true,
39-
'html' => $html,
40-
]);
41-
}
42-
43-
return view('campaigns.export', compact('campaign', 'rows'));
23+
return view('campaigns.export', compact('campaign'));
4424
}
4525

4626
/**

‎app/Livewire/Campaigns/ExportsTable.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public function download(CampaignExport $model): string
101101
if (! $model->finished()) {
102102
return '';
103103
}
104-
if ($model->path && Storage::exists($model->path)) {
105-
$html = '<a class="block break-all truncate" href="' . Storage::url($model->path) . '" target="_blank">' . __('campaigns/export.actions.download') . '</a>';
104+
if ($model->path && Storage::disk('export')->exists($model->path)) {
105+
$html = '<a class="block break-all truncate" href="' . Storage::disk('export')->url($model->path) . '" target="_blank">' . __('campaigns/export.actions.download') . '</a>';
106106

107107
return $html;
108108
}

‎app/Renderers/Layouts/Campaign/CampaignExport.php

-132
This file was deleted.

‎app/Renderers/Layouts/Campaign/CampaignImport.php

+16-19
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,10 @@ class CampaignImport extends Layout
1515
public function columns(): array
1616
{
1717
$columns = [
18-
'status' => [
19-
'key' => 'status_id',
20-
'label' => 'campaigns/plugins.fields.status',
21-
'render' => function ($model) {
22-
$key = 'running';
23-
/** @var \App\Models\CampaignImport $model */
24-
if ($model->status_id === CampaignImportStatus::FAILED) {
25-
$key = 'failed';
26-
} elseif ($model->status_id == CampaignImportStatus::QUEUED) {
27-
$key = 'queued';
28-
} elseif ($model->status_id == CampaignImportStatus::FINISHED) {
29-
$key = 'finished';
30-
}
31-
32-
return __('campaigns/import.status.' . $key);
33-
},
34-
],
3518
'user_id' => [
3619
'key' => 'user.name',
3720
'label' => 'campaigns.members.fields.name',
38-
'render' => function ($model) {
21+
'render' => function (\App\Models\CampaignImport $model) {
3922
if (! $model->user_id) {
4023
return '';
4124
}
@@ -47,12 +30,26 @@ public function columns(): array
4730
'updated_at' => [
4831
'key' => 'updated_at',
4932
'label' => 'campaigns/import.fields.updated',
50-
'render' => function ($model) {
33+
'render' => function (\App\Models\CampaignImport $model) {
5134
$html = '<span data-title="' . $model->updated_at . 'UTC" data-toggle="tooltip">' . $model->updated_at->diffForHumans() . '</span>';
5235

5336
return $html;
5437
},
5538
],
39+
'status' => [
40+
'key' => 'status_id',
41+
'label' => 'campaigns/plugins.fields.status',
42+
'render' => function (\App\Models\CampaignImport $model) {
43+
if ($model->status_id === CampaignImportStatus::FAILED) {
44+
return '<span class="text-error"><i class="fa-regular fa-xmark-circle" aria-hidden="true"></i> ' . __('campaigns/import.status.failed') . '</span>';
45+
} elseif ($model->status_id == CampaignImportStatus::QUEUED) {
46+
return '<span class="text-neutral-content"><i class="fa-regular fa-hourglass" aria-hidden="true"></i> ' . __('campaigns/import.status.queued') . '</span>';
47+
} elseif ($model->status_id == CampaignImportStatus::FINISHED) {
48+
return '<span class="text-success"><i class="fa-regular fa-check-circle" aria-hidden="true"></i> ' . __('campaigns/import.status.finished') . '</span>';
49+
}
50+
return '<span class="text-neutral-content"><i class="fa-regular fa-spinner fa-spin" aria-hidden="true"></i> ' . __('campaigns/import.status.running') . '</span>';
51+
},
52+
],
5653
];
5754

5855
return $columns;

‎app/Services/Campaign/ExportService.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,11 @@ protected function finish(): self
460460
{
461461
// Save all the content.
462462
try {
463-
$path = 'exports/campaigns/' . $this->campaign->id . '/';
464-
$this->exportPath = $path . $this->file;
463+
$path = 'exports/' . $this->campaign->id;
464+
$this->exportPath = $path . '/' . $this->file;
465465
Log::info('Campaign export finished', ['exportPath' => $this->exportPath]);
466-
$this->archive->saveToDisk('s3', $path);
467-
Storage::disk('s3')->setVisibility($this->exportPath, 'public');
466+
$this->archive->saveToDisk('export', $path);
467+
Storage::disk('export')->setVisibility($this->exportPath, 'public');
468468
$this->filesize = (int) floor($this->archive->getFinalSize() / pow(1024, 2));
469469
} catch (Exception $e) {
470470
Log::error('Campaign export', ['action' => 'finish', 'err' => $e->getMessage()]);

‎app/Services/Campaign/Import/ImportService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ protected function download(): self
148148
$path = '/campaigns/' . $this->campaign->id . '/imports/';
149149
foreach ($files as $file) {
150150
Log::info('Want to download ' . $file);
151-
$s3 = Storage::disk('s3')->get($file);
151+
$s3 = Storage::disk('export')->get($file);
152152
$local = $path . uniqid() . '.zip';
153153
Storage::disk('local')->put($local, $s3);
154154

‎config/filesystems.php

+12
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@
7070
'visibility' => 'private',
7171
],
7272

73+
'export' => [
74+
'driver' => 's3',
75+
'key' => env('HETZNER_S3_ACCESS_KEY_ID', env('AWS_ACCESS_KEY_ID')),
76+
'secret' => env('HETZNER_S3_ACCESS_KEY_SECRET', env('AWS_SECRET_ACCESS_KEY')),
77+
'region' => env('HETZNER_S3_REGION', env('AWS_DEFAULT_REGION')),
78+
'bucket' => env('S3_BUCKET_EXPORT', env('AWS_BUCKET')),
79+
'root' => env('APP_ENV'),
80+
'endpoint' => env('HETZNER_S3_ENDPOINT', env('AWS_ENDPOINT')),
81+
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
82+
'throw' => false,
83+
],
84+
7385
's3-assets' => [
7486
'driver' => 's3',
7587
'key' => env('AWS_ACCESS_KEY_ID'),

‎public/build/assets/app-s_6r0suL.css

-1
This file was deleted.

‎public/build/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@
341341
"isEntry": true
342342
},
343343
"resources/sass/app.scss": {
344-
"file": "assets/app-s_6r0suL.css",
344+
"file": "assets/app-enioaHuc.css",
345345
"src": "resources/sass/app.scss",
346346
"isEntry": true
347347
},

‎resources/sass/colour.scss

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@
8282
--tw-text-opacity: 1;
8383
color:hsl(var(--erc)/var(--tw-text-opacity));
8484
}
85+
.text-success {
86+
--tw-text-opacity: 1;
87+
color:hsl(var(--su)/var(--tw-text-opacity))
88+
}
8589
.text-success-content {
8690
--tw-text-opacity: 1;
8791
color:hsl(var(--suc)/var(--tw-text-opacity));

0 commit comments

Comments
 (0)