Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom destroy attributes #23

Merged
merged 3 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/Integration/Laravel/Contracts/SyncableModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,42 @@
interface SyncableModel
{
/**
* @var string
* @return string
*/
public function getKeyName();

/**
* @var string
* @return string
*/
public function getKey();

/**
* @var static|null
* @return static|null
*/
public function fresh();

/**
* @var array
* @return array
*/
public function getTableSyncableAttributes();

/**
* @var string
* @return array
*/
public function getTableSyncableDestroyAttributes();

/**
* @return string
*/
public function classForSync();

/**
* @var bool
* @return bool
*/
public function exists();

/**
* @var string
* @return string
*/
public function routingKey();
}
8 changes: 4 additions & 4 deletions src/Integration/Laravel/Syncer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ private function syncTable(SyncableModel $model, string $event): void

private function getSyncableAttributes(SyncableModel $model): array
{
if (!$model->exists()) {
return $this->pkAttributes($model);
}
$syncableAttributes = $model->exists() ?
$model->getTableSyncableAttributes() :
$model->getTableSyncableDestroyAttributes();

return array_merge($this->pkAttributes($model), $model->getTableSyncableAttributes());
return array_merge($this->pkAttributes($model), $syncableAttributes);
}

private function needsPublishAttributes(SyncableModel $model, array $attributes): bool
Expand Down
5 changes: 5 additions & 0 deletions src/Integration/Laravel/TableSyncable.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public function getTableSyncableAttributes(): array
return $this->getAttributes();
}

public function getTableSyncableDestroyAttributes(): array
{
return [];
}

public function classForSync(): string
{
return static::class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function setUp(): void
{
parent::setUp();

$this->spyPublisher = $this->makeSpyPublsiher();
$this->spyPublisher = $this->makeSpyPublisher();

$this->app->bind(Publisher::class, function () {
return $this->spyPublisher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function setUp(): void
{
parent::setUp();

$this->spyPublisher = $this->makeSpyPublsiher();
$this->spyPublisher = $this->makeSpyPublisher();

$this->app->bind(Publisher::class, function () {
return $this->spyPublisher;
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/Laravel/Traits/SpyPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

trait SpyPublisher
{
protected function makeSpyPublsiher(): Publisher
protected function makeSpyPublisher(): Publisher
{
return new class() implements Publisher {
public $messages;
Expand Down