1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

Merge pull request #5663 from turbo124/v5-develop

Fixes for deleting users / company_users and companies
This commit is contained in:
David Bomba 2021-05-11 17:25:58 +10:00 committed by GitHub
commit a46b132275
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 43 additions and 42 deletions

View File

@ -480,12 +480,9 @@ class CompanyController extends BaseController
if ($company_count == 1) { if ($company_count == 1) {
$company->company_users->each(function ($company_user) { $company->company_users->each(function ($company_user) {
$company_user->user->forceDelete(); $company_user->user->forceDelete();
$company_user->forceDelete();
}); });
// if (Ninja::isHosted()) {
// RefundCancelledAccount::dispatchNow($account);
// }
$account->delete(); $account->delete();
LightLogs::create(new AccountDeleted()) LightLogs::create(new AccountDeleted())
@ -493,6 +490,11 @@ class CompanyController extends BaseController
->batch(); ->batch();
} else { } else {
$company_id = $company->id; $company_id = $company->id;
$company->company_users->each(function ($company_user){
$company_user->forceDelete();
});
$company->delete(); $company->delete();
//If we are deleting the default companies, we'll need to make a new company the default. //If we are deleting the default companies, we'll need to make a new company the default.

View File

@ -52,8 +52,7 @@ class QueryLogging
$timeEnd = microtime(true); $timeEnd = microtime(true);
$time = $timeEnd - $timeStart; $time = $timeEnd - $timeStart;
nlog($request->method().' - '.urldecode($request->url()).": $count queries - ".$time); //nlog($request->method().' - '.urldecode($request->url()).": $count queries - ".$time);
// if($count > 50) // if($count > 50)
//nlog($queries); //nlog($queries);

View File

@ -43,7 +43,7 @@ class ArchivedClientActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->client->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->client->user_id;
$fields->client_id = $event->client->id; $fields->client_id = $event->client->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -45,7 +45,7 @@ class ClientUpdatedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->client->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->client->user_id;
$fields->client_id = $client->id; $fields->client_id = $client->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -43,7 +43,7 @@ class CreatedClientActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->client->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->client->user_id;
$fields->client_id = $event->client->id; $fields->client_id = $event->client->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -43,7 +43,7 @@ class CreatedCreditActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->credit->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->credit->user_id;
$fields->credit_id = $event->credit->id; $fields->credit_id = $event->credit->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -44,7 +44,7 @@ class CreatedExpenseActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->expense->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->expense->user_id;
$fields->expense_id = $event->expense->id; $fields->expense_id = $event->expense->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -43,7 +43,7 @@ class CreatedQuoteActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->quote->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->quote->user_id;
$fields->quote_id = $event->quote->id; $fields->quote_id = $event->quote->id;
$fields->client_id = $event->quote->client_id; $fields->client_id = $event->quote->client_id;

View File

@ -43,7 +43,7 @@ class CreatedSubscriptionActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->subscription->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->subscription->user_id;
$fields->subscription_id = $event->subscription->id; $fields->subscription_id = $event->subscription->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -43,7 +43,7 @@ class CreatedTaskActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->task->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->task->user_id;
$fields->task_id = $event->task->id; $fields->task_id = $event->task->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -43,7 +43,7 @@ class CreatedVendorActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->vendor->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->vendor->user_id;
$fields->vendor_id = $event->vendor->id; $fields->vendor_id = $event->vendor->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -43,7 +43,7 @@ class CreditArchivedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->credit->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->credit->user_id;
$fields->payment_id = $event->credit->id; $fields->payment_id = $event->credit->id;
$fields->client_id = $event->credit->client_id; $fields->client_id = $event->credit->client_id;

View File

@ -43,7 +43,7 @@ class DeleteClientActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->client->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->client->user_id;
$fields->client_id = $event->client->id; $fields->client_id = $event->client->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -43,7 +43,7 @@ class DeleteCreditActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->credit->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->credit->user_id;
$fields->client_id = $event->credit->client_id; $fields->client_id = $event->credit->client_id;
$fields->credit_id = $event->credit->id; $fields->credit_id = $event->credit->id;

View File

@ -45,7 +45,7 @@ class ExpenseArchivedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->expense->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->expense->user_id;
$fields->expense_id = $expense->id; $fields->expense_id = $expense->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -43,7 +43,7 @@ class ExpenseDeletedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = array_key_exists('user_id', $event->event_vars['user_id']) ? $event->event_vars['user_id'] : $event->expense->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->expense->user_id;
$fields->expense_id = $event->expense->id; $fields->expense_id = $event->expense->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -43,7 +43,7 @@ class ExpenseRestoredActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->expense->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->expense->user_id;
$fields->expense_id = $event->expense->id; $fields->expense_id = $event->expense->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -43,7 +43,7 @@ class ExpenseUpdatedActivity implements ShouldQueue
$expense = $event->expense; $expense = $event->expense;
$user_id = $event->event_vars['user_id'] ?: $event->expense->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->expense->user_id;
$fields = new stdClass; $fields = new stdClass;

View File

@ -48,7 +48,7 @@ class PaymentArchivedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->payment->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->payment->user_id;
$fields->payment_id = $payment->id; $fields->payment_id = $payment->id;
$fields->client_id = $payment->client_id; $fields->client_id = $payment->client_id;

View File

@ -43,7 +43,7 @@ class PaymentCreatedActivity implements ShouldQueue
$payment = $event->payment; $payment = $event->payment;
$user_id = $event->event_vars['user_id'] ?: $event->payment->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->payment->user_id;
$invoices = $payment->invoices; $invoices = $payment->invoices;

View File

@ -43,7 +43,7 @@ class PaymentDeletedActivity implements ShouldQueue
$payment = $event->payment; $payment = $event->payment;
$user_id = $event->event_vars['user_id'] ?: $event->payment->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->payment->user_id;
$invoices = $payment->invoices; $invoices = $payment->invoices;

View File

@ -43,7 +43,7 @@ class PaymentRefundedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->payment->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->payment->user_id;
$fields->client_id = $event->payment->id; $fields->client_id = $event->payment->id;
$fields->client_id = $event->payment->client_id; $fields->client_id = $event->payment->client_id;

View File

@ -48,7 +48,7 @@ class PaymentUpdatedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->payment->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->payment->user_id;
$fields->payment_id = $payment->id; $fields->payment_id = $payment->id;
$fields->client_id = $payment->client_id; $fields->client_id = $payment->client_id;

View File

@ -43,7 +43,7 @@ class PaymentVoidedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->payment->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->payment->user_id;
$fields->client_id = $event->payment->id; $fields->client_id = $event->payment->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -45,7 +45,7 @@ class QuoteUpdatedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->quote->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->quote->user_id;
$fields->quote_id = $quote->id; $fields->quote_id = $quote->id;
$fields->client_id = $quote->client_id; $fields->client_id = $quote->client_id;

View File

@ -43,7 +43,7 @@ class RestoreClientActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->client->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->client->user_id;
$fields->client_id = $event->client->id; $fields->client_id = $event->client->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -45,7 +45,7 @@ class SubscriptionArchivedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->subscription->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->subscription->user_id;
$fields->subscription_id = $subscription->id; $fields->subscription_id = $subscription->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -43,7 +43,7 @@ class SubscriptionDeletedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->subscription->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->subscription->user_id;
$fields->subscription_id = $event->subscription->id; $fields->subscription_id = $event->subscription->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -43,7 +43,7 @@ class SubscriptionRestoredActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->subscription->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->subscription->user_id;
$fields->subscription_id = $event->subscription->id; $fields->subscription_id = $event->subscription->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -45,7 +45,7 @@ class SubscriptionUpdatedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->subscription->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->subscription->user_id;
$fields->subscription_id = $subscription->id; $fields->subscription_id = $subscription->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -45,7 +45,7 @@ class TaskArchivedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->task->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->task->user_id;
$fields->task_id = $task->id; $fields->task_id = $task->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -43,7 +43,7 @@ class TaskRestoredActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->task->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->task->user_id;
$fields->task_id = $event->task->id; $fields->task_id = $event->task->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -45,7 +45,7 @@ class TaskUpdatedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->task->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->task->user_id;
$fields->task_id = $task->id; $fields->task_id = $task->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -43,7 +43,7 @@ class UpdatedCreditActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->credit->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->credit->user_id;
$fields->credit_id = $event->credit->id; $fields->credit_id = $event->credit->id;
$fields->client_id = $event->credit->client_id; $fields->client_id = $event->credit->client_id;

View File

@ -45,7 +45,7 @@ class VendorArchivedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->vendor->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->vendor->user_id;
$fields->vendor_id = $vendor->id; $fields->vendor_id = $vendor->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -43,7 +43,7 @@ class VendorDeletedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->vendor->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->vendor->user_id;
$fields->vendor_id = $event->vendor->id; $fields->vendor_id = $event->vendor->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -43,7 +43,7 @@ class VendorRestoredActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->vendor->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->vendor->user_id;
$fields->vendor_id = $event->vendor->id; $fields->vendor_id = $event->vendor->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;

View File

@ -45,7 +45,7 @@ class VendorUpdatedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->vendor->user_id; $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->vendor->user_id;
$fields->vendor_id = $vendor->id; $fields->vendor_id = $vendor->id;
$fields->user_id = $user_id; $fields->user_id = $user_id;