1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Mail/SupportMessageSent.php

76 lines
2.1 KiB
PHP
Raw Normal View History

<?php
namespace App\Mail;
use App\Utils\Ninja;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
2020-10-28 11:10:49 +01:00
use LimitIterator;
use SplFileObject;
class SupportMessageSent extends Mailable
{
// use Queueable, SerializesModels;
2021-06-21 23:21:59 +02:00
public $support_message;
public $send_logs;
2021-06-21 23:21:59 +02:00
public function __construct($support_message, $send_logs)
{
2021-06-21 23:21:59 +02:00
$this->support_message = $support_message;
$this->send_logs = $send_logs;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$system_info = null;
$log_lines = [];
/*
* With self-hosted version of Ninja,
* we are going to bundle system-level info
* and last 10 lines of laravel.log file.
*/
if (Ninja::isSelfHost() && $this->send_logs !== false) {
$system_info = Ninja::getDebugInfo();
2020-10-28 11:10:49 +01:00
$log_file = new SplFileObject(sprintf('%s/laravel.log', base_path('storage/logs')));
$log_file->seek(PHP_INT_MAX);
$last_line = $log_file->key();
2021-03-22 11:55:09 +01:00
$lines = new LimitIterator($log_file, $last_line - 100, $last_line);
$log_lines = iterator_to_array($lines);
}
$account = auth()->user()->account;
2021-07-04 00:22:33 +02:00
$plan = $account->plan ?: 'Forever Free';
$company = auth()->user()->company();
$user = auth()->user();
2021-06-20 23:52:45 +02:00
if(Ninja::isHosted())
2021-06-30 13:21:46 +02:00
$subject = "Hosted {$user->present()->name} - [{$plan} - {$company->db}]";
2021-06-20 23:52:45 +02:00
else
2021-06-30 13:21:46 +02:00
$subject = "Self Host {$user->present()->name} - [{$plan} - {$company->db}]";
2021-07-13 00:07:09 +02:00
return $this->from(config('mail.from.address'), $user->present()->name())
2021-05-25 01:31:12 +02:00
->replyTo($user->email, $user->present()->name())
2021-05-24 13:31:52 +02:00
->subject($subject)
2021-06-12 23:19:56 +02:00
->view('email.support.message', [
2021-06-21 23:29:04 +02:00
'support_message' => $this->support_message,
2021-05-24 13:31:52 +02:00
'system_info' => $system_info,
'laravel_log' => $log_lines,
2021-06-12 23:19:56 +02:00
'logo' => $company->present()->logo(),
2021-05-24 13:31:52 +02:00
]);
}
}