From da23662d7b8598fd26fad6de771467d0a1a4d767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Mon, 1 Jun 2020 09:51:22 +0200 Subject: [PATCH] Clenup for resource syncing --- assets/TenancyServiceProvider.stub.php | 5 +++++ src/Contracts/Syncable.php | 2 ++ .../2020_05_11_000002_create_tenant_users_table.php | 5 ----- tests/ResourceSyncingTest.php | 9 ++------- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/assets/TenancyServiceProvider.stub.php b/assets/TenancyServiceProvider.stub.php index cc3f72e6..711fd0f4 100644 --- a/assets/TenancyServiceProvider.stub.php +++ b/assets/TenancyServiceProvider.stub.php @@ -78,6 +78,11 @@ class TenancyServiceProvider extends ServiceProvider Events\TenancyBootstrapped::class => [], Events\RevertingToCentralContext::class => [], Events\RevertedToCentralContext::class => [], + + // Resource syncing + Events\SyncedResourceSaved::class => [ + Listeners\UpdateSyncedResource::class, + ], ]; } diff --git a/src/Contracts/Syncable.php b/src/Contracts/Syncable.php index 16550cfb..db8a7037 100644 --- a/src/Contracts/Syncable.php +++ b/src/Contracts/Syncable.php @@ -13,4 +13,6 @@ interface Syncable public function getCentralModelName(): string; public function getSyncedAttributeNames(): array; + + public function triggerSyncEvent(); } diff --git a/tests/Etc/synced_resource_migrations/2020_05_11_000002_create_tenant_users_table.php b/tests/Etc/synced_resource_migrations/2020_05_11_000002_create_tenant_users_table.php index fb00b0d8..0aafd23c 100644 --- a/tests/Etc/synced_resource_migrations/2020_05_11_000002_create_tenant_users_table.php +++ b/tests/Etc/synced_resource_migrations/2020_05_11_000002_create_tenant_users_table.php @@ -8,11 +8,6 @@ use Illuminate\Support\Facades\Schema; class CreateTenantUsersTable extends Migration { - /** - * Run the migrations. - * - * @return void - */ public function up() { Schema::create('tenant_users', function (Blueprint $table) { diff --git a/tests/ResourceSyncingTest.php b/tests/ResourceSyncingTest.php index 0df8b715..6db7c4ca 100644 --- a/tests/ResourceSyncingTest.php +++ b/tests/ResourceSyncingTest.php @@ -117,9 +117,9 @@ class ResourceSyncingTest extends TestCase // Update user in tenant DB $user->update([ + 'name' => 'John Foo', // synced + 'email' => 'john@foreignhost', // synced 'role' => 'admin', // unsynced - 'name' => 'John Foo', // synceed - 'email' => 'john@foreignhost', // synceed ]); // Assert new values @@ -603,11 +603,6 @@ class CentralUser extends Model implements SyncMaster return ResourceUser::class; } - public function getTenantIdColumnInMapTable(): string - { - return 'tenant_id'; - } - public function getGlobalIdentifierKey(): string { return $this->getAttribute($this->getGlobalIdentifierKeyName());