Expand install routine.

This commit is contained in:
James Cole 2018-03-10 07:17:05 +01:00
parent 0566d0d198
commit 648a6dca42
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
6 changed files with 125 additions and 16 deletions

View File

@ -29,7 +29,6 @@ use FireflyIII\Http\Controllers\Controller;
use Laravel\Passport\Passport;
use Log;
use phpseclib\Crypt\RSA;
use Symfony\Component\Console\Output\BufferedOutput;
/**
* Class InstallController
@ -47,15 +46,16 @@ class InstallController extends Controller
/**
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function migrate()
public function index()
{
Log::debug('Am now calling migrate routine...');
$output = new BufferedOutput();
Artisan::call('migrate', ['--seed' => true, '--force' => true]);
$result = $output->fetch();
Log::debug($result);
Log::debug(Artisan::output());
return view('install.index');
}
/**
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function keys()
{
// create keys manually because for some reason the passport namespace
// does not exist
$rsa = new RSA();
@ -67,13 +67,37 @@ class InstallController extends Controller
];
if ((file_exists($publicKey) || file_exists($privateKey))) {
return redirect(route('index'));
return response()->json(['OK']);
}
file_put_contents($publicKey, array_get($keys, 'publickey'));
file_put_contents($privateKey, array_get($keys, 'privatekey'));
return redirect(route('index'));
return response()->json(['OK']);
}
/**
* @return \Illuminate\Http\JsonResponse
*/
public function migrate()
{
Log::debug('Am now calling migrate routine...');
Artisan::call('migrate', ['--seed' => true, '--force' => true]);
Log::debug(Artisan::output());
return response()->json(['OK']);
}
/**
* @return \Illuminate\Http\JsonResponse
*/
public function upgrade()
{
Log::debug('Am now calling upgrade database routine...');
Artisan::call('firefly:upgrade-database');
Log::debug(Artisan::output());
return response()->json(['OK']);
}
}

View File

@ -50,7 +50,7 @@ class Installer
// redirect to UpdateController
Log::warning('There are no Firefly III tables present. Redirect to migrate routine.');
return response()->redirectTo(route('installer.migrate'));
return response()->redirectTo(route('installer.index'));
}
throw new FireflyException(sprintf('Could not access the database: %s', $message));
}
@ -64,7 +64,7 @@ class Installer
));
// redirect to migrate routine:
return response()->redirectTo(route('installer.migrate'));
return response()->redirectTo(route('installer.index'));
}
return $next($request);
}

70
public/js/ff/install/index.js vendored Normal file
View File

@ -0,0 +1,70 @@
/*
* index.js
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
$(function () {
"use strict";
//var status = $('#status-box');
// set HTML to "migrating...":
startMigration();
});
function startMigration() {
$('#status-box').html('<i class="fa fa-spin fa-spinner"></i> Setting up DB...');
$.post(migrateUri, {_token: token}).done(function () {
startPassport();
}).fail(function () {
$('#status-box').html('<i class="fa fa-warning"></i> Migration failed! See log files :(');
});
}
/**
*
*/
function startPassport() {
$('#status-box').html('<i class="fa fa-spin fa-spinner"></i> Setting up OAuth2...');
$.post(keysUri, {_token: token}).done(function () {
startUpgrade();
}).fail(function () {
$('#status-box').html('<i class="fa fa-warning"></i> OAuth2 failed! See log files :(');
});
}
/**
*
*/
function startUpgrade() {
$('#status-box').html('<i class="fa fa-spin fa-spinner"></i> Upgrading database...');
$.post(upgradeUri, {_token: token}).done(function () {
completeDone();
}).fail(function () {
$('#status-box').html('<i class="fa fa-warning"></i> Upgrade failed! See log files :(');
});
}
/**
*
*/
function completeDone() {
$('#status-box').html('<i class="fa fa-thumbs-up"></i> Installation complete! Wait to be redirected...');
setTimeout(function () {
window.location = homeUri;
}, 3000);
}

View File

@ -4,10 +4,22 @@
<div class="login-box-body">
<p class="login-box-msg">Please wait...</p>
<div class="row">
<div class="col-xs-8">
Hello
<div class="col-lg-12">
<div id="status-box" style="border:1px #ddd solid;padding:5px;">
<i class="fa fa-spin fa-spinner"></i> Waiting to start...
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script type="text/javascript">
var token = '{{ csrf_token() }}';
var migrateUri = '{{ route('installer.migrate') }}';
var keysUri = '{{ route('installer.keys') }}';
var upgradeUri = '{{ route('installer.upgrade') }}';
var homeUri = '{{ route('home') }}';
</script>
<script type="text/javascript" src="js/ff/install/index.js"></script>
{% endblock %}

View File

@ -6,6 +6,7 @@
<meta name="robots" content="noindex, nofollow, noarchive, noodp, NoImageIndex, noydir">
<title>Firefly III - Installation and update</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<link href="css/app.css?v={{ FF_VERSION }}" rel="stylesheet" type="text/css"/>
<link href="lib/adminlte/css/AdminLTE.min.css?v={{ FF_VERSION }}" rel="stylesheet" type="text/css"/>
@ -29,5 +30,6 @@
{% block content %}{% endblock %}
</div>
<script src="js/app.js?v={{ FF_VERSION }}" type="text/javascript"></script>
{% block scripts %}{% endblock %}
</body>
</html>

View File

@ -26,8 +26,9 @@ Route::group(
['namespace' => 'FireflyIII\Http\Controllers\System',
'as' => 'installer.', 'prefix' => 'install'], function () {
Route::get('', ['uses' => 'InstallController@index', 'as' => 'index']);
Route::get('migrate', ['uses' => 'InstallController@migrate', 'as' => 'migrate']);
Route::post('migrate', ['uses' => 'InstallController@migrate', 'as' => 'migrate']);
Route::post('keys', ['uses' => 'InstallController@keys', 'as' => 'keys']);
Route::post('upgrade', ['uses' => 'InstallController@upgrade', 'as' => 'upgrade']);
}
);