Skip to content

Firefly III: a personal finances manager

Expand install routine.

James Cole648a6dca422f
diff --git a/app/Http/Controllers/System/InstallController.php b/app/Http/Controllers/System/InstallController.php
index a21b0bc325..cd87548876 100644
--- a/app/Http/Controllers/System/InstallController.php
+++ b/app/Http/Controllers/System/InstallController.php
@@ -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']);
}
}
\ No newline at end of file
diff --git a/app/Http/Middleware/Installer.php b/app/Http/Middleware/Installer.php
index 43e38ba37c..d707f6872a 100644
--- a/app/Http/Middleware/Installer.php
+++ b/app/Http/Middleware/Installer.php
@@ -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);
}
diff --git a/public/js/ff/install/index.js b/public/js/ff/install/index.js
new file mode 100644
index 0000000000..22b8575918
--- /dev/null
+++ b/public/js/ff/install/index.js
@@ -0,0 +1,70 @@
+/*
+ * index.js
+ * Copyright (c) 2018 [email protected]
+ *
+ * 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);
+}
\ No newline at end of file
diff --git a/resources/views/install/index.twig b/resources/views/install/index.twig
index 7c36df9e57..e913abb5d8 100644
--- a/resources/views/install/index.twig
+++ b/resources/views/install/index.twig
@@ -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 %}
diff --git a/resources/views/layout/install.twig b/resources/views/layout/install.twig
index 3d354801ac..ede966473e 100644
--- a/resources/views/layout/install.twig
+++ b/resources/views/layout/install.twig
@@ -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>
diff --git a/routes/web.php b/routes/web.php
index 423d9d886e..23e38b188d 100755
--- a/routes/web.php
+++ b/routes/web.php
@@ -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']);
}
);