Improve notification performance (#3452)

* Improve notification performance

* Cascade deletes

* Fixes for company deletes

* Fixes for formatting

* todos for company

* Set currency id on payment

* Minor fixes for payment controller
This commit is contained in:
David Bomba 2020-03-08 16:59:06 +11:00 committed by GitHub
parent a8c15ef1c9
commit 37f295d49e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 55 additions and 23 deletions

View File

@ -488,6 +488,7 @@ class CreateTestData extends Command
$payment->type_id = PaymentType::CREDIT_CARD_OTHER; $payment->type_id = PaymentType::CREDIT_CARD_OTHER;
$payment->status_id = Payment::STATUS_COMPLETED; $payment->status_id = Payment::STATUS_COMPLETED;
$payment->number = $client->getNextPaymentNumber($client); $payment->number = $client->getNextPaymentNumber($client);
$payment->currency_id = 1;
$payment->save(); $payment->save();
$payment->invoices()->save($invoice); $payment->invoices()->save($invoice);

View File

@ -108,6 +108,7 @@ class CreateTestInvoiceJob implements ShouldQueue
$payment->type_id = PaymentType::CREDIT_CARD_OTHER; $payment->type_id = PaymentType::CREDIT_CARD_OTHER;
$payment->status_id = Payment::STATUS_COMPLETED; $payment->status_id = Payment::STATUS_COMPLETED;
$payment->number = $this->client->getNextPaymentNumber($this->client); $payment->number = $this->client->getNextPaymentNumber($this->client);
$payment->currency_id = 1;
$payment->save(); $payment->save();
$payment->invoices()->save($invoice); $payment->invoices()->save($invoice);

View File

@ -459,12 +459,43 @@ class CompanyController extends BaseController
*/ */
public function destroy(DestroyCompanyRequest $request, Company $company) public function destroy(DestroyCompanyRequest $request, Company $company)
{ {
$company_count = $company->account->companies->count();
$company->delete(); if($company_count == 1){
//@TODO if last company, delete the account also. $company->company_users->each(function ($company_user) {
return response()->json([], 200); $company_user->user->forceDelete();
});
$company->account->delete();
}
else {
$account = $company->account;
$company_id = $company->id;
$company->delete();
//If we are deleting the default companies, we'll need to make a new company the default.
if($account->default_company == $company_id){
$account->fresh();
$account->default_company = $account->companies->first()->id();
$account->save();
}
}
//@todo delete documents also!!
//@todo in the hosted version deleting the last
//account will trigger an account refund.
return response()->json(['message' => 'success'], 200);
} }
} }

View File

@ -148,8 +148,6 @@ class PreviewController extends BaseController
$invoice->setRelation('company', auth()->user()->company()); $invoice->setRelation('company', auth()->user()->company());
$invoice->load('client'); $invoice->load('client');
\Log::error(print_r(request()->input('body'),1));
$design_object = json_decode(request()->input('body')); $design_object = json_decode(request()->input('body'));
if(!is_object($design_object)) if(!is_object($design_object))

View File

@ -13,6 +13,7 @@ namespace App\Http\Controllers;
use Codedge\Updater\UpdaterManager; use Codedge\Updater\UpdaterManager;
use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Facades\Storage;
class SelfUpdateController extends BaseController class SelfUpdateController extends BaseController
{ {
@ -61,18 +62,14 @@ class SelfUpdateController extends BaseController
$res = $updater->update(); $res = $updater->update();
return response()->json(['message'=>$res], 200); return response()->json(['message'=>$res], 200);
} }
public function checkVersion(UpdaterManager $updater) public function checkVersion(UpdaterManager $updater)
{ {
$file_version = storage_path().'app/local_version.txt';
if(file_exists($file_version)){
return response()->json(['message' => file_get_contents($file_version)]);
}else{
return response()->json(['message' => '0.0.0']);
}
} }
} }

View File

@ -2,7 +2,7 @@
namespace App\Jobs\Util; namespace App\Jobs\Util;
use App\Utils\Traits\BulkOptions; use App\Models\Account;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
@ -14,7 +14,6 @@ class VersionCheck implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct() public function __construct()
{ {
@ -27,15 +26,11 @@ class VersionCheck implements ShouldQueue
*/ */
public function handle() public function handle()
{ {
//$local_version = storage_path() . '/app/local_version.txt';
$local_version = 'local_version.txt';
$version_file = file_get_contents(config('ninja.version_url')); $version_file = file_get_contents(config('ninja.version_url'));
if(Storage::exists($local_version)); if($version_file)
Storage::delete($local_version); Account::whereNotNull('id')->update(['latest_version' => $version_file]);
Storage::disk('local')->put('local_version.txt', $version_file);
} }

View File

@ -5,13 +5,17 @@ namespace App\Notifications\Ninja;
use App\Mail\Signup\NewSignup; use App\Mail\Signup\NewSignup;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification; use Illuminate\Notifications\Notification;
class NewAccountCreated extends Notification implements ShouldQueue class NewAccountCreated extends Notification implements ShouldQueue
{ {
use Queueable;
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/** /**
* Create a new notification instance. * Create a new notification instance.

View File

@ -267,6 +267,7 @@ class BasePaymentDriver
$payment->client_id = $this->client->id; $payment->client_id = $this->client->id;
$payment->company_gateway_id = $this->company_gateway->id; $payment->company_gateway_id = $this->company_gateway->id;
$payment->status_id = Payment::STATUS_COMPLETED; $payment->status_id = Payment::STATUS_COMPLETED;
$payment->currency_id = $this->client->getSetting('currency_id');
$payment->date = Carbon::now(); $payment->date = Carbon::now();
return $payment; return $payment;

View File

@ -50,6 +50,7 @@ class MarkPaid extends AbstractService
$payment->status_id = Payment::STATUS_COMPLETED; $payment->status_id = Payment::STATUS_COMPLETED;
$payment->client_id = $this->invoice->client_id; $payment->client_id = $this->invoice->client_id;
$payment->transaction_reference = ctrans('texts.manual_entry'); $payment->transaction_reference = ctrans('texts.manual_entry');
$payment->currency_id = $this->invoice->client->getSetting('currency_id');
/* Create a payment relationship to the invoice entity */ /* Create a payment relationship to the invoice entity */
$payment->save(); $payment->save();

View File

@ -35,6 +35,7 @@ class PaymentService
$payment->status_id = Payment::STATUS_COMPLETED; $payment->status_id = Payment::STATUS_COMPLETED;
$payment->client_id = $invoice->client_id; $payment->client_id = $invoice->client_id;
$payment->transaction_reference = ctrans('texts.manual_entry'); $payment->transaction_reference = ctrans('texts.manual_entry');
$payment->currency_id = $invoice->client->getSetting('currency_id');
/* Create a payment relationship to the invoice entity */ /* Create a payment relationship to the invoice entity */
$payment->save(); $payment->save();

View File

@ -60,6 +60,7 @@ class AccountTransformer extends EntityTransformer
'id' => (string)$this->encodePrimaryKey($account->id), 'id' => (string)$this->encodePrimaryKey($account->id),
'default_url' => config('ninja.site_url'), 'default_url' => config('ninja.site_url'),
'plan' => $account->getPlan(), 'plan' => $account->getPlan(),
'latest_version' => (string)$account->latest_version,
'updated_at' => (int)$account->updated_at, 'updated_at' => (int)$account->updated_at,
'archived_at' => (int)$account->deleted_at, 'archived_at' => (int)$account->deleted_at,
]; ];

View File

@ -7,7 +7,7 @@ return [
'production' => env('NINJA_PROD', false), 'production' => env('NINJA_PROD', false),
'license' => env('NINJA_LICENSE', ''), 'license' => env('NINJA_LICENSE', ''),
'app_name' => env('APP_NAME'), 'app_name' => env('APP_NAME'),
'version_url' => 'https://github.com/invoiceninja/invoiceninja/tree/v2/VERSION.txt', 'version_url' => 'https://raw.githubusercontent.com/invoiceninja/invoiceninja/v2/VERSION.txt',
'site_url' => env('APP_URL', ''), 'site_url' => env('APP_URL', ''),
'app_domain' => env('APP_DOMAIN', 'invoicing.co'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
'app_version' => '0.0.1', 'app_version' => '0.0.1',

View File

@ -127,6 +127,7 @@ class CreateUsersTable extends Migration
$table->string('utm_campaign')->nullable(); $table->string('utm_campaign')->nullable();
$table->string('utm_term')->nullable(); $table->string('utm_term')->nullable();
$table->string('utm_content')->nullable(); $table->string('utm_content')->nullable();
$table->string('latest_version')->default('0.0.0');
$table->float('discount')->default(0); $table->float('discount')->default(0);
$table->date('discount_expires')->nullable(); $table->date('discount_expires')->nullable();