Added recent errors to self host support messages

This commit is contained in:
Hillel Coren 2017-08-29 12:43:57 +03:00
parent 2c10dcae41
commit 1b28a2b377
10 changed files with 119 additions and 29 deletions

View File

@ -366,6 +366,17 @@ class AppController extends BaseController
}
}
public function errors()
{
if (Utils::isNinjaProd()) {
return redirect('/');
}
$errors = Utils::getErrors();
return view('errors.list', compact('errors'));
}
public function stats()
{
if (! hash_equals(Input::get('password'), env('RESELLER_PASSWORD'))) {

View File

@ -131,12 +131,18 @@ class HomeController extends BaseController
*/
public function contactUs()
{
Mail::raw(request()->contact_us_message, function ($message) {
$message = request()->contact_us_message;
if (request()->include_errors) {
$message .= "\n\n" . join("\n", Utils::getErrors());
}
Mail::raw($message, function ($message) {
$subject = 'Customer Message: ';
if (Utils::isNinja()) {
if (Utils::isNinjaProd()) {
$subject .= config('database.default');
} else {
$subject .= 'v' . NINJA_VERSION;
$subject .= 'Self-Host';
}
$message->to(env('CONTACT_EMAIL', 'contact@invoiceninja.com'))
->from(CONTACT_EMAIL, Auth::user()->present()->fullName)

View File

@ -260,6 +260,7 @@ Route::group([
Route::get('/account/{account_key}', 'UserController@viewAccountByKey');
Route::get('/unlink_account/{user_account_id}/{user_id}', 'UserController@unlinkAccount');
Route::get('/manage_companies', 'UserController@manageCompanies');
Route::get('/errors', 'AppController@errors');
Route::get('api/tokens', 'TokenController@getDatatable');
Route::resource('tokens', 'TokenController');

View File

@ -2,6 +2,7 @@
namespace App\Libraries;
use DB;
use App;
use Auth;
use Cache;
@ -235,6 +236,26 @@ class Utils
return App::getLocale() == 'en';
}
public static function getDebugInfo()
{
if ($info = session('DEBUG_INFO')) {
return $info;
}
$mysqlVersion = DB::select( DB::raw("select version() as version") )[0]->version;
$accountKey = Auth::check() ? Auth::user()->account->account_key : '';
$info = "App Version: v" . NINJA_VERSION . "\\n" .
"White Label: " . (Utils::isWhiteLabel() ? 'Yes' : 'No') . " - {$accountKey}\\n" .
"Server OS: " . php_uname('s') . ' ' . php_uname('r') . "\\n" .
"PHP Version: " . phpversion() . "\\n" .
"MySQL Version: " . $mysqlVersion;
session(['DEBUG_INFO' => $info]);
return $info;
}
public static function getLocaleRegion()
{
$parts = explode('_', App::getLocale());
@ -410,6 +431,27 @@ class Utils
];
}
public static function getErrors()
{
$data = [];
$filename = storage_path('logs/laravel-error.log');
if (! file_exists($filename)) {
return $data;
}
$errors = file($filename);
for ($i=count($errors)-1; $i>=0; $i--) {
$data[] = $errors[$i];
if (count($data) >= 10) {
break;
}
}
return $data;
}
public static function parseFloat($value)
{
$value = preg_replace('/[^0-9\.\-]/', '', $value);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -113,6 +113,14 @@ function getQuarter(offset) {
return 'Q' + quarter;
}
// https://gist.github.com/beiyuu/2029907
$.fn.selectRange = function(start, end) {
var e = document.getElementById($(this).attr('id')); // I don't know why... but $(this) don't want to work today :-/
if (!e) return;
else if (e.setSelectionRange) { e.focus(); e.setSelectionRange(start, end); } /* WebKit */
else if (e.createTextRange) { var range = e.createTextRange(); range.collapse(true); range.moveEnd('character', end); range.moveStart('character', start); range.select(); } /* IE */
else if (e.selectionStart) { e.selectionStart = start; e.selectionEnd = end; }
};
/* Default class modification */
if ($.fn.dataTableExt) {

View File

@ -2421,6 +2421,10 @@ $LANG = array(
'applied_discount' => 'The coupon has been applied, the plan price has been reduced by :discount%.',
'applied_free_year' => 'The coupon has been applied, your account has been upgraded to pro for one year.',
'contact_us_help' => 'If you\'re reporting an error please include any relevant logs from storage/logs/laravel-error.log',
'include_errors' => 'Include Errors',
'include_errors_help' => 'Include :link from storage/logs/laravel-error.log',
'recent_errors' => 'recent errors',
);

View File

@ -0,0 +1,7 @@
@if (count($errors))
@foreach ($errors as $error)
<p>{{ $error }}</p>
@endforeach
@else
There are no errors
@endif

View File

@ -25,6 +25,13 @@
{!! Former::textarea('contact_us_message')
->label('message')
->rows(10) !!}
@if (! Utils::isNinjaProd())
{!! Former::checkbox('include_errors')->label(false)
->text(trans('texts.include_errors_help', [
'link' => link_to('/errors', trans('texts.recent_errors'), ['target' => '_blank'])
])) !!}
@endif
</div>
<div class="response-div" style="display: none; font-size: 16px">
{{ trans('texts.contact_us_response') }}
@ -56,9 +63,13 @@
$(function() {
$('#contactUsModal').on('shown.bs.modal', function() {
var message = '';
@if (! Utils::isNinjaProd())
message = '\n\n' + "{{ Utils::getDebugInfo() }}";
@endif
$('#contactUsModal .input-div').show();
$('#contactUsModal .response-div').hide();
$("#contact_us_message").focus();
$("#contact_us_message").val(message).focus().selectRange(0, 0);
})
})