1 <?php namespace BookStack\Http\Controllers;
3 use Illuminate\Support\Facades\Cache;
4 use Illuminate\Support\Facades\DB;
5 use Illuminate\Support\Facades\Session;
6 use Illuminate\Support\Str;
8 class StatusController extends Controller
12 * Show the system status as a simple json page.
14 public function show()
17 'database' => $this->trueWithoutError(function () {
18 return DB::table('migrations')->count() > 0;
20 'cache' => $this->trueWithoutError(function () {
21 $rand = Str::random();
22 Cache::set('status_test', $rand);
23 return Cache::get('status_test') === $rand;
25 'session' => $this->trueWithoutError(function () {
26 $rand = Str::random();
27 Session::put('status_test', $rand);
28 return Session::get('status_test') === $rand;
32 $hasError = in_array(false, $statuses);
33 return response()->json($statuses, $hasError ? 500 : 200);
37 * Check the callable passed returns true and does not throw an exception.
39 protected function trueWithoutError(callable $test): bool
42 return $test() === true;
43 } catch (\Exception $e) {