3 namespace BookStack\Settings;
5 use BookStack\Http\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(12);
24 $key = "status_test_{$rand}";
25 Cache::add($key, $rand);
27 return Cache::pull($key) === $rand;
29 'session' => $this->trueWithoutError(function () {
30 $rand = Str::random();
31 Session::put('status_test', $rand);
33 return Session::get('status_test') === $rand;
37 $hasError = in_array(false, $statuses);
39 return response()->json($statuses, $hasError ? 500 : 200);
43 * Check the callable passed returns true and does not throw an exception.
45 protected function trueWithoutError(callable $test): bool
48 return $test() === true;
49 } catch (\Exception $e) {