mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
db in one refactor WIP3
This commit is contained in:
@@ -29,6 +29,7 @@ use App\StreamedOutput;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use LibreNMS\DB\Eloquent;
|
||||
use LibreNMS\DB\Schema;
|
||||
use LibreNMS\Interfaces\InstallerStep;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
@@ -39,7 +40,8 @@ class DatabaseController extends InstallationController implements InstallerStep
|
||||
public function index(Request $request)
|
||||
{
|
||||
$data = Arr::only(session()->get('db') ?: [], self::KEYS);
|
||||
$data['status'] = session('install.database');
|
||||
$data['valid_credentials'] = Eloquent::isConnected();
|
||||
$data['migrated'] = session('install.database');
|
||||
|
||||
return view('install.database', $this->formatData($data));
|
||||
}
|
||||
@@ -57,6 +59,7 @@ class DatabaseController extends InstallationController implements InstallerStep
|
||||
);
|
||||
|
||||
session()->put('db', Arr::only(config('database.connections.setup', []), self::KEYS));
|
||||
session()->forget('install.database'); // reset db complete status
|
||||
|
||||
$ok = false;
|
||||
$message = '';
|
||||
@@ -67,8 +70,6 @@ class DatabaseController extends InstallationController implements InstallerStep
|
||||
$message = $e->getMessage();
|
||||
}
|
||||
|
||||
session(['install.database' => $ok]);
|
||||
|
||||
return response()->json([
|
||||
'result' => $ok ? 'ok' : 'fail',
|
||||
'message' => $message,
|
||||
@@ -82,13 +83,12 @@ class DatabaseController extends InstallationController implements InstallerStep
|
||||
$this->configureDatabase();
|
||||
$output = new StreamedOutput(fopen('php://stdout', 'w'));
|
||||
echo "Starting Update...\n";
|
||||
$ret = \Artisan::call('migrate', ['--seed' => true, '--force' => true, '--database' => $this->connection], $output);
|
||||
$ret = \Artisan::call('migrate', ['--seed' => true, '--force' => true], $output);
|
||||
if ($ret !== 0) {
|
||||
throw new \RuntimeException('Migration failed');
|
||||
}
|
||||
echo "\n\nSuccess!";
|
||||
session(['install.migrate' => true]);
|
||||
session()->save();
|
||||
$this->markStepComplete('database');
|
||||
} catch (\Exception $e) {
|
||||
echo $e->getMessage() . "\n\nError!";
|
||||
}
|
||||
@@ -102,6 +102,16 @@ class DatabaseController extends InstallationController implements InstallerStep
|
||||
|
||||
public function complete(): bool
|
||||
{
|
||||
if (session('install.database')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->configureDatabase();
|
||||
if (Eloquent::isConnected() && Schema::isCurrent()) {
|
||||
$this->markStepComplete('database');
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -68,6 +68,7 @@ class InstallationController extends Controller
|
||||
final protected function markStepComplete($step)
|
||||
{
|
||||
session(["install.$step" => true]);
|
||||
session()->save();
|
||||
}
|
||||
|
||||
final protected function formatData($data = [])
|
||||
|
@@ -18,20 +18,19 @@ return [
|
||||
],
|
||||
'database' => [
|
||||
'title' => 'Configure Database',
|
||||
'status' => 'Status',
|
||||
'test' => 'Check Connection',
|
||||
'test' => 'Check Credentials',
|
||||
'host' => 'Host',
|
||||
'port' => 'Port',
|
||||
'socket' => 'Unix-Socket',
|
||||
'username' => 'User',
|
||||
'password' => 'Password',
|
||||
'name' => 'Database Name',
|
||||
'credentials' => 'Database Credentials',
|
||||
'socket_empty' => 'Leave empty if using Unix-Socket',
|
||||
'ip_empty' => 'Leave empty if using Host',
|
||||
],
|
||||
'migrate' => [
|
||||
'title' => 'Build Database',
|
||||
'building' => 'Building Database structure...',
|
||||
'migrate' => 'Build Database',
|
||||
'building_interrupt' => 'Do not close this page or interrupt the import!',
|
||||
'wait' => 'Please Wait...',
|
||||
'timeout' => 'HTTP request timed out, your database structure may be inconsistent.',
|
||||
|
@@ -5,6 +5,26 @@
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card mb-2">
|
||||
<div id="db-form-header"
|
||||
class="card-header h6"
|
||||
data-toggle="collapse"
|
||||
href="#db-form-container"
|
||||
aria-expanded="@if($valid_credentials) false @else true @endif"
|
||||
>
|
||||
<span id="database-status">
|
||||
@if($valid_credentials === null)
|
||||
<i class="fa fa-lg fa-question-circle text-muted"></i>
|
||||
@elseif($valid_credentials)
|
||||
<i class="fa fa-lg fa-check-circle text-success"></i>
|
||||
@else
|
||||
<i class="fa fa-lg fa-times-circle text-danger"></i>
|
||||
@endif
|
||||
</span>
|
||||
@lang('install.database.credentials')
|
||||
<i class="fa fa-lg fa-chevron-down rotate-if-collapsed fa-pull-right"></i>
|
||||
</div>
|
||||
<div id="db-form-container" class="card-body collapse @if(!$valid_credentials) show @endif">
|
||||
<form id="database-form" class="form-horizontal" role="form" method="post" action="{{ route('install.acton.test-database') }}">
|
||||
@csrf
|
||||
<div class="form-row pb-3">
|
||||
@@ -44,36 +64,51 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4 offset-1">
|
||||
<strong>@lang('install.database.status'):</strong>
|
||||
<span id="database-status" style="vertical-align: middle">
|
||||
@if($status === null)
|
||||
<i class="fa fa-2x fa-question-circle text-muted"></i>
|
||||
@elseif($status)
|
||||
<i class="fa fa-2x fa-check-circle text-success"></i>
|
||||
@else
|
||||
<i class="fa fa-2x fa-times-circle text-danger"></i>
|
||||
@endif
|
||||
</span>
|
||||
</div>
|
||||
<div class="col-7">
|
||||
<button type="submit" class="btn btn-success float-right">@lang('install.database.test')</button>
|
||||
<div class="col-12">
|
||||
<button type="submit" class="btn btn-primary float-right">@lang('install.database.test')</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div id="migration-output" class="row install-show-migrate">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" @if(!$valid_credentials) style="display: none" @endif>
|
||||
<div class="col-12">
|
||||
<label for="db-update">@lang('install.migrate.building')<br />@lang('install.migrate.building_interrupt')</label>
|
||||
<div class="card">
|
||||
<div id="db-form-header"
|
||||
class="card-header h6"
|
||||
data-toggle="collapse"
|
||||
href="#db-migration-container"
|
||||
aria-expanded="@if($migrated) false @else true @endif"
|
||||
>
|
||||
@if($migrated === null)
|
||||
<i class="fa fa-lg fa-question-circle text-muted"></i>
|
||||
@elseif($migrated)
|
||||
<i class="fa fa-lg fa-check-circle text-success"></i>
|
||||
@else
|
||||
<i class="fa fa-lg fa-times-circle text-danger"></i>
|
||||
@endif
|
||||
@lang('install.migrate.migrate')
|
||||
<i class="fa fa-lg fa-chevron-down rotate-if-collapsed fa-pull-right"></i>
|
||||
</div>
|
||||
<div id="db-migration-container" class="card-body collapse @if(!$migrated) show @endif">
|
||||
<div class="mb-2 text-right">
|
||||
<button type="button" id="retry-btn" onClick="alert('do something')" class="btn btn-primary">
|
||||
@lang('install.migrate.retry')
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary">
|
||||
@lang('install.migrate.migrate')
|
||||
</button>
|
||||
</div>
|
||||
<div class="alert alert-warning">@lang('install.migrate.building_interrupt')</div>
|
||||
<textarea readonly id="db-update" class="form-control" rows="20" placeholder="@lang('install.migrate.wait')"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<button type="button" id="retry-btn" onClick="window.location.reload()" class="btn btn-success pull-right">
|
||||
@lang('install.migrate.retry')
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -82,7 +117,7 @@
|
||||
<script>
|
||||
$('#database-form').submit(function (event) {
|
||||
event.preventDefault();
|
||||
$('#database-status>i').attr('class', 'fa fa-2x fa-spinner fa-spin');
|
||||
$('#database-status>i').attr('class', 'fa fa-lg fa-spinner fa-spin');
|
||||
$('#error-box').empty();
|
||||
|
||||
$.ajax({
|
||||
@@ -92,9 +127,11 @@
|
||||
data: $('#database-form').serialize(),
|
||||
success: function (response) {
|
||||
if (response.result === 'ok') {
|
||||
$('#database-status>i').attr('class', 'fa fa-2x fa-check-circle text-success');
|
||||
$('#database-status>i').attr('class', 'fa fa-lg fa-check-circle text-success');
|
||||
$('#migration-output').show();
|
||||
$('#db-form-container').collapse('hide')
|
||||
} else {
|
||||
$('#database-status>i').attr('class', 'fa fa-2x fa-times-circle text-danger')
|
||||
$('#database-status>i').attr('class', 'fa fa-lg fa-times-circle text-danger')
|
||||
if (response.message) {
|
||||
$('#error-box').append($('<div class="alert alert-danger">' + response.message + '</div>'))
|
||||
}
|
||||
@@ -136,17 +173,12 @@
|
||||
|
||||
@section('style')
|
||||
<style type="text/css">
|
||||
label[for=db-update] {
|
||||
font-size: large;
|
||||
}
|
||||
#db-update {
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
#retry-btn {
|
||||
display: none;
|
||||
}
|
||||
#migration-output {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
@endsection
|
||||
|
@@ -38,17 +38,3 @@
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('style')
|
||||
<style type="text/css">
|
||||
.rotate-if-collapsed {
|
||||
transition: .4s transform;
|
||||
}
|
||||
[data-toggle="collapse"] {
|
||||
cursor: pointer;
|
||||
}
|
||||
[data-toggle="collapse"][aria-expanded="true"] > .rotate-if-collapsed {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
</style>
|
||||
@endsection
|
||||
|
@@ -68,6 +68,16 @@
|
||||
#step-title {
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
.rotate-if-collapsed {
|
||||
transition: .4s transform ease-in-out;
|
||||
}
|
||||
[data-toggle="collapse"] {
|
||||
cursor: pointer;
|
||||
}
|
||||
[data-toggle="collapse"][aria-expanded="true"] .rotate-if-collapsed {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
</style>
|
||||
@yield('style')
|
||||
</head>
|
||||
@@ -118,10 +128,8 @@
|
||||
Object.keys(data).forEach(function (key) {
|
||||
if (data[key]) {
|
||||
$('.install-enable-' + key).removeClass('disabled');
|
||||
$('.install-show-' + key).show();
|
||||
} else {
|
||||
$('.install-enable-' + key).addClass('disabled');
|
||||
$('.install-show-' + key).hide();
|
||||
}
|
||||
});
|
||||
})
|
||||
|
Reference in New Issue
Block a user