diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 8c268535fa..4ffa5f6240 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers; use Carbon\Carbon; +use Carbon\Exceptions\InvalidFormatException; use Exception; use FireflyIII\Events\RequestedVersionCheckStatus; use FireflyIII\Exceptions\FireflyException; @@ -66,12 +67,24 @@ class HomeController extends Controller */ public function dateRange(Request $request): JsonResponse { - $start = new Carbon($request->get('start')); - $end = new Carbon($request->get('end')); + try { + $stringStart = e((string)$request->get('start')); + $start = Carbon::createFromFormat('Y-m-d', $stringStart); + } catch (InvalidFormatException $e) { + Log::error(sprintf('Start: could not parse date string "%s" so ignore it.', $stringStart)); + $start = Carbon::now()->startOfMonth(); + } + try { + $stringEnd = e((string)$request->get('end')); + $end = Carbon::createFromFormat('Y-m-d', $stringEnd); + } catch (InvalidFormatException $e) { + Log::error(sprintf('End could not parse date string "%s" so ignore it.', $stringEnd)); + $end = Carbon::now()->endOfMonth(); + } $label = $request->get('label'); $isCustomRange = false; - Log::debug('Received dateRange', ['start' => $request->get('start'), 'end' => $request->get('end'), 'label' => $request->get('label')]); + Log::debug('Received dateRange', ['start' => $stringStart, 'end' => $stringEnd, 'label' => $request->get('label')]); // check if the label is "everything" or "Custom range" which will betray // a possible problem with the budgets. if ($label === (string)trans('firefly.everything') || $label === (string)trans('firefly.customRange')) { diff --git a/database/migrations/2016_06_16_000000_create_support_tables.php b/database/migrations/2016_06_16_000000_create_support_tables.php index 65925899dc..18c6be1856 100644 --- a/database/migrations/2016_06_16_000000_create_support_tables.php +++ b/database/migrations/2016_06_16_000000_create_support_tables.php @@ -84,6 +84,22 @@ class CreateSupportTables extends Migration } } + private function createConfigurationTable(): void + { + if (!Schema::hasTable('configuration')) { + Schema::create( + 'configuration', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->string('name', 50); + $table->text('data'); + } + ); + } + } + private function createCurrencyTable(): void { if (!Schema::hasTable('transaction_currencies')) { @@ -104,24 +120,6 @@ class CreateSupportTables extends Migration } } - private function createTransactionTypeTable(): void - { - if (!Schema::hasTable('transaction_types')) { - Schema::create( - 'transaction_types', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->string('type', 50); - - // type must be unique. - $table->unique(['type']); - } - ); - } - } - private function createJobsTable(): void { if (!Schema::hasTable('jobs')) { @@ -158,6 +156,24 @@ class CreateSupportTables extends Migration } } + private function createPermissionRoleTable(): void + { + if (!Schema::hasTable('permission_role')) { + Schema::create( + 'permission_role', + static function (Blueprint $table) { + $table->integer('permission_id')->unsigned(); + $table->integer('role_id')->unsigned(); + + $table->foreign('permission_id')->references('id')->on('permissions')->onUpdate('cascade')->onDelete('cascade'); + $table->foreign('role_id')->references('id')->on('roles')->onUpdate('cascade')->onDelete('cascade'); + + $table->primary(['permission_id', 'role_id']); + } + ); + } + } + private function createPermissionsTable(): void { if (!Schema::hasTable('permissions')) { @@ -190,24 +206,6 @@ class CreateSupportTables extends Migration } } - private function createPermissionRoleTable(): void - { - if (!Schema::hasTable('permission_role')) { - Schema::create( - 'permission_role', - static function (Blueprint $table) { - $table->integer('permission_id')->unsigned(); - $table->integer('role_id')->unsigned(); - - $table->foreign('permission_id')->references('id')->on('permissions')->onUpdate('cascade')->onDelete('cascade'); - $table->foreign('role_id')->references('id')->on('roles')->onUpdate('cascade')->onDelete('cascade'); - - $table->primary(['permission_id', 'role_id']); - } - ); - } - } - private function createSessionsTable(): void { if (!Schema::hasTable('sessions')) { @@ -225,17 +223,19 @@ class CreateSupportTables extends Migration } } - private function createConfigurationTable(): void + private function createTransactionTypeTable(): void { - if (!Schema::hasTable('configuration')) { + if (!Schema::hasTable('transaction_types')) { Schema::create( - 'configuration', + 'transaction_types', static function (Blueprint $table) { $table->increments('id'); $table->timestamps(); $table->softDeletes(); - $table->string('name', 50); - $table->text('data'); + $table->string('type', 50); + + // type must be unique. + $table->unique(['type']); } ); } diff --git a/database/migrations/2016_06_16_000002_create_main_tables.php b/database/migrations/2016_06_16_000002_create_main_tables.php index 7f364d2cf8..ba70a57a08 100644 --- a/database/migrations/2016_06_16_000002_create_main_tables.php +++ b/database/migrations/2016_06_16_000002_create_main_tables.php @@ -124,44 +124,6 @@ class CreateMainTables extends Migration } } - private function createPiggyBanksTable(): void - { - if (!Schema::hasTable('piggy_banks')) { - Schema::create( - 'piggy_banks', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('account_id', false, true); - $table->string('name', 1024); - $table->decimal('targetamount', 32, 12); - $table->date('startdate')->nullable(); - $table->date('targetdate')->nullable(); - $table->integer('order', false, true)->default(0); - $table->boolean('active')->default(0); - $table->boolean('encrypted')->default(1); - $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); - } - ); - } - - if (!Schema::hasTable('piggy_bank_repetitions')) { - Schema::create( - 'piggy_bank_repetitions', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->integer('piggy_bank_id', false, true); - $table->date('startdate')->nullable(); - $table->date('targetdate')->nullable(); - $table->decimal('currentamount', 32, 12); - $table->foreign('piggy_bank_id')->references('id')->on('piggy_banks')->onDelete('cascade'); - } - ); - } - } - private function createAttachmentsTable(): void { if (!Schema::hasTable('attachments')) { @@ -323,6 +285,44 @@ class CreateMainTables extends Migration } } + private function createPiggyBanksTable(): void + { + if (!Schema::hasTable('piggy_banks')) { + Schema::create( + 'piggy_banks', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('account_id', false, true); + $table->string('name', 1024); + $table->decimal('targetamount', 32, 12); + $table->date('startdate')->nullable(); + $table->date('targetdate')->nullable(); + $table->integer('order', false, true)->default(0); + $table->boolean('active')->default(0); + $table->boolean('encrypted')->default(1); + $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); + } + ); + } + + if (!Schema::hasTable('piggy_bank_repetitions')) { + Schema::create( + 'piggy_bank_repetitions', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->integer('piggy_bank_id', false, true); + $table->date('startdate')->nullable(); + $table->date('targetdate')->nullable(); + $table->decimal('currentamount', 32, 12); + $table->foreign('piggy_bank_id')->references('id')->on('piggy_banks')->onDelete('cascade'); + } + ); + } + } + private function createPreferencesTable(): void { if (!Schema::hasTable('preferences')) { diff --git a/database/migrations/2022_08_21_104626_add_user_groups.php b/database/migrations/2022_08_21_104626_add_user_groups.php index 4a8ea74758..e21fc3b484 100644 --- a/database/migrations/2022_08_21_104626_add_user_groups.php +++ b/database/migrations/2022_08_21_104626_add_user_groups.php @@ -23,13 +23,15 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Schema; /** * */ -return new class () extends Migration { +return new class() extends Migration { /** * Run the migrations. * @@ -41,8 +43,16 @@ return new class () extends Migration { 'currency_exchange_rates', function (Blueprint $table) { if (!Schema::hasColumn('currency_exchange_rates', 'user_group_id')) { - $table->bigInteger('user_group_id', false, true)->nullable()->after('user_id'); - $table->foreign('user_group_id', 'cer_to_ugi')->references('id')->on('user_groups')->onDelete('set null')->onUpdate('cascade'); + try { + $table->bigInteger('user_group_id', false, true)->nullable()->after('user_id'); + } catch (QueryException $e) { + Log::error(sprintf('Could not add column "user_group_id" to table "currency_exchange_rates": %s', $e->getMessage())); + } + try { + $table->foreign('user_group_id', 'cer_to_ugi')->references('id')->on('user_groups')->onDelete('set null')->onUpdate('cascade'); + } catch (QueryException $e) { + Log::error(sprintf('Could not add foreign key "cer_to_ugi" to table "currency_exchange_rates": %s', $e->getMessage())); + } } } ); @@ -58,9 +68,17 @@ return new class () extends Migration { Schema::table( 'currency_exchange_rates', function (Blueprint $table) { - $table->dropForeign('cer_to_ugi'); + try { + $table->dropForeign('cer_to_ugi'); + } catch (QueryException $e) { + Log::error(sprintf('Could not drop foreign key "cer_to_ugi" from table "currency_exchange_rates": %s', $e->getMessage())); + } if (Schema::hasColumn('currency_exchange_rates', 'user_group_id')) { - $table->dropColumn('user_group_id'); + try { + $table->dropColumn('user_group_id'); + } catch (QueryException $e) { + Log::error(sprintf('Could not drop column "user_group_id" from table "currency_exchange_rates": %s', $e->getMessage())); + } } } ); diff --git a/database/migrations/2022_09_18_123911_create_notifications_table.php b/database/migrations/2022_09_18_123911_create_notifications_table.php index cafb647bf0..e2781adaca 100644 --- a/database/migrations/2022_09_18_123911_create_notifications_table.php +++ b/database/migrations/2022_09_18_123911_create_notifications_table.php @@ -23,10 +23,12 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Schema; -return new class () extends Migration { +return new class() extends Migration { /** * Run the migrations. * @@ -34,14 +36,18 @@ return new class () extends Migration { */ public function up() { - Schema::create('notifications', function (Blueprint $table) { - $table->uuid('id')->primary(); - $table->string('type'); - $table->morphs('notifiable'); - $table->text('data'); - $table->timestamp('read_at')->nullable(); - $table->timestamps(); - }); + try { + Schema::create('notifications', function (Blueprint $table) { + $table->uuid('id')->primary(); + $table->string('type'); + $table->morphs('notifiable'); + $table->text('data'); + $table->timestamp('read_at')->nullable(); + $table->timestamps(); + }); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "notifications": %s', $e->getMessage())); + } } /** diff --git a/database/migrations/2022_10_01_074908_invited_users.php b/database/migrations/2022_10_01_074908_invited_users.php index d91ccb6508..3f1880741a 100644 --- a/database/migrations/2022_10_01_074908_invited_users.php +++ b/database/migrations/2022_10_01_074908_invited_users.php @@ -23,10 +23,12 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Schema; -return new class () extends Migration { +return new class() extends Migration { /** * Run the migrations. * @@ -34,16 +36,20 @@ return new class () extends Migration { */ public function up(): void { - Schema::create('invited_users', function (Blueprint $table) { - $table->id(); - $table->timestamps(); - $table->integer('user_id', false, true); - $table->string('email', 255); - $table->string('invite_code', 64); - $table->dateTime('expires'); - $table->boolean('redeemed'); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - }); + try { + Schema::create('invited_users', function (Blueprint $table) { + $table->id(); + $table->timestamps(); + $table->integer('user_id', false, true); + $table->string('email', 255); + $table->string('invite_code', 64); + $table->dateTime('expires'); + $table->boolean('redeemed'); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + }); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "invited_users": %s', $e->getMessage())); + } } /** diff --git a/database/migrations/2022_10_01_210238_audit_log_entries.php b/database/migrations/2022_10_01_210238_audit_log_entries.php index 5b6d2d1ae9..6cd4ad159f 100644 --- a/database/migrations/2022_10_01_210238_audit_log_entries.php +++ b/database/migrations/2022_10_01_210238_audit_log_entries.php @@ -23,10 +23,12 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Schema; -return new class () extends Migration { +return new class() extends Migration { /** * Run the migrations. * @@ -34,21 +36,25 @@ return new class () extends Migration { */ public function up() { - Schema::create('audit_log_entries', function (Blueprint $table) { - $table->id(); - $table->timestamps(); - $table->softDeletes(); + try { + Schema::create('audit_log_entries', function (Blueprint $table) { + $table->id(); + $table->timestamps(); + $table->softDeletes(); - $table->integer('auditable_id', false, true); - $table->string('auditable_type'); + $table->integer('auditable_id', false, true); + $table->string('auditable_type'); - $table->integer('changer_id', false, true); - $table->string('changer_type'); + $table->integer('changer_id', false, true); + $table->string('changer_type'); - $table->string('action', 255); - $table->text('before')->nullable(); - $table->text('after')->nullable(); - }); + $table->string('action', 255); + $table->text('before')->nullable(); + $table->text('after')->nullable(); + }); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "audit_log_entries": %s', $e->getMessage())); + } } /**