From 8ca2452dd05f614d55d2fd3ce188d9d04f44d285 Mon Sep 17 00:00:00 2001 From: winter Date: Fri, 20 Dec 2024 17:57:36 +0000 Subject: implement deletion/tombstones? --- Digitigrade/Model/PushableModel.php | 42 ++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'Digitigrade/Model/PushableModel.php') diff --git a/Digitigrade/Model/PushableModel.php b/Digitigrade/Model/PushableModel.php index c008320..9de3507 100644 --- a/Digitigrade/Model/PushableModel.php +++ b/Digitigrade/Model/PushableModel.php @@ -1,11 +1,24 @@ type == 'tombstone') { + // actually just delete the object if we know it and do nothing if not + $obj = static::findWhere('uri = ?', [$data->self]); + if ($obj == null) + return null; + $obj->deleted = true; + $obj->save(); + return null; + } - public static function importFromReceivedObject(\stdClass $data, bool $autoSave = true): static { $obj = static::createFromJson($data, $autoSave); if ($autoSave) { $obj->save(); @@ -13,4 +26,31 @@ abstract class PushableModel extends FetchableModel implements \JsonSerializable } return $obj; } + + /** + * @return Instance[] a list of instances who this object should be pushed to + */ + protected abstract function getRelevantServers(): array; + + /** + * Sends this object to all instances it's relevant to. + * + * Please don't call this on non-local objects :3 + * @return void + */ + public function publish() { + foreach ($this->getRelevantServers() as $instance) { + (new PushObject($this, $instance))->submit(); + } + } + + /** + * Marks this object as deleted and publishes a tombstone in its place. + * @return void + */ + public function markDeleted() { + $this->deleted = true; + $this->save(); + $this->publish(); + } } \ No newline at end of file -- cgit v1.3