FEATURE #2389 @20m: add deleting all data from profiler

This commit is contained in:
Michal Kváček
2017-03-28 01:01:21 +02:00
parent aa55ffe46a
commit 7d6a3737e3
9 changed files with 156 additions and 85 deletions
@@ -4,6 +4,7 @@ use App\Http\Controllers\Admin\Controller;
use Carbon\Carbon;
use Illuminate\Support\Facades\Input;
use Modules\Profiler\Entities\HttpLog;
use Modules\Profiler\Entities\QueryLog;
class ProfilerController extends Controller
{
@@ -29,6 +30,7 @@ class ProfilerController extends Controller
if (Input::get('url')) {
$httpLog = $httpLog->where('url', Input::get('url'))
->orderBy('created_at', 'DESC')
->with('queries');
} else {
$displayGrouped = true;
@@ -42,4 +44,24 @@ class ProfilerController extends Controller
$filter = Input::all();
return view('profiler::index', compact('httpLog', 'displayGrouped', 'filter', 'pastDays'));
}
public function destroy()
{
$older = Input::get('olderThan');
if (is_null($older)) {
\DB::statement("SET foreign_key_checks=0");
QueryLog::truncate();
HttpLog::truncate();
\DB::statement("SET foreign_key_checks=1");
} else {
HttpLog::where('created_at', '<=', Carbon::now()
->subDays($older))
->delete();
}
return redirect()
->back()
->with('success', trans('profiler::module.succesfullyDeleted'));
}
}
@@ -1,7 +1,10 @@
<?php
namespace Modules\Profiler\Http\Controllers;
use App\Http\Controllers\Admin\Controller;
use Carbon\Carbon;
use Illuminate\Support\Facades\Input;
use Modules\Profiler\Entities\HttpLog;
class RequestController extends Controller
@@ -9,8 +12,17 @@ class RequestController extends Controller
public function detail(HttpLog $httpLog)
{
$sameRequests = HttpLog::where('url', $httpLog->url)
->where('method', $httpLog->method)
->get();
->where('method', $httpLog->method);
$pastDays = Input::get('pastDays', session('profilerPastDays', 0));
if (is_numeric($pastDays) && $pastDays >= 0) {
$sameRequests = $sameRequests->where('created_at', '>=', Carbon::today()
->subDays($pastDays));
}
session(['profilerPastDays' => $pastDays]);
$sameRequests = $sameRequests->get();
$times = [
'avg' => $sameRequests->avg('time'),
@@ -18,6 +30,8 @@ class RequestController extends Controller
'max' => $sameRequests->max('time')
];
return view('profiler::request.detail', compact('httpLog', 'sameRequests', 'times'));
$filter = Input::all();
return view('profiler::request.detail', compact('httpLog', 'sameRequests', 'times', 'pastDays', 'filter'));
}
}
+3
View File
@@ -16,5 +16,8 @@ Route::group([
Route::get('{httpLog}/queries', 'QueryController@index')
->name('queries.index');
Route::get('delete/all', 'ProfilerController@destroy')
->name('profiler.deleteAll');
});
});
@@ -36,6 +36,9 @@ return [
],
'listDescription' => 'Seznam HTTP požadavků na tuto aplikaci.',
'groupedListDescription' => 'Seznam HTTP požadavků na tuto aplikaci.',
'requestDetail' => 'Detail HTTP požadavku'
'requestDetail' => 'Detail HTTP požadavku',
'deleteAllData' => 'Smazat všechna data',
'deleteOld' => 'Smazat data starší než 30 dní',
'succesfullyDeleted' => 'Úspěšně vymazána data z profileru.',
];
@@ -1,3 +1,4 @@
@if(count($requests) > 0)
<table class="item-list content-overview full-width table striped">
<thead>
<tr>
@@ -25,3 +26,6 @@
@endforeach
</tbody>
</table>
@else
@lang('admin/common.empty')
@endif
@@ -1,3 +1,4 @@
@if(count($requests) > 0)
<table class="item-list content-overview full-width table striped">
<thead>
<tr>
@@ -53,3 +54,7 @@
@endforeach
</tbody>
</table>
@else
@lang('admin/common.empty')
@endif
@@ -4,6 +4,15 @@
@section('headerButtons')
<a class="btn btn-sm rounded btn-primary" href="{{route('profiler.index')}}"><i class="fa fa-list"></i></a>
<div class="pull-right">
@foreach(['0' => 'today', '7' => 'days', '30' => 'days', 'inf' => 'overall'] as $pastDay => $name)
@php $filter['httpLog'] = $httpLog ;$filter['pastDays'] = $pastDay; @endphp
<a class="btn btn-sm rounded @if($pastDays === (string)$pastDay) btn-primary @else btn-secondary @endif"
href="{{route('request.detail', $filter)}}">{{trans_choice('profiler::module.index.pastDays.'.$name, $pastDay)}}</a>
@endforeach
</div>
@endsection
@@ -48,6 +48,16 @@
</div>
</div>
<div class="row text-center">
<a href="{{route('profiler.deleteAll')}}" class="btn btn-danger remove confirm">
<i class="fa fa-trash-o"></i> @lang('profiler::module.deleteAllData')
</a>
<a href="{{route('profiler.deleteAll', ['olderThan' => 30])}}" class="btn btn-danger remove confirm">
<i class="fa fa-trash-o"></i> @lang('profiler::module.deleteOld')
</a>
</div>
+1
View File
@@ -7,4 +7,5 @@ return [
"logoutSuccessfull" => "Odhlášení proběhlo úspěšně",
"no" => "Ne",
"yes" => "Ano",
'empty' => 'Žádná data nebyla nalezena.'
];