mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 11:14:04 +00:00
Rename and move triggerRestoredEvent
Rename triggerRestoredEvent to triggerRestoreEvent, move triggerRestoreEvent from the Syncable interface to SyncMaster, call triggerRestoreEvent only when restoring SyncMaster, delete useless assertions.
This commit is contained in:
parent
2b45a01018
commit
ed12b92bd8
4 changed files with 6 additions and 15 deletions
|
|
@ -46,8 +46,8 @@ trait ResourceSyncing
|
|||
});
|
||||
|
||||
static::restoring(static function (Syncable&Model $model) {
|
||||
if ($model->shouldSync()) {
|
||||
$model->triggerRestoredEvent();
|
||||
if ($model instanceof SyncMaster && $model->shouldSync()) {
|
||||
$model->triggerRestoreEvent();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -69,7 +69,7 @@ trait ResourceSyncing
|
|||
event(new SyncedResourceDeleted($this, tenant(), $forceDelete));
|
||||
}
|
||||
|
||||
public function triggerRestoredEvent(): void
|
||||
public function triggerRestoreEvent(): void
|
||||
{
|
||||
if ($this instanceof SyncMaster && in_array(SoftDeletes::class, class_uses_recursive($this), true)) {
|
||||
/** @var SyncMaster&Model $this */
|
||||
|
|
|
|||
|
|
@ -24,4 +24,6 @@ interface SyncMaster extends Syncable
|
|||
public function triggerDetachEvent(TenantWithDatabase&Model $tenant): void;
|
||||
|
||||
public function triggerAttachEvent(TenantWithDatabase&Model $tenant): void;
|
||||
|
||||
public function triggerRestoreEvent(): void;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ interface Syncable
|
|||
|
||||
public function triggerDeleteEvent(bool $forceDelete = false): void;
|
||||
|
||||
public function triggerRestoredEvent(): void;
|
||||
|
||||
/**
|
||||
* Get the attributes used for creating the *other* model (i.e. tenant if this is the central one, and central if this is the tenant one).
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1102,16 +1102,7 @@ test('restoring soft deleted resources works', function () {
|
|||
CentralUserWithSoftDeletes::withTrashed()->first()->restore();
|
||||
|
||||
tenancy()->runForMultiple([$tenant1, $tenant2], function () {
|
||||
$tenantResource = TenantUserWithSoftDeletes::withTrashed()->first();
|
||||
|
||||
expect($tenantResource->trashed())->toBeFalse();
|
||||
|
||||
$tenantResource->delete();
|
||||
|
||||
// Restoring a tenant resource works as expected
|
||||
$tenantResource->restore();
|
||||
|
||||
expect($tenantResource->trashed())->toBeFalse();
|
||||
expect(TenantUserWithSoftDeletes::withTrashed()->first()->trashed())->toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue