mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Add fixing of invitations into check data script
This commit is contained in:
parent
52285b4a38
commit
b12190e554
@ -25,11 +25,11 @@ use App\Models\InvoiceInvitation;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Paymentable;
|
||||
use App\Utils\Ninja;
|
||||
use DB;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Str;
|
||||
use Mail;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/*
|
||||
@ -103,6 +103,7 @@ class CheckData extends Command
|
||||
// $this->checkPaidToCompanyDates();
|
||||
$this->checkClientBalances();
|
||||
$this->checkContacts();
|
||||
$this->checkEntityInvitations();
|
||||
$this->checkCompanyData();
|
||||
|
||||
|
||||
@ -307,13 +308,63 @@ class CheckData extends Command
|
||||
$invitation->company_id = $invoice->company_id;
|
||||
$invitation->user_id = $invoice->user_id;
|
||||
$invitation->invoice_id = $invoice->id;
|
||||
$invitation->contact_id = ClientContact::whereClientId($invoice->client_id)->whereIsPrimary(true)->first()->id;
|
||||
$invitation->invitation_key = str_random(config('ninja.key_length'));
|
||||
$invitation->contact_id = ClientContact::whereClientId($invoice->client_id)->first()->id;
|
||||
$invitation->invitation_key = Str::random(config('ninja.key_length'));
|
||||
$invitation->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function checkEntityInvitations()
|
||||
{
|
||||
|
||||
$entities = ['invoice', 'quote', 'credit', 'recurring_invoice'];
|
||||
|
||||
foreach($entities as $entity)
|
||||
{
|
||||
$table = "{$entity}s";
|
||||
$invitation_table = "{$entity}_invitations";
|
||||
|
||||
$entities = DB::table($table)
|
||||
->leftJoin($invitation_table, function ($join) use($invitation_table, $table, $entity){
|
||||
$join->on("{$invitation_table}.{$entity}_id", '=', "{$table}.id")
|
||||
->whereNull("{$invitation_table}.deleted_at");
|
||||
})
|
||||
->groupBy("{$table}.id", "{$table}.user_id", "{$table}.company_id", "{$table}.client_id")
|
||||
->havingRaw("count({$invitation_table}.id) = 0")
|
||||
->get(["{$table}.id", "{$table}.user_id", "{$table}.company_id", "{$table}.client_id"]);
|
||||
|
||||
|
||||
$this->logMessage($entities->count()." {$table} without any invitations");
|
||||
|
||||
if ($this->option('fix') == 'true')
|
||||
$this->fixInvitations($entities, $entity);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function fixInvitations($entities, $entity)
|
||||
{
|
||||
$entity_key = "{$entity}_id";
|
||||
|
||||
$entity_obj = 'App\Models\\'.ucfirst(Str::camel($entity)).'Invitation';
|
||||
|
||||
foreach($entities as $entity)
|
||||
{
|
||||
$invitation = new $entity_obj();
|
||||
$invitation->company_id = $entity->company_id;
|
||||
$invitation->user_id = $entity->user_id;
|
||||
$invitation->{$entity_key} = $entity->id;
|
||||
$invitation->client_contact_id = ClientContact::whereClientId($entity->client_id)->first()->id;
|
||||
$invitation->key = Str::random(config('ninja.key_length'));
|
||||
$invitation->save();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// private function checkPaidToCompanyDates()
|
||||
// {
|
||||
// Company::cursor()->each(function ($company){
|
||||
|
@ -90,7 +90,7 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
'contacts.company',
|
||||
// 'currency',
|
||||
// 'primary_contact',
|
||||
// 'country',
|
||||
'country',
|
||||
// 'contacts',
|
||||
// 'shipping_country',
|
||||
// 'company',
|
||||
@ -218,7 +218,7 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
|
||||
public function assigned_user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id');
|
||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
|
||||
}
|
||||
|
||||
public function country()
|
||||
|
@ -36,7 +36,7 @@ class CompanyLedger extends Model
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
return $this->belongsTo(User::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function company()
|
||||
|
@ -23,6 +23,8 @@ class CompanyToken extends BaseModel
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
'company',
|
||||
'user'
|
||||
];
|
||||
|
||||
protected $touches = [];
|
||||
|
@ -78,7 +78,7 @@ class CompanyUser extends Pivot
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
return $this->belongsTo(User::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function company()
|
||||
|
@ -120,7 +120,7 @@ class Credit extends BaseModel
|
||||
|
||||
public function assigned_user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id');
|
||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
|
||||
}
|
||||
|
||||
public function history()
|
||||
|
@ -84,7 +84,7 @@ class Expense extends BaseModel
|
||||
|
||||
public function assigned_user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id');
|
||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
|
||||
}
|
||||
|
||||
public function company()
|
||||
|
@ -52,7 +52,7 @@ class GroupSetting extends StaticModel
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
return $this->belongsTo(User::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function clients()
|
||||
|
@ -45,6 +45,11 @@ class Proposal extends BaseModel
|
||||
return $this->morphMany(Document::class, 'documentable');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function assigned_user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id');
|
||||
|
@ -76,7 +76,7 @@ class Subscription extends BaseModel
|
||||
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
return $this->belongsTo(User::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function nextDateByInterval($date, $frequency_id)
|
||||
|
@ -66,7 +66,7 @@ class Task extends BaseModel
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
return $this->belongsTo(User::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function client()
|
||||
|
@ -82,7 +82,7 @@ class Vendor extends BaseModel
|
||||
|
||||
public function assigned_user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id');
|
||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
|
||||
}
|
||||
|
||||
public function contacts()
|
||||
|
@ -87,7 +87,7 @@ class Webhook extends BaseModel
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
return $this->belongsTo(User::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function company()
|
||||
|
@ -208,6 +208,7 @@ trait MockAccountData
|
||||
$this->cu = CompanyUserFactory::create($user->id, $this->company->id, $this->account->id);
|
||||
$this->cu->is_owner = true;
|
||||
$this->cu->is_admin = true;
|
||||
$this->cu->is_locked = false;
|
||||
$this->cu->save();
|
||||
|
||||
$this->token = \Illuminate\Support\Str::random(64);
|
||||
|
Loading…
x
Reference in New Issue
Block a user