2019-08-31 03:59:08 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Contracts\Controller;
|
2019-10-30 21:55:32 +08:00
|
|
|
use App\Services\CronService;
|
2019-08-31 03:59:08 +08:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Artisan;
|
|
|
|
use Laracasts\Flash\Flash;
|
|
|
|
|
|
|
|
class MaintenanceController extends Controller
|
|
|
|
{
|
2019-10-30 21:55:32 +08:00
|
|
|
private $cronSvc;
|
|
|
|
|
|
|
|
public function __construct(CronService $cronSvc)
|
2019-08-31 03:59:08 +08:00
|
|
|
{
|
2019-10-30 21:55:32 +08:00
|
|
|
$this->cronSvc = $cronSvc;
|
2019-08-31 03:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
{
|
2019-10-30 21:55:32 +08:00
|
|
|
return view('admin.maintenance.index', [
|
2019-12-10 04:26:30 +08:00
|
|
|
'cron_path' => $this->cronSvc->getCronExecString(),
|
2019-10-30 21:55:32 +08:00
|
|
|
'cron_problem_exists' => $this->cronSvc->cronProblemExists(),
|
|
|
|
]);
|
2019-08-31 03:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear caches depending on the type passed in
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
|
*/
|
|
|
|
public function cache(Request $request)
|
|
|
|
{
|
|
|
|
$calls = [];
|
|
|
|
$type = $request->get('type');
|
|
|
|
|
|
|
|
// When clearing the application, clear the config and the app itself
|
|
|
|
if ($type === 'application' || $type === 'all') {
|
|
|
|
$calls[] = 'config:cache';
|
|
|
|
$calls[] = 'cache:clear';
|
|
|
|
$calls[] = 'route:cache';
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we want to clear only the views but keep everything else
|
|
|
|
if ($type === 'views' || $type === 'all') {
|
|
|
|
$calls[] = 'view:clear';
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($calls as $call) {
|
|
|
|
Artisan::call($call);
|
|
|
|
}
|
|
|
|
|
|
|
|
Flash::success('Cache cleared!');
|
|
|
|
return redirect(route('admin.maintenance.index'));
|
|
|
|
}
|
|
|
|
}
|