2019-10-16 22:12:38 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Mail;
|
|
|
|
|
|
|
|
use App\Utils\Ninja;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Mail\Mailable;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2023-02-16 02:36:09 +01:00
|
|
|
use Illuminate\Support\Carbon;
|
2020-10-28 11:10:49 +01:00
|
|
|
use LimitIterator;
|
|
|
|
use SplFileObject;
|
2019-10-16 22:12:38 +02:00
|
|
|
|
|
|
|
class SupportMessageSent extends Mailable
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
// use Queueable, SerializesModels;
|
2019-10-16 22:12:38 +02:00
|
|
|
|
2021-09-30 00:13:48 +02:00
|
|
|
public $data;
|
2019-10-16 22:12:38 +02:00
|
|
|
|
2020-01-19 04:02:02 +01:00
|
|
|
public $send_logs;
|
|
|
|
|
2021-09-30 00:13:48 +02:00
|
|
|
public function __construct(array $data, $send_logs)
|
2019-10-16 22:12:38 +02:00
|
|
|
{
|
2021-09-30 00:13:48 +02:00
|
|
|
$this->data = $data;
|
2020-01-19 04:02:02 +01:00
|
|
|
$this->send_logs = $send_logs;
|
2019-10-16 22:12:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the message.
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function build()
|
|
|
|
{
|
2022-04-27 01:39:52 +02:00
|
|
|
$system_info = request()->has('version') ? 'Version: '.request()->input('version') : 'Version: No Version Supplied.';
|
|
|
|
|
2019-10-16 22:12:38 +02:00
|
|
|
$log_lines = [];
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
/*
|
2019-10-16 22:12:38 +02:00
|
|
|
* With self-hosted version of Ninja,
|
|
|
|
* we are going to bundle system-level info
|
|
|
|
* and last 10 lines of laravel.log file.
|
|
|
|
*/
|
2020-01-19 04:02:02 +01:00
|
|
|
if (Ninja::isSelfHost() && $this->send_logs !== false) {
|
2019-10-16 22:12:38 +02:00
|
|
|
$system_info = Ninja::getDebugInfo();
|
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
$log_file = new SplFileObject(sprintf('%s/laravel.log', base_path('storage/logs')));
|
2019-10-16 22:12:38 +02:00
|
|
|
|
|
|
|
$log_file->seek(PHP_INT_MAX);
|
|
|
|
$last_line = $log_file->key();
|
2022-06-21 11:57:17 +02:00
|
|
|
|
|
|
|
$lines = new LimitIterator($log_file, max(0, $last_line - 100), $last_line);
|
2019-10-16 22:12:38 +02:00
|
|
|
$log_lines = iterator_to_array($lines);
|
|
|
|
}
|
|
|
|
|
2020-05-04 13:13:46 +02:00
|
|
|
$account = auth()->user()->account;
|
|
|
|
|
2021-07-13 13:25:17 +02:00
|
|
|
$priority = '';
|
2021-08-16 06:34:51 +02:00
|
|
|
$plan = $account->plan ?: 'customer support';
|
2021-08-15 23:15:03 +02:00
|
|
|
$plan = ucfirst($plan);
|
2021-07-13 13:25:17 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (strlen($account->plan) > 1) {
|
2021-07-13 13:25:17 +02:00
|
|
|
$priority = '[PRIORITY] ';
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2020-05-04 13:13:46 +02:00
|
|
|
|
|
|
|
$company = auth()->user()->company();
|
|
|
|
$user = auth()->user();
|
2022-06-21 11:57:17 +02:00
|
|
|
$db = str_replace('db-ninja-', '', $company->db);
|
|
|
|
$is_large = $company->is_large ? 'L' : 'S';
|
|
|
|
$platform = array_key_exists('platform', $this->data) ? $this->data['platform'] : 'U';
|
2023-07-27 11:22:33 +02:00
|
|
|
$migrated = ctype_lower(preg_replace('/[0-9]+/', '', $company->company_key)) ? 'M' : '';
|
2022-06-21 11:57:17 +02:00
|
|
|
$trial = $account->isTrial() ? 'T' : '';
|
|
|
|
$plan = str_replace('_', ' ', $plan);
|
|
|
|
|
2022-09-05 00:19:03 +02:00
|
|
|
$plan_status = '';
|
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
if ($account->plan_expires && Carbon::parse($account->plan_expires)->lt(now())) {
|
2022-09-11 12:29:11 +02:00
|
|
|
$plan_status = 'Plan Expired :: ';
|
2023-02-16 02:36:09 +01:00
|
|
|
}
|
2022-09-05 00:19:03 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (Ninja::isHosted()) {
|
2022-09-05 00:19:03 +02:00
|
|
|
$subject = "{$priority}Hosted-{$db}-{$is_large}{$platform}{$migrated}{$trial} :: {$plan} :: {$plan_status} ".date('M jS, g:ia');
|
2022-06-21 11:57:17 +02:00
|
|
|
} else {
|
2021-10-18 12:46:26 +02:00
|
|
|
$subject = "{$priority}Self Hosted :: {$plan} :: {$is_large}{$platform}{$migrated} :: ".date('M jS, g:ia');
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2020-05-04 13:13:46 +02:00
|
|
|
|
2022-06-21 11:57:17 +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', [
|
2022-03-30 05:14:04 +02:00
|
|
|
'support_message' => nl2br($this->data['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(),
|
2022-06-21 11:57:17 +02:00
|
|
|
'settings' => $company->settings,
|
2021-05-24 13:31:52 +02:00
|
|
|
]);
|
2019-10-16 22:12:38 +02:00
|
|
|
}
|
|
|
|
}
|