Consolidate DB version code (#13111)

* Consilidate DB version
and don't use dbConnected() function

* cleanup imports
This commit is contained in:
Tony Murray
2021-08-09 18:33:31 -05:00
committed by GitHub
parent 2b8eb74b7a
commit 5d691dc375
4 changed files with 10 additions and 4 deletions

View File

@@ -28,6 +28,7 @@ use Dotenv\Dotenv;
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Events\StatementPrepared;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Arr;
use LibreNMS\Util\Laravel;
class Eloquent
@@ -144,4 +145,9 @@ class Eloquent
]);
\Config::set('database.default', $name);
}
public static function version($name = null)
{
return Arr::first(self::DB($name)->selectOne('select version()'));
}
}

View File

@@ -99,7 +99,7 @@ class Database extends BaseValidation
private function checkVersion(Validator $validator)
{
$version = Eloquent::DB()->selectOne('SELECT VERSION() as version')->version;
$version = Eloquent::version();
$version = explode('-', $version);
if (isset($version[1]) && $version[1] == 'MariaDB') {

View File

@@ -49,9 +49,9 @@ use App\Models\Syslog;
use App\Models\Vlan;
use App\Models\Vrf;
use App\Models\WirelessSensor;
use DB;
use Illuminate\Http\Request;
use LibreNMS\Config;
use LibreNMS\DB\Eloquent;
use LibreNMS\Util\Version;
class AboutController extends Controller
@@ -71,7 +71,7 @@ class AboutController extends Controller
'project_name' => Config::get('project_name'),
'version_local' => $version->local(),
'version_mysql' => current(DB::selectOne('select version()')),
'version_mysql' => Eloquent::version(),
'version_php' => phpversion(),
'version_laravel' => App::VERSION(),
'version_python' => Version::python(),

View File

@@ -656,7 +656,7 @@ function version_info($remote = false)
$output['db_schema'] = vsprintf('%s (%s)', $version->database());
$output['php_ver'] = phpversion();
$output['python_ver'] = \LibreNMS\Util\Version::python();
$output['mysql_ver'] = dbIsConnected() ? dbFetchCell('SELECT version()') : '?';
$output['mysql_ver'] = \LibreNMS\DB\Eloquent::isConnected() ? \LibreNMS\DB\Eloquent::version() : '?';
$output['rrdtool_ver'] = str_replace('1.7.01.7.0', '1.7.0', implode(' ', array_slice(explode(' ', shell_exec(
Config::get('rrdtool', 'rrdtool') . ' --version |head -n1'
)), 1, 1)));