added report-not-found email
This commit is contained in:
parent
741f195a24
commit
22222990b6
|
|
@ -41,6 +41,7 @@ public function save()
|
|||
}
|
||||
|
||||
public static function saveAndSendMailing($report, $subject, $message, $recipients) {
|
||||
if ($report->documentExists()) {
|
||||
$mailing = $report->project->mailings()->create([
|
||||
'subject' => $subject,
|
||||
'message' => $message,
|
||||
|
|
@ -55,6 +56,13 @@ public static function saveAndSendMailing($report, $subject, $message, $recipien
|
|||
$mailing->recipients()->createMany($recipients);
|
||||
Mail::to($mailing->recipients()->pluck('email')->toArray())
|
||||
->send(new \App\Mail\ReportMailer($mailing, $report));
|
||||
} else {
|
||||
self::sendReportNotFoundNotificationToAdmin($report);
|
||||
}
|
||||
}
|
||||
|
||||
private static function sendReportNotFoundNotificationToAdmin($report) {
|
||||
Mail::to(config('mail.from.address'))
|
||||
->send(new \App\Mail\ReportNotFound($report));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
68
laravel_app/app/Mail/ReportNotFound.php
Normal file
68
laravel_app/app/Mail/ReportNotFound.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\ProjectReport;
|
||||
use App\ProjectLogger;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Attachment;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ReportNotFound extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct(ProjectReport $report)
|
||||
{
|
||||
$this->report = $report;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: sprintf('Report Not Found for project %s', $this->report->project->name)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'emails.report-not-found',
|
||||
with: [
|
||||
'logoPath'=> resource_path('images/smartcane.png'),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
$path = ProjectLogger::getLogFileForToday($this->report->project);
|
||||
if ($path) {
|
||||
$filename = sprintf('%s_%s.log', $this->report->project->name, now()->format('Ymd'));
|
||||
return [
|
||||
Attachment::fromPath($path)
|
||||
->as($filename)
|
||||
->withMime('text/plain'),
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
@ -70,9 +70,14 @@ public static function getReportDateForYearAndWeek(Project $project, $year, $wee
|
|||
return $reportDay;
|
||||
}
|
||||
|
||||
public function documentExists()
|
||||
{
|
||||
return File::exists($this->getFullPathName());
|
||||
}
|
||||
|
||||
public function deleteMe()
|
||||
{
|
||||
if (File::exists($this->getFullPathName())) {
|
||||
if ($this->documentExists()) {
|
||||
File::delete($this->getFullPathName());
|
||||
}
|
||||
$this->delete();
|
||||
|
|
|
|||
|
|
@ -28,6 +28,15 @@ public static function getAsList(Project $project)
|
|||
];
|
||||
}
|
||||
}
|
||||
return collect($logs);
|
||||
return collect($logs)->orderBy('name', 'desc');
|
||||
}
|
||||
|
||||
public static function getLogFileForToday(Project $project)
|
||||
{
|
||||
$logPath = $project->download_path . '/logs/' . now()->format('Ymd') . '.log';
|
||||
if(Storage::exists($logPath)) {
|
||||
return Storage::path($logPath);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
<x-mail::layout>
|
||||
{{-- Header --}}
|
||||
<x-slot:header>
|
||||
<x-mail::header :url="config('app.url')">
|
||||
<span>
|
||||
<img src="{{$message->embed($logoPath)}}" alt="Smartcane Logo">
|
||||
</span>
|
||||
</x-mail::header>
|
||||
</x-slot:header>
|
||||
{{-- Body --}}
|
||||
# <h1 style="text-align: center">Report not found</h1>
|
||||
* please view log in attachment.*
|
||||
*This report is automatically generated. Do not reply*
|
||||
## Thanks.
|
||||
## Contact
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p style="text-align:center;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512" style="width: 20px;height: 20px;"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path fill="#475060" d="M16 64C16 28.7 44.7 0 80 0H304c35.3 0 64 28.7 64 64V448c0 35.3-28.7 64-64 64H80c-35.3 0-64-28.7-64-64V64zM224 448a32 32 0 1 0 -64 0 32 32 0 1 0 64 0zM304 64H80V384H304V64z"/></svg>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p style="text-align:justify-all;"><a href="tel:0031620376734">+31 6 2037 6734</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p style="text-align:center;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" style="width: 20px;height: 20px;"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path fill="#475060" d="M256 64C150 64 64 150 64 256s86 192 192 192c17.7 0 32 14.3 32 32s-14.3 32-32 32C114.6 512 0 397.4 0 256S114.6 0 256 0S512 114.6 512 256v32c0 53-43 96-96 96c-29.3 0-55.6-13.2-73.2-33.9C320 371.1 289.5 384 256 384c-70.7 0-128-57.3-128-128s57.3-128 128-128c27.9 0 53.7 8.9 74.7 24.1c5.7-5 13.1-8.1 21.3-8.1c17.7 0 32 14.3 32 32v80 32c0 17.7 14.3 32 32 32s32-14.3 32-32V256c0-106-86-192-192-192zm64 192a64 64 0 1 0 -128 0 64 64 0 1 0 128 0z"/></svg>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p style="text-align:justify-all;"><a href="mailto:info@smartcane.org">info@smartcane.org</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p style="text-align:center;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512" style="width: 20px;height: 20px;"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path fill="#475060" d="M48 0C21.5 0 0 21.5 0 48V464c0 26.5 21.5 48 48 48h96V432c0-26.5 21.5-48 48-48s48 21.5 48 48v80h96c26.5 0 48-21.5 48-48V48c0-26.5-21.5-48-48-48H48zM64 240c0-8.8 7.2-16 16-16h32c8.8 0 16 7.2 16 16v32c0 8.8-7.2 16-16 16H80c-8.8 0-16-7.2-16-16V240zm112-16h32c8.8 0 16 7.2 16 16v32c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V240c0-8.8 7.2-16 16-16zm80 16c0-8.8 7.2-16 16-16h32c8.8 0 16 7.2 16 16v32c0 8.8-7.2 16-16 16H272c-8.8 0-16-7.2-16-16V240zM80 96h32c8.8 0 16 7.2 16 16v32c0 8.8-7.2 16-16 16H80c-8.8 0-16-7.2-16-16V112c0-8.8 7.2-16 16-16zm80 16c0-8.8 7.2-16 16-16h32c8.8 0 16 7.2 16 16v32c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V112zM272 96h32c8.8 0 16 7.2 16 16v32c0 8.8-7.2 16-16 16H272c-8.8 0-16-7.2-16-16V112c0-8.8 7.2-16 16-16z"/></svg>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p style="text-align:justify-all;"><a href="https://smartcane.org">Bevrijdingsstraat 38, 6703AA, Wageningen, The Netherlands</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{{-- Footer --}}
|
||||
<x-slot:footer>
|
||||
<x-mail::footer>
|
||||
<p style="text-align:center;">SmartCane is an innovative spinoff from the Resilience Network, which includes SmartFarming BV and IRIPO Lda.</p>
|
||||
<p>
|
||||
© {{ date('Y') }} {{ config('app.name') }}. {{ __('All rights reserved.') }}
|
||||
</p>
|
||||
|
||||
</x-mail::footer>
|
||||
</x-slot:footer>
|
||||
</x-mail::layout>
|
||||
|
|
@ -16,11 +16,21 @@
|
|||
Route::get('/', function () {
|
||||
return view('welcome');
|
||||
});
|
||||
|
||||
if (config('app.env') === 'local') {
|
||||
Route::get('no-report-found', function () {
|
||||
$report = App\Models\ProjectReport::find(287);
|
||||
return new App\Mail\ReportNotFound($report);
|
||||
});
|
||||
Route::get('/mailable/{id}', function ($id) {
|
||||
if($project_mailing = App\Models\ProjectMailing::find($id)) return new App\Mail\ReportMailer($project_mailing);
|
||||
if ($project_mailing = App\Models\ProjectMailing::find($id)) {
|
||||
return new App\Mail\ReportMailer($project_mailing);
|
||||
}
|
||||
return abort(404);
|
||||
})->name('mail');
|
||||
}
|
||||
|
||||
|
||||
|
||||
Route::middleware([
|
||||
'auth:sanctum',
|
||||
config('jetstream.auth_session'),
|
||||
|
|
@ -29,8 +39,10 @@
|
|||
Route::get('/dashboard', function () {
|
||||
return view('dashboard');
|
||||
})->name('dashboard');
|
||||
Route::get('/projects/{projectName}/{currentTab?}', [\App\Http\Controllers\ProjectController::class, 'show'])->name('project.show');
|
||||
Route::get('/projects/{projectReport}/download', [\App\Http\Controllers\ProjectReportController::class, 'download'])->name('project.report.download');
|
||||
Route::get('/projects/{projectName}/{currentTab?}',
|
||||
[\App\Http\Controllers\ProjectController::class, 'show'])->name('project.show');
|
||||
Route::get('/projects/{projectReport}/download',
|
||||
[\App\Http\Controllers\ProjectReportController::class, 'download'])->name('project.report.download');
|
||||
Route::get('/projects', [\App\Http\Controllers\ProjectController::class, 'index'])->name('project');
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue