mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-19 11:14:06 +00:00
Improve installed database detection
This commit is contained in:
@@ -6,6 +6,7 @@ use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
use InvoiceShelf\Models\CompanySetting;
|
||||
use InvoiceShelf\Models\RecurringInvoice;
|
||||
use InvoiceShelf\Space\InstallUtils;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
@@ -28,7 +29,7 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
if (\Storage::disk('local')->has('database_created')) {
|
||||
if (InstallUtils::isDbCreated()) {
|
||||
$schedule->command('check:invoices:status')
|
||||
->daily();
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace InvoiceShelf\Http\Controllers\V1\Installation;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use InvoiceShelf\Http\Controllers\Controller;
|
||||
use InvoiceShelf\Space\InstallUtils;
|
||||
|
||||
class FinishController extends Controller
|
||||
{
|
||||
@@ -14,7 +15,7 @@ class FinishController extends Controller
|
||||
*/
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
\Storage::disk('local')->put('database_created', 'database_created');
|
||||
InstallUtils::createDbMarker();
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
}
|
||||
|
||||
@@ -5,17 +5,18 @@ namespace InvoiceShelf\Http\Controllers\V1\Installation;
|
||||
use Illuminate\Http\Request;
|
||||
use InvoiceShelf\Http\Controllers\Controller;
|
||||
use InvoiceShelf\Models\Setting;
|
||||
use InvoiceShelf\Space\InstallUtils;
|
||||
|
||||
class OnboardingWizardController extends Controller
|
||||
{
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getStep(Request $request)
|
||||
{
|
||||
if (! \Storage::disk('local')->has('database_created')) {
|
||||
if (! InstallUtils::dbMarkerExists()) {
|
||||
return response()->json([
|
||||
'profile_complete' => 0,
|
||||
]);
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace InvoiceShelf\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use InvoiceShelf\Models\FileDisk;
|
||||
use InvoiceShelf\Space\InstallUtils;
|
||||
|
||||
class ConfigMiddleware
|
||||
{
|
||||
@@ -15,7 +16,7 @@ class ConfigMiddleware
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (\Storage::disk('local')->has('database_created')) {
|
||||
if (InstallUtils::isDbCreated()) {
|
||||
if ($request->has('file_disk_id')) {
|
||||
$file_disk = FileDisk::find($request->file_disk_id);
|
||||
} else {
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace InvoiceShelf\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use InvoiceShelf\Models\Setting;
|
||||
use InvoiceShelf\Space\InstallUtils;
|
||||
|
||||
class InstallationMiddleware
|
||||
{
|
||||
@@ -15,14 +16,12 @@ class InstallationMiddleware
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (! \Storage::disk('local')->has('database_created')) {
|
||||
return redirect('/installation');
|
||||
}
|
||||
|
||||
if (\Storage::disk('local')->has('database_created')) {
|
||||
if (Setting::getSetting('profile_complete') !== 'COMPLETED') {
|
||||
return redirect('/installation');
|
||||
if (! InstallUtils::isDbCreated() || Setting::getSetting('profile_complete') !== 'COMPLETED') {
|
||||
if (InstallUtils::dbMarkerExists()) {
|
||||
InstallUtils::deleteDbMarker();
|
||||
}
|
||||
|
||||
return redirect('/installation');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace InvoiceShelf\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use InvoiceShelf\Models\Setting;
|
||||
use InvoiceShelf\Space\InstallUtils;
|
||||
|
||||
class RedirectIfInstalled
|
||||
{
|
||||
@@ -15,7 +16,7 @@ class RedirectIfInstalled
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (\Storage::disk('local')->has('database_created')) {
|
||||
if (InstallUtils::dbMarkerExists()) {
|
||||
if (Setting::getSetting('profile_complete') === 'COMPLETED') {
|
||||
return redirect('login');
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
namespace InvoiceShelf\Providers;
|
||||
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use InvoiceShelf\Space\InstallUtils;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -18,7 +18,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
Paginator::useBootstrapThree();
|
||||
$this->loadJsonTranslationsFrom(resource_path('scripts/locales'));
|
||||
|
||||
if (\Storage::disk('local')->has('database_created') && Schema::hasTable('abilities')) {
|
||||
if (InstallUtils::isDbCreated()) {
|
||||
$this->addMenus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace InvoiceShelf\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Schema;
|
||||
|
||||
class ViewServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -25,12 +24,10 @@ class ViewServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
if (\Storage::disk('local')->has('database_created') && Schema::hasTable('settings')) {
|
||||
View::share('login_page_logo', get_app_setting('login_page_logo'));
|
||||
View::share('login_page_heading', get_app_setting('login_page_heading'));
|
||||
View::share('login_page_description', get_app_setting('login_page_description'));
|
||||
View::share('admin_page_title', get_app_setting('admin_page_title'));
|
||||
View::share('copyright_text', get_app_setting('copyright_text'));
|
||||
}
|
||||
View::share('login_page_logo', get_app_setting('login_page_logo'));
|
||||
View::share('login_page_heading', get_app_setting('login_page_heading'));
|
||||
View::share('login_page_description', get_app_setting('login_page_description'));
|
||||
View::share('admin_page_title', get_app_setting('admin_page_title'));
|
||||
View::share('copyright_text', get_app_setting('copyright_text'));
|
||||
}
|
||||
}
|
||||
|
||||
86
app/Space/InstallUtils.php
Normal file
86
app/Space/InstallUtils.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace InvoiceShelf\Space;
|
||||
|
||||
use League\Flysystem\FilesystemException;
|
||||
|
||||
class InstallUtils
|
||||
{
|
||||
/**
|
||||
* Check if database is created
|
||||
*
|
||||
* @return bool|int|string
|
||||
*/
|
||||
public static function isDbCreated()
|
||||
{
|
||||
return self::tableExists('users');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if database is created
|
||||
*
|
||||
* @return bool|int|string
|
||||
*/
|
||||
public static function tableExists($table)
|
||||
{
|
||||
static $cache = [];
|
||||
|
||||
if (isset($cache[$table])) {
|
||||
return $cache[$table];
|
||||
}
|
||||
|
||||
try {
|
||||
$flag = self::dbMarkerExists();
|
||||
if ($flag) {
|
||||
$flag &= \Schema::hasTable($table);
|
||||
}
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
$flag = false;
|
||||
} catch (\Exception $e) {
|
||||
$flag = false;
|
||||
}
|
||||
|
||||
$cache[$table] = $flag;
|
||||
|
||||
return $flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if database created marker exists
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function dbMarkerExists()
|
||||
{
|
||||
try {
|
||||
$flag = \Storage::disk('local')->has('database_created');
|
||||
} catch (FilesystemException $e) {
|
||||
$flag = false;
|
||||
}
|
||||
|
||||
return $flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the database marker
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function createDbMarker()
|
||||
{
|
||||
\Storage::disk('local')->put('database_created', 'database_created');
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the database marker
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function deleteDbMarker()
|
||||
{
|
||||
try {
|
||||
\Storage::disk('local')->delete('database_created');
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ use InvoiceShelf\Models\CompanySetting;
|
||||
use InvoiceShelf\Models\Currency;
|
||||
use InvoiceShelf\Models\CustomField;
|
||||
use InvoiceShelf\Models\Setting;
|
||||
use InvoiceShelf\Space\InstallUtils;
|
||||
|
||||
/**
|
||||
* Get company setting
|
||||
@@ -13,9 +14,11 @@ use InvoiceShelf\Models\Setting;
|
||||
*/
|
||||
function get_company_setting($key, $company_id)
|
||||
{
|
||||
if (\Storage::disk('local')->has('database_created')) {
|
||||
return CompanySetting::getSetting($key, $company_id);
|
||||
if (! InstallUtils::isDbCreated()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return CompanySetting::getSetting($key, $company_id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,9 +29,11 @@ function get_company_setting($key, $company_id)
|
||||
*/
|
||||
function get_app_setting($key)
|
||||
{
|
||||
if (\Storage::disk('local')->has('database_created')) {
|
||||
return Setting::getSetting($key);
|
||||
if (! InstallUtils::isDbCreated()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Setting::getSetting($key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,22 +43,23 @@ function get_app_setting($key)
|
||||
*/
|
||||
function get_page_title($company_id)
|
||||
{
|
||||
if (! InstallUtils::isDbCreated()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$routeName = Route::currentRouteName();
|
||||
|
||||
$pageTitle = null;
|
||||
$defaultPageTitle = 'InvoiceShelf - Self Hosted Invoicing Platform';
|
||||
|
||||
if (\Storage::disk('local')->has('database_created')) {
|
||||
if ($routeName === 'customer.dashboard') {
|
||||
$pageTitle = CompanySetting::getSetting('customer_portal_page_title', $company_id);
|
||||
|
||||
return $pageTitle ? $pageTitle : $defaultPageTitle;
|
||||
}
|
||||
|
||||
$pageTitle = Setting::getSetting('admin_page_title');
|
||||
if ($routeName === 'customer.dashboard') {
|
||||
$pageTitle = CompanySetting::getSetting('customer_portal_page_title', $company_id);
|
||||
|
||||
return $pageTitle ? $pageTitle : $defaultPageTitle;
|
||||
}
|
||||
|
||||
$pageTitle = Setting::getSetting('admin_page_title');
|
||||
|
||||
return $pageTitle ? $pageTitle : $defaultPageTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user