diff --git a/app/Client.php b/app/Client.php index 1aed226..6837d93 100644 --- a/app/Client.php +++ b/app/Client.php @@ -2,14 +2,15 @@ namespace App; -use App\Traits\Uuids; use Illuminate\Database\Eloquent\Model; -use Illuminate\Notifications\Notifiable; +use Illuminate\Mail\Mailable; +use App\Traits\Uuids; +// use Illuminate\Notifications\Notifiable; class Client extends Model { use Uuids; - use Notifiable; + // use Notifiable; /** * Indicates if the IDs are auto-incrementing. @@ -24,13 +25,6 @@ class Client extends Model * * @var array */ - // protected $fillable = [ - // 'client_name', - // 'secret_key', - // 'access_key', - // 'setup_config' - // ]; protected $guarded = [ 'id' ]; - } \ No newline at end of file diff --git a/app/Http/Controllers/API/v1/BackupController.php b/app/Http/Controllers/API/v1/BackupController.php index 6eba8c6..c73bc28 100644 --- a/app/Http/Controllers/API/v1/BackupController.php +++ b/app/Http/Controllers/API/v1/BackupController.php @@ -1,19 +1,21 @@ toDateTimeString(); - // Sort out timestamps from $message - // dd($data); $begin_time = parse_duplicati_time($data['BeginTime']); $end_time = parse_duplicati_time($data['EndTime']); @@ -81,14 +81,23 @@ class BackupController extends Controller // notify client by email. $client = Client::where('id', '=', $client_id)->first(); - if($backup->status == "Success"){ - $client->notify(new BackupSuccess($backup)); + if($backup->status == "Success") + { + Mail::to($client->email) + ->cc(['matthew@shillam.me.uk','j.kendrick@dentalsupportuk.com']) + ->send(new BackupSuccess($backup)); } - elseif($backup->status == "Warning"){ - $client->notify(new BackupWarning($backup)); + elseif($backup->status == "Warning") + { + Mail::to($client->email) + ->cc(['matthew@shillam.me.uk','j.kendrick@dentalsupportuk.com']) + ->send(new BackupWarning($backup)); } - elseif($backup->status == "Error"){ - $client->notify(new BackupError($backup)); + elseif($backup->status == "Error") + { + Mail::to($client->email) + ->cc(['matthew@shillam.me.uk','j.kendrick@dentalsupportuk.com']) + ->send(new BackupError($backup)); } } diff --git a/app/Mail/BackupError.php b/app/Mail/BackupError.php new file mode 100644 index 0000000..3b9bc44 --- /dev/null +++ b/app/Mail/BackupError.php @@ -0,0 +1,36 @@ +backup = $backup; + } + + /** + * Build the message. + * + * @return $this + */ + public function build() + { + return $this->from('reports@mydentalbackup.co.uk') + ->subject('ERROR Your backup ( ' . $this->backup->schedule_name . ' ) has a warning!') + ->markdown('mail.backup.warning', ['backup' => $this->backup]); + } +} diff --git a/app/Mail/BackupSuccess.php b/app/Mail/BackupSuccess.php new file mode 100644 index 0000000..aa14776 --- /dev/null +++ b/app/Mail/BackupSuccess.php @@ -0,0 +1,36 @@ +backup = $backup; + } + + /** + * Build the message. + * + * @return $this + */ + public function build() + { + return $this->from('reports@mydentalbackup.co.uk') + ->subject('SUCCESS Your backup ( ' . $this->backup->schedule_name . ' ) completed succesfully') + ->markdown('mail.backup.success', ['backup' => $this->backup]); + } +} diff --git a/app/Mail/BackupWarning.php b/app/Mail/BackupWarning.php new file mode 100644 index 0000000..fbcab99 --- /dev/null +++ b/app/Mail/BackupWarning.php @@ -0,0 +1,36 @@ +backup = $backup; + } + + /** + * Build the message. + * + * @return $this + */ + public function build() + { + return $this->from('reports@mydentalbackup.co.uk') + ->subject('SUCCESS Your backup ( ' . $this->backup->schedule_name . ' ) completed succesfully') + ->markdown('mail.backup.success', ['backup' => $this->backup]); + } +} diff --git a/app/Notifications/BackupComplete.php b/app/Notifications/BackupComplete.php deleted file mode 100644 index 556ae9d..0000000 --- a/app/Notifications/BackupComplete.php +++ /dev/null @@ -1,68 +0,0 @@ -backup = $backup; - } - - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - return ['mail']; - } - - /** - * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage - */ - public function toMail($notifiable) - { - return (new MailMessage) - - ->line('The backup schedule ( ' . $this->backup->schedule_name . ' ) has completed succesfully!') - ->action('Contact us ', url('/')) - ->line($this->backup->schedule_name . ' has completed successfully! yay!') - ->line('Size of added files: ' . readableBytes($this->backup->size_of_added_files)) - ->line('Thank you for using our application!'); - } - - - /** - * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array - */ - public function toArray($notifiable) - { - return [ - // - ]; - } -} diff --git a/app/Notifications/BackupError.php b/app/Notifications/BackupError.php deleted file mode 100644 index 7f534dc..0000000 --- a/app/Notifications/BackupError.php +++ /dev/null @@ -1,62 +0,0 @@ -backup = $backup; - } - - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - return ['mail']; - } - - /** - * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage - */ - public function toMail($notifiable) - { - return (new MailMessage) - ->subject('ERROR Your backup ( ' . $this->backup->schedule_name . ' ) has an error!') - ->greeting('Error!') - ->markdown('mail.backup.error', ['backup' => $this->backup]); - } - - /** - * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array - */ - public function toArray($notifiable) - { - return [ - // - ]; - } -} diff --git a/app/Notifications/BackupSuccess.php b/app/Notifications/BackupSuccess.php deleted file mode 100644 index a3d2de8..0000000 --- a/app/Notifications/BackupSuccess.php +++ /dev/null @@ -1,62 +0,0 @@ -backup = $backup; - } - - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - return ['mail']; - } - - /** - * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage - */ - public function toMail($notifiable) - { - return (new MailMessage) - ->subject('SUCCESS Your backup ( ' . $this->backup->schedule_name . ' ) completed succesfully') - ->greeting('Success!') - ->markdown('mail.backup.success', ['backup' => $this->backup]); - } - - /** - * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array - */ - public function toArray($notifiable) - { - return [ - // - ]; - } -} diff --git a/app/Notifications/BackupWarning.php b/app/Notifications/BackupWarning.php deleted file mode 100644 index fafe741..0000000 --- a/app/Notifications/BackupWarning.php +++ /dev/null @@ -1,62 +0,0 @@ -backup = $backup; - } - - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - return ['mail']; - } - - /** - * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage - */ - public function toMail($notifiable) - { - return (new MailMessage) - ->subject('ERROR Your backup ( ' . $this->backup->schedule_name . ' ) has a warning!') - ->greeting('Error!') - ->markdown('mail.backup.warning', ['backup' => $this->backup]); - } - - /** - * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array - */ - public function toArray($notifiable) - { - return [ - // - ]; - } -}