From 8420a4bac170276460a903da189d88d8261581c8 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 21 Jul 2020 09:00:59 +1000 Subject: [PATCH] Remove redundant properties from account table and transformer --- app/Console/Commands/DemoMode.php | 2 +- app/Exceptions/Handler.php | 3 +- .../ValidationRules/Ninja/CanAddUserRule.php | 4 +-- app/Repositories/BaseRepository.php | 12 ++++++-- app/Transformers/AccountTransformer.php | 7 ----- config/ninja.php | 2 +- config/sentry.php | 30 +++++++++++++++++++ .../2014_10_13_000000_create_users_table.php | 9 ------ tests/Unit/CompareObjectTest.php | 4 +-- 9 files changed, 48 insertions(+), 25 deletions(-) create mode 100644 config/sentry.php diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index bc1875f5a787..a1ba6b757ded 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -383,7 +383,7 @@ class DemoMode extends Command $invoice = $invoice->service()->markPaid()->save(); $invoice->payments->each(function ($payment){ - $payment->date = now()->addDays(rand(0,90)); + $payment->date = now()->addDays(rand(-30,30)); $payment->save(); }); } diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index aafe25931921..a8350e2642fd 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -36,7 +36,7 @@ class Handler extends ExceptionHandler * @var array */ protected $dontReport = [ - // + \PDOException::class, ]; /** @@ -81,6 +81,7 @@ class Handler extends ExceptionHandler } }); + app('sentry')->setRelease(config('ninja.app_version')); app('sentry')->captureException($exception); } diff --git a/app/Http/ValidationRules/Ninja/CanAddUserRule.php b/app/Http/ValidationRules/Ninja/CanAddUserRule.php index 75bf15f5e552..3665a3757f97 100644 --- a/app/Http/ValidationRules/Ninja/CanAddUserRule.php +++ b/app/Http/ValidationRules/Ninja/CanAddUserRule.php @@ -35,7 +35,7 @@ class CanAddUserRule implements Rule */ public function passes($attribute, $value) { - return $this->account->num_users < $this->account->pending_num_users; + return $this->account->users->count() < $this->account->num_users; } /** @@ -43,7 +43,7 @@ class CanAddUserRule implements Rule */ public function message() { - return ctrans('texts.limit_users', ['limit' => $this->account->pending_num_users]); + return ctrans('texts.limit_users', ['limit' => $this->account->num_users]); } } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index c96cdf52577f..05858f8c83b2 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -178,7 +178,7 @@ class BaseRepository public function getInvitation($invitation, $resource) { - if (!array_key_exists('key', $invitation)) { + if (is_array($invitation) && !array_key_exists('key', $invitation)) { return false; } @@ -253,7 +253,15 @@ class BaseRepository /* Get array of Keys which have been removed from the invitations array and soft delete each invitation */ $model->invitations->pluck('key')->diff($invitations->pluck('key'))->each(function ($invitation) use($resource){ - $this->getInvitation($invitation, $resource)->delete(); + // $this->getInvitation($invitation, $resource)->delete(); + + $invitation_class = sprintf("App\\Models\\%sInvitation", $resource); + + $invitation = $invitation_class::whereRaw("BINARY `key`= ?", [$invitation])->first(); + + if($invitation) + $invitation->delete(); + }); foreach ($data['invitations'] as $invitation) { diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.php index e7ae650cbf44..58e3242a7eda 100644 --- a/app/Transformers/AccountTransformer.php +++ b/app/Transformers/AccountTransformer.php @@ -68,19 +68,12 @@ class AccountTransformer extends EntityTransformer 'payment_id' => (string) $account->payment_id, 'trial_started' => (string) $account->trial_started, 'trial_plan' => (string) $account->trial_plan, - 'pending_plan' => (string) $account->pending_plan, // todo remove - 'pending_term' => (string) $account->pending_term, // todo remove 'plan_price' => (float) $account->plan_price, - 'pending_plan_price' => (string) $account->pending_plan_price, //todo remove 'num_users' => (int) $account->num_users, - 'pending_num_users' => (int) $account->pending_num_users, 'utm_source' => (string) $account->utm_source, 'utm_medium' => (string) $account->utm_medium, 'utm_content' => (string) $account->utm_content, 'utm_term' => (string) $account->utm_term, - 'discount' => (float) $account->discount, //todo delete - 'discount_expires' => (string) $account->discount_expires, //todo delete - 'bluevine_status' => (string) $account->bluevine_status, //todo delete this 'referral_code' => (string) $account->referral_code, 'latest_version' => (string)$account->latest_version, 'current_version' => (string)config('ninja.app_version'), diff --git a/config/ninja.php b/config/ninja.php index c2703bac8091..38d93fc5842c 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -8,7 +8,7 @@ return [ 'license' => env('NINJA_LICENSE', ''), 'version_url' => 'https://raw.githubusercontent.com/invoiceninja/invoiceninja/v2/VERSION.txt', 'app_name' => env('APP_NAME'), - 'app_env' => env('APP_ENV', 'local'), + 'app_env' => env('APP_ENV', 'selfhosted'), 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => env('APP_URL', ''), 'app_domain' => env('APP_DOMAIN', ''), diff --git a/config/sentry.php b/config/sentry.php new file mode 100644 index 000000000000..8c91c3dbbc8b --- /dev/null +++ b/config/sentry.php @@ -0,0 +1,30 @@ + env('SENTRY_LARAVEL_DSN', env('SENTRY_DSN')), + + // capture release as git sha + // 'release' => trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')), + + 'breadcrumbs' => [ + // Capture Laravel logs in breadcrumbs + 'logs' => true, + + // Capture SQL queries in breadcrumbs + 'sql_queries' => true, + + // Capture bindings on SQL queries logged in breadcrumbs + 'sql_bindings' => true, + + // Capture queue job information in breadcrumbs + 'queue_info' => true, + + // Capture command information in breadcrumbs + 'command_info' => true, + ], + + // @see: https://docs.sentry.io/error-reporting/configuration/?platform=php#send-default-pii + 'send_default_pii' => false, + +]; diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index cee12a11992f..1141ee17b48d 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -112,13 +112,8 @@ class CreateUsersTable extends Migration $table->date('trial_started')->nullable(); $table->enum('trial_plan', ['pro', 'enterprise'])->nullable(); - $table->enum('pending_plan', ['pro', 'enterprise', 'free'])->nullable(); - $table->enum('pending_term', ['month', 'year'])->nullable(); - $table->decimal('plan_price', 7, 2)->nullable(); - $table->decimal('pending_plan_price', 7, 2)->nullable(); $table->smallInteger('num_users')->default(1); - $table->smallInteger('pending_num_users')->default(1); $table->string('utm_source')->nullable(); $table->string('utm_medium')->nullable(); @@ -128,10 +123,6 @@ class CreateUsersTable extends Migration $table->string('latest_version')->default('0.0.0'); $table->boolean('report_errors')->default(false); - $table->float('discount')->default(0); - $table->date('discount_expires')->nullable(); - - $table->enum('bluevine_status', ['ignored', 'signed_up'])->nullable(); $table->string('referral_code')->nullable(); $table->timestamps(6); diff --git a/tests/Unit/CompareObjectTest.php b/tests/Unit/CompareObjectTest.php index c91c540fccb5..b7a6c62fbe77 100644 --- a/tests/Unit/CompareObjectTest.php +++ b/tests/Unit/CompareObjectTest.php @@ -41,7 +41,7 @@ class CompareObjectTest extends TestCase $this->assertEquals($build_client_settings->timezone_id, 1); $this->assertEquals($build_client_settings->language_id, 1); - $this->assertEquals($build_client_settings->payment_terms, '-1'); + $this->assertEquals($build_client_settings->payment_terms, ''); } public function testDirectClientSettingsBuild() @@ -50,7 +50,7 @@ class CompareObjectTest extends TestCase $this->assertEquals($settings->timezone_id, 1); $this->assertEquals($settings->language_id, 1); - $this->assertEquals($settings->payment_terms, '-1'); + $this->assertEquals($settings->payment_terms, ''); $this->assertFalse($settings->auto_archive_invoice); } }