diff options
Diffstat (limited to 'Digitigrade/Model/Actor.php')
| -rw-r--r-- | Digitigrade/Model/Actor.php | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/Digitigrade/Model/Actor.php b/Digitigrade/Model/Actor.php index 62d1b39..2b9a867 100644 --- a/Digitigrade/Model/Actor.php +++ b/Digitigrade/Model/Actor.php @@ -1,6 +1,7 @@ <?php namespace Digitigrade\Model; +use Digitigrade\Db; use Digitigrade\Notification\PendingFollowActionedNotif; use Digitigrade\Notification\UnblockNotif; use Digitigrade\Notification\UnfollowNotif; @@ -76,6 +77,37 @@ class Actor extends PushableModel implements RpcReceiver { return null; } + protected function hydrate() { + $this->endpoints = ActorEndpoints::findWhere('actor_id = ?', [$this->id]); + $this->extensions = $this->findExtensions(); + } + + protected function dehydrate() { + $this->saveExtensions(); + } + + private function findExtensions() { + $pdo = Db::getInstance()->getPdo(); + $stmt = $pdo->prepare('SELECT uri, data FROM actor_extension WHERE actor_id = ?'); + $stmt->execute([$this->id]); + $items = []; + while ($row = $stmt->fetch()) { + $items[$row['uri']] = json_decode($row['data']); + } + return $items; + } + + private function saveExtensions() { + $pdo = Db::getInstance()->getPdo(); + foreach ($this->extensions as $uri => $obj) { + $stmt = $pdo->prepare( + 'INSERT INTO actor_extension(actor_id, uri, data) VALUES (?, ?, ?) ' . + 'ON CONFLICT (actor_id, uri) DO UPDATE SET data = EXCLUDED.data' + ); + $stmt->execute([$this->id, $uri, json_encode($obj)]); + } + } + public static function findLocalByHandle(string $handle): ?self { return self::findWhere('is_local = true AND handle = ?', [$handle]); } @@ -323,8 +355,4 @@ class Actor extends PushableModel implements RpcReceiver { ] ]; } - - public function hydrate() { - $this->endpoints = ActorEndpoints::findWhere('actor_id = ?', [$this->id]); - } } |
