1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 08:51:34 +02:00
invoiceninja/app/Utils/SystemHealth.php

99 lines
2.4 KiB
PHP
Raw Normal View History

2019-07-05 00:36:40 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
2019-07-05 00:36:40 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Utils;
use App\Libraries\MultiDB;
use Illuminate\Support\Facades\DB;
/**
* Class SystemHealth.
*/
class SystemHealth
{
private static $extensions = [
'mysqli',
'gd',
'curl',
'zip',
'gmp'
];
2019-07-05 00:36:40 +02:00
2019-07-09 11:13:33 +02:00
private static $php_version = 7.3;
2019-07-05 00:36:40 +02:00
/**
* Check loaded extensions / PHP version / DB Connections
*
* @return array Result set of checks
*/
public static function check() : array
{
$system_health = true;
2019-07-05 00:36:40 +02:00
if (in_array(false, self::extensions())) {
$system_health = false;
} elseif (phpversion() < self::$php_version) {
$system_health = false;
}
2019-07-05 00:36:40 +02:00
return [
'system_health' => $system_health,
'extensions' => self::extensions(),
'php_version' => phpversion(),
'min_php_version' => self::$php_version,
'dbs' => self::dbCheck(),
];
}
2019-07-05 00:36:40 +02:00
private static function extensions() :array
{
$loaded_extensions = [];
2019-07-05 00:36:40 +02:00
foreach (self::$extensions as $extension) {
$loaded_extensions[] = [$extension => extension_loaded($extension)];
}
2019-07-05 00:36:40 +02:00
return $loaded_extensions;
}
2019-07-05 00:36:40 +02:00
private static function dbCheck() :array
{
$result = [];
2019-07-05 00:36:40 +02:00
if (! config('ninja.db.multi_db_enabled')) {
2019-07-05 00:36:40 +02:00
$pdo = DB::connection()->getPdo();
if ($pdo) {
$result[] = [ DB::connection()->getDatabaseName() => true ];
} else {
$result[] = [ config('database.connections.' . config('database.default') . '.database') => false ];
}
} else {
foreach (MultiDB::$dbs as $db) {
2019-07-05 00:36:40 +02:00
MultiDB::setDB($db);
$pdo = DB::connection()->getPdo();
2019-07-05 00:36:40 +02:00
if ($pdo) {
$result[] = [ DB::connection()->getDatabaseName() => true ];
} else {
$result[] = [ config('database.connections.' . config('database.default') . '.database') => false ];
}
2019-07-05 00:36:40 +02:00
}
}
return $result;
}
2019-07-05 00:36:40 +02:00
}