-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1101 from nextcloud/feat/add-events-for-table-mod…
…ification feat: Add events for row added and row updated
- Loading branch information
Showing
11 changed files
with
143 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Tables\Event; | ||
|
||
use OCA\Tables\Db\Row2; | ||
use OCA\Tables\Model\Public\Row; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IWebhookCompatibleEvent; | ||
|
||
if (interface_exists(\OCP\EventDispatcher\IWebhookCompatibleEvent::class)) { | ||
abstract class AbstractRowEvent extends Event implements IWebhookCompatibleEvent { | ||
protected Row $row; | ||
|
||
public function __construct(Row2 $rowEntity, ?array $previousValues = null) { | ||
parent::__construct(); | ||
$this->row = $rowEntity->toPublicRow($previousValues); | ||
} | ||
|
||
public function getRow(): Row { | ||
return $this->row; | ||
} | ||
|
||
public function getWebhookSerializable(): array { | ||
return $this->row->jsonSerialize(); | ||
} | ||
} | ||
} else { | ||
// need this block as long as NC < 30 is supported | ||
abstract class AbstractRowEvent extends Event { | ||
protected Row $row; | ||
|
||
public function __construct(Row2 $rowEntity, ?array $previousValues = null) { | ||
parent::__construct(); | ||
$this->row = $rowEntity->toPublicRow($previousValues); | ||
} | ||
|
||
public function getRow(): Row { | ||
return $this->row; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Tables\Event; | ||
|
||
final class RowAddedEvent extends AbstractRowEvent { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Tables\Event; | ||
|
||
final class RowUpdatedEvent extends AbstractRowEvent { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace OCA\Tables\Model\Public; | ||
|
||
use JsonSerializable; | ||
|
||
/** | ||
* @since 0.8 | ||
*/ | ||
final class Row implements JsonSerializable { | ||
|
||
/** | ||
* @param int $tableId | ||
* @param int $rowId | ||
* @param array<int,mixed>|null $previousValues key is the columnId. Only set on Update events. | ||
* @param array<int,mixed>|null $values key is the columnId. Contains values across all events, including Delete. | ||
* | ||
* @since 0.8 | ||
*/ | ||
public function __construct( | ||
/** @readonly */ | ||
public int $tableId, | ||
/** @readonly */ | ||
public int $rowId, | ||
/** @readonly */ | ||
public null|array $previousValues = null, | ||
/** @readonly */ | ||
public null|array $values = null, | ||
) { | ||
} | ||
|
||
|
||
/** | ||
* @return array{"tableId": int, "rowId": int, "previousValues": null|array<int, mixed>, "values": null|array<int, mixed>} | ||
* | ||
* @since 0.8 | ||
*/ | ||
public function jsonSerialize(): array { | ||
return [ | ||
'tableId' => $this->tableId, | ||
'rowId' => $this->rowId, | ||
'previousValues' => $this->previousValues, | ||
'values' => $this->values, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters