Various improved error catching.

This commit is contained in:
James Cole 2023-04-05 20:22:17 +02:00
parent 70b6e39cd7
commit 5068fc76c1
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
7 changed files with 169 additions and 120 deletions

View File

@ -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')) {

View File

@ -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']);
}
);
}

View File

@ -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')) {

View File

@ -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()));
}
}
}
);

View File

@ -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()));
}
}
/**

View File

@ -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()));
}
}
/**

View File

@ -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()));
}
}
/**