Refactor a bit
This commit is contained in:
parent
2f4e89944c
commit
f7d3d225e4
|
|
@ -13,3 +13,4 @@ yarn-error.log
|
|||
.env
|
||||
.phpunit.result.cache
|
||||
.DS_Store
|
||||
public/get.php
|
||||
|
|
|
|||
|
|
@ -8,25 +8,14 @@ use Illuminate\Http\Request;
|
|||
use App\Mail\BackupWarning;
|
||||
use App\Mail\BackupSuccess;
|
||||
use App\Mail\BackupError;
|
||||
use App\Mail\BackupDebug;
|
||||
use Carbon\Carbon;
|
||||
use App\Schedule;
|
||||
use App\Backup;
|
||||
use App\Client;
|
||||
|
||||
class BackupController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function test()
|
||||
{
|
||||
$created_at = Backup::all()-> pluck('created_at');
|
||||
return $created_at;
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
|
|
@ -36,9 +25,18 @@ class BackupController extends Controller
|
|||
*/
|
||||
public function store($client_id, $schedule_name, Request $request)
|
||||
{
|
||||
$client = Client::where('id', '=', $client_id)->first();
|
||||
$current_time = Carbon::now()->toDateTimeString();
|
||||
|
||||
$response = json_decode( file_get_contents('php://input') );
|
||||
$data = $response->Data;
|
||||
if( isset($response->Data->ParsedResult)){
|
||||
$data = $response->Data;
|
||||
}
|
||||
else{
|
||||
Mail::to('matthew@shillam.me.uk')
|
||||
->send(new BackupDebug($client, $response));
|
||||
return response()->json(['error' => 'A Problem with the data provided from Duplicati!'], 403);
|
||||
}
|
||||
|
||||
$schedule = Schedule::updateOrCreate(
|
||||
['client_id' => $client_id, 'name' => $schedule_name],
|
||||
|
|
@ -77,30 +75,28 @@ class BackupController extends Controller
|
|||
'version' => $data->Version
|
||||
));
|
||||
|
||||
// notify client by email.
|
||||
$client = Client::where('id', '=', $client_id)->first();
|
||||
|
||||
/**
|
||||
* notify client by email
|
||||
*/
|
||||
if($backup->status == "Success")
|
||||
{
|
||||
Mail::to($client->email)
|
||||
->cc(['matthew@shillam.me.uk','j.kendrick@dentalsupportuk.com'])
|
||||
->send(new BackupSuccess($backup));
|
||||
Mail::to($client->email)
|
||||
->send(new BackupSuccess($backup, $client));
|
||||
}
|
||||
elseif($backup->status == "Warning")
|
||||
{
|
||||
Mail::to($client->email)
|
||||
->cc(['matthew@shillam.me.uk','j.kendrick@dentalsupportuk.com'])
|
||||
->send(new BackupWarning($backup));
|
||||
->send(new BackupWarning($backup, $client));
|
||||
}
|
||||
elseif($backup->status == "Error")
|
||||
{
|
||||
Mail::to($client->email)
|
||||
->cc(['matthew@shillam.me.uk','j.kendrick@dentalsupportuk.com'])
|
||||
->send(new BackupError($backup));
|
||||
->send(new BackupError($backup, $client));
|
||||
}
|
||||
else{
|
||||
Mail::to('matthew@shillam.me.uk')
|
||||
->send(new BackupError($backup));
|
||||
->send(new BackupDebug($client, $response));
|
||||
return response()->json(['error' => 'A Problem with the data provided from Duplicati!'], 403);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ class ScheduleResource extends JsonResource
|
|||
// return parent::toArray($request);
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->client_name,
|
||||
'last_backup_status' => $this->access_key,
|
||||
'name' => $this->name,
|
||||
'last_backup_status' => $this->last_backup_status,
|
||||
'client' => $this->client->client_name,
|
||||
'client_id' => $this->client->id,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
use App\Client;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class BackupDebug extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($client, $response)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this->from('reports@mydentalbackup.co.uk')
|
||||
->subject('** MAILING-PROBLEM ** for : ' . $this->client->client_name)
|
||||
->markdown('mail.backup.debug', ['response' => $this->response, 'client' => $this->client]);
|
||||
}
|
||||
}
|
||||
|
|
@ -17,9 +17,10 @@ class BackupError extends Mailable
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Backup $backup)
|
||||
public function __construct(Backup $backup, $client)
|
||||
{
|
||||
$this->backup = $backup;
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -30,7 +31,8 @@ class BackupError extends Mailable
|
|||
public function build()
|
||||
{
|
||||
return $this->from('reports@mydentalbackup.co.uk')
|
||||
->subject('ERROR Your backup ( ' . $this->backup->schedule_name . ' ) has an error!')
|
||||
->cc('reports@mydentalbackup.co.uk')
|
||||
->subject('Backup ( ' . $this->backup->schedule_name . ' ) Error! for : ' . $this->client->client_name)
|
||||
->markdown('mail.backup.error', ['backup' => $this->backup]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,9 +17,10 @@ class BackupSuccess extends Mailable
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Backup $backup)
|
||||
public function __construct(Backup $backup, $client)
|
||||
{
|
||||
$this->backup = $backup;
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -30,7 +31,8 @@ class BackupSuccess extends Mailable
|
|||
public function build()
|
||||
{
|
||||
return $this->from('reports@mydentalbackup.co.uk')
|
||||
->subject('SUCCESS Your backup ( ' . $this->backup->schedule_name . ' ) completed successfully')
|
||||
->cc('reports@mydentalbackup.co.uk')
|
||||
->subject('Backup ( ' . $this->backup->schedule_name . ' ) Success! for : ' . $this->client->client_name . '')
|
||||
->markdown('mail.backup.success', ['backup' => $this->backup]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,9 +17,10 @@ class BackupWarning extends Mailable
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Backup $backup)
|
||||
public function __construct(Backup $backup, $client)
|
||||
{
|
||||
$this->backup = $backup;
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -30,7 +31,8 @@ class BackupWarning extends Mailable
|
|||
public function build()
|
||||
{
|
||||
return $this->from('reports@mydentalbackup.co.uk')
|
||||
->subject('WARNING Your backup ( ' . $this->backup->schedule_name . ' ) has warnings')
|
||||
->cc('reports@mydentalbackup.co.uk')
|
||||
->subject('Backup ( ' . $this->backup->schedule_name . ' ) Warning! for : ' . $this->client->client_name . '')
|
||||
->markdown('mail.backup.warning', ['backup' => $this->backup]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
@component('mail::message')
|
||||
<h4 class="error">Error!</h4>
|
||||
@component('mail::panel')
|
||||
No mail was sent to users for ( {{$client->client_name}} ) has some errors! See log below...
|
||||
@endcomponent
|
||||
|
||||
<div class="dark-box">
|
||||
<h1 style="text-align:center;font-weight:normal;color:white;">Full variable data logs..</h1>
|
||||
</div>
|
||||
|
||||
@component('mail::panel')
|
||||
<?php var_dump($response); ?>
|
||||
@endcomponent
|
||||
|
||||
Regards,<br>
|
||||
{{ config('app.name') }} - auto notification bot.
|
||||
|
||||
@endcomponent
|
||||
Loading…
Reference in New Issue