3 namespace BookStack\Settings;
5 use BookStack\Http\Controllers\Controller;
6 use Illuminate\Support\Facades\Cache;
7 use Illuminate\Support\Facades\DB;
8 use Illuminate\Support\Facades\Session;
9 use Illuminate\Support\Str;
11 class StatusController extends Controller
14 * Show the system status as a simple json page.
16 public function show()
19 'database' => $this->trueWithoutError(function () {
20 return DB::table('migrations')->count() > 0;
22 'cache' => $this->trueWithoutError(function () {
23 $rand = Str::random();
24 Cache::add('status_test', $rand);
26 return Cache::pull('status_test') === $rand;
28 'session' => $this->trueWithoutError(function () {
29 $rand = Str::random();
30 Session::put('status_test', $rand);
32 return Session::get('status_test') === $rand;
36 $hasError = in_array(false, $statuses);
38 return response()->json($statuses, $hasError ? 500 : 200);
42 * Check the callable passed returns true and does not throw an exception.
44 protected function trueWithoutError(callable $test): bool
47 return $test() === true;
48 } catch (\Exception $e) {