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 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 . + */ + + +$(function () { + "use strict"; + //var status = $('#status-box'); + // set HTML to "migrating...": + startMigration(); +}); + +function startMigration() { + $('#status-box').html(' Setting up DB...'); + $.post(migrateUri, {_token: token}).done(function () { + startPassport(); + }).fail(function () { + $('#status-box').html(' Migration failed! See log files :('); + }); +} + +/** + * + */ +function startPassport() { + $('#status-box').html(' Setting up OAuth2...'); + $.post(keysUri, {_token: token}).done(function () { + startUpgrade(); + }).fail(function () { + $('#status-box').html(' OAuth2 failed! See log files :('); + }); +} + +/** + * + */ +function startUpgrade() { + $('#status-box').html(' Upgrading database...'); + $.post(upgradeUri, {_token: token}).done(function () { + completeDone(); + }).fail(function () { + $('#status-box').html(' Upgrade failed! See log files :('); + }); +} + +/** + * + */ +function completeDone() { + $('#status-box').html(' 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 @@
-
- Hello +
+
+ Waiting to start... +
{% endblock %} +{% block scripts %} + + +{% 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 @@ Firefly III - Installation and update + @@ -29,5 +30,6 @@ {% block content %}{% endblock %}
+{% block scripts %}{% endblock %} 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']); } );