mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 19:14:04 +00:00
[4.x] Add feature to ignore the resource synchronization based on provided condition. (#993)
* wip * add test * readability * remove group * DisabledSync -> ConditionalSync; test both cases with dataset Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
This commit is contained in:
parent
77c5ae1f32
commit
22d1b2065b
5 changed files with 67 additions and 3 deletions
|
|
@ -18,4 +18,6 @@ interface Syncable
|
|||
|
||||
/** 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). */
|
||||
public function getSyncedCreationAttributes(): array|null; // todo come up with a better name
|
||||
|
||||
public function shouldSync(): bool;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,9 @@ trait ResourceSyncing
|
|||
public static function bootResourceSyncing(): void
|
||||
{
|
||||
static::saved(function (Syncable $model) {
|
||||
/** @var ResourceSyncing $model */
|
||||
$model->triggerSyncEvent();
|
||||
if ($model->shouldSync()) {
|
||||
$model->triggerSyncEvent();
|
||||
}
|
||||
});
|
||||
|
||||
static::creating(function (self $model) {
|
||||
|
|
@ -37,4 +38,9 @@ trait ResourceSyncing
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function shouldSync(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class TenantPivot extends Pivot
|
|||
static::saved(function (self $pivot) {
|
||||
$parent = $pivot->pivotParent;
|
||||
|
||||
if ($parent instanceof Syncable) {
|
||||
if ($parent instanceof Syncable && $parent->shouldSync()) {
|
||||
$parent->triggerSyncEvent();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue