fix: enable queued jobs to create portfolios with owners
This commit is contained in:
@@ -50,8 +50,9 @@ class PortfoliosSheet implements ToCollection, WithValidation, WithHeadingRow, S
|
|||||||
'title' => $portfolio['title'],
|
'title' => $portfolio['title'],
|
||||||
'wishlist' => $portfolio['wishlist'] ?? false,
|
'wishlist' => $portfolio['wishlist'] ?? false,
|
||||||
'notes' => $portfolio['notes'],
|
'notes' => $portfolio['notes'],
|
||||||
|
'owner_id' => $this->backupImport->user_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Artisan::queue(SyncDailyChange::class, ['portfolio_id' => $portfolio->id])->delay(30 + ($index * 10));
|
Artisan::queue(SyncDailyChange::class, ['portfolio_id' => $portfolio->id])->delay(30 + ($index * 10));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,18 @@ class Portfolio extends Model
|
|||||||
'wishlist',
|
'wishlist',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public static ?string $owner_id = null;
|
||||||
|
|
||||||
protected static function boot()
|
protected static function boot()
|
||||||
{
|
{
|
||||||
parent::boot();
|
parent::boot();
|
||||||
|
|
||||||
|
static::creating(function ($portfolio) {
|
||||||
|
|
||||||
|
// enable queued jobs to create portfolios with owners
|
||||||
|
static::$owner_id = auth()->user()?->id ?? $portfolio->attributes['owner_id'];
|
||||||
|
unset($portfolio->owner_id);
|
||||||
|
});
|
||||||
|
|
||||||
static::saved(function ($portfolio) {
|
static::saved(function ($portfolio) {
|
||||||
|
|
||||||
@@ -99,10 +108,10 @@ class Portfolio extends Model
|
|||||||
{
|
{
|
||||||
// make sure we don't remove owner access
|
// make sure we don't remove owner access
|
||||||
if (!$portfolio->owner_id) {
|
if (!$portfolio->owner_id) {
|
||||||
$users[auth()->user()->id] = ['owner' => true];
|
$owner[static::$owner_id ?? auth()->user()->id] = ['owner' => true];
|
||||||
|
|
||||||
// save
|
// save
|
||||||
$portfolio->users()->sync($users);
|
$portfolio->users()->sync($owner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user