INIT: initial commit
This commit is contained in:
@@ -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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user