INIT: initial commit

This commit is contained in:
Michal Kváček
2017-09-23 00:46:53 +02:00
commit ed32a1c27b
29 changed files with 935 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
<?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;
use Modules\Profiler\Entities\QueryLog;
class ProfilerController extends Controller
{
public function index()
{
$filters = [];
$pastDays = Input::get('pastDays', session('profilerPastDays', 0));
$httpLog = HttpLog::query();
if (is_numeric($pastDays) && $pastDays >= 0) {
$httpLog = $httpLog->where('created_at', '>=', Carbon::today()
->subDays($pastDays));
}
session(['profilerPastDays' => $pastDays]);
if (Input::get('method')) {
$filters[] = 'method';
$httpLog = $httpLog->where('method', Input::get('method'));
}
$displayGrouped = false;
if (Input::get('url')) {
$httpLog = $httpLog->where('url', Input::get('url'))
->orderBy('created_at', 'DESC')
->with('queries');
} else {
$displayGrouped = true;
$httpLog = $httpLog->groupBy('url', 'method')
->select(\DB::raw('*'), \DB::raw('COUNT(url) as total'), \DB::raw('AVG(time) as time_avg'))
->orderBy('total', 'DESC');
}
$httpLog = $httpLog->paginate(25);
$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'));
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace Modules\Profiler\Http\Controllers;
use App\Http\Controllers\Admin\Controller;
use Modules\Profiler\Entities\HttpLog;
class QueryController extends Controller {
public function index(HttpLog $httpLog) {
$queries = $httpLog->queries;
return view('profiler::queries.index', compact('queries'));
}
}
+37
View File
@@ -0,0 +1,37 @@
<?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
{
public function detail(HttpLog $httpLog)
{
$sameRequests = HttpLog::where('url', $httpLog->url)
->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'),
'min' => $sameRequests->min('time'),
'max' => $sameRequests->max('time')
];
$filter = Input::all();
return view('profiler::request.detail', compact('httpLog', 'sameRequests', 'times', 'pastDays', 'filter'));
}
}
View File
View File
+23
View File
@@ -0,0 +1,23 @@
<?php
Route::group([
'prefix' => LaravelLocalization::setLocale(),
'namespace' => 'Modules\Profiler\Http\Controllers'
], function () {
Route::group([
'middleware' => ['admin'],
'prefix' => 'admin/profiler'
], function () {
Route::get('/', 'ProfilerController@index')
->name('profiler.index');
Route::get('{httpLog}', 'RequestController@detail')
->name('request.detail');
Route::get('{httpLog}/queries', 'QueryController@index')
->name('queries.index');
Route::get('delete/all', 'ProfilerController@destroy')
->name('profiler.deleteAll');
});
});