2019-08-31 03:59:08 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Contracts\Controller;
|
2020-02-11 01:39:59 +08:00
|
|
|
use App\Repositories\KvpRepository;
|
2019-10-30 21:55:32 +08:00
|
|
|
use App\Services\CronService;
|
2020-02-11 06:47:46 +08:00
|
|
|
use App\Services\VersionService;
|
2021-03-10 00:36:56 +08:00
|
|
|
use App\Support\Utils;
|
2019-08-31 03:59:08 +08:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Artisan;
|
2020-02-11 01:39:59 +08:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2019-08-31 03:59:08 +08:00
|
|
|
use Laracasts\Flash\Flash;
|
|
|
|
|
|
|
|
class MaintenanceController extends Controller
|
|
|
|
{
|
2019-10-30 21:55:32 +08:00
|
|
|
private $cronSvc;
|
2020-02-11 01:39:59 +08:00
|
|
|
private $kvpRepo;
|
2020-02-11 06:47:46 +08:00
|
|
|
private $versionSvc;
|
2019-10-30 21:55:32 +08:00
|
|
|
|
2020-02-11 01:39:59 +08:00
|
|
|
public function __construct(
|
|
|
|
CronService $cronSvc,
|
|
|
|
KvpRepository $kvpRepo,
|
2020-02-11 06:47:46 +08:00
|
|
|
VersionService $versionSvc
|
2020-02-11 01:39:59 +08:00
|
|
|
) {
|
2019-10-30 21:55:32 +08:00
|
|
|
$this->cronSvc = $cronSvc;
|
2020-02-11 01:39:59 +08:00
|
|
|
$this->kvpRepo = $kvpRepo;
|
2020-02-11 06:47:46 +08:00
|
|
|
$this->versionSvc = $versionSvc;
|
2019-08-31 03:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
{
|
2021-03-10 00:36:56 +08:00
|
|
|
// Get the cron URL
|
|
|
|
$cron_id = setting('cron.random_id');
|
|
|
|
$cron_url = empty($cron_id) ? 'Not enabled' : url(route('api.maintenance.cron', $cron_id));
|
|
|
|
|
2019-10-30 21:55:32 +08:00
|
|
|
return view('admin.maintenance.index', [
|
2021-03-10 00:36:56 +08:00
|
|
|
'cron_url' => $cron_url,
|
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(),
|
2020-05-21 23:06:27 +08:00
|
|
|
'new_version' => $this->kvpRepo->get('new_version_available', false),
|
2020-02-11 01:39:59 +08:00
|
|
|
'new_version_tag' => $this->kvpRepo->get('latest_version_tag'),
|
2019-10-30 21:55:32 +08:00
|
|
|
]);
|
2019-08-31 03:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear caches depending on the type passed in
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
2020-02-11 01:39:59 +08:00
|
|
|
* @return mixed
|
2019-08-31 03:59:08 +08:00
|
|
|
*/
|
|
|
|
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';
|
2020-01-31 03:59:48 +08:00
|
|
|
$calls[] = 'clear-compiled';
|
2019-08-31 03:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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'));
|
|
|
|
}
|
2020-02-11 01:39:59 +08:00
|
|
|
|
|
|
|
/**
|
2020-02-11 06:47:46 +08:00
|
|
|
* Force an update check
|
2020-02-11 01:39:59 +08:00
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2020-02-11 06:47:46 +08:00
|
|
|
public function forcecheck(Request $request)
|
2020-02-11 01:39:59 +08:00
|
|
|
{
|
2020-02-11 06:47:46 +08:00
|
|
|
$this->versionSvc->isNewVersionAvailable();
|
|
|
|
|
2020-02-11 01:39:59 +08:00
|
|
|
$new_version_avail = $this->kvpRepo->get('new_version_available', false);
|
2020-02-11 06:47:46 +08:00
|
|
|
$new_version_tag = $this->kvpRepo->get('latest_version_tag');
|
|
|
|
|
|
|
|
Log::info('Force check, available='.$new_version_avail.', tag='.$new_version_tag);
|
|
|
|
|
2020-02-11 01:39:59 +08:00
|
|
|
if (!$new_version_avail) {
|
2020-02-11 06:47:46 +08:00
|
|
|
Flash::success('No new version available');
|
|
|
|
} else {
|
|
|
|
Flash::success('New version available: '.$new_version_tag);
|
2020-02-11 01:39:59 +08:00
|
|
|
}
|
|
|
|
|
2020-02-11 06:47:46 +08:00
|
|
|
return redirect(route('admin.maintenance.index'));
|
|
|
|
}
|
|
|
|
|
2021-03-10 00:36:56 +08:00
|
|
|
/**
|
|
|
|
* Enable the cron, or if it's enabled, change the ID that is used
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
*/
|
|
|
|
public function cron_enable(Request $request)
|
|
|
|
{
|
|
|
|
$id = Utils::generateNewId(24);
|
|
|
|
setting_save('cron.random_id', $id);
|
|
|
|
|
|
|
|
Flash::success('Web cron refreshed!');
|
|
|
|
return redirect(route('admin.maintenance.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable the web cron
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function cron_disable(Request $request)
|
|
|
|
{
|
|
|
|
setting_save('cron.random_id', '');
|
|
|
|
|
|
|
|
Flash::success('Web cron disabled!');
|
|
|
|
return redirect(route('admin.maintenance.index'));
|
|
|
|
}
|
2019-08-31 03:59:08 +08:00
|
|
|
}
|