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