[PLUGIN][ActivityPub] Simplify DB usage

This commit is contained in:
2022-02-18 17:48:06 +00:00
parent 9523927b8e
commit 51cccd0155
14 changed files with 122 additions and 116 deletions

View File

@@ -261,7 +261,10 @@ class ActivitypubActor extends Entity
'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
],
'primary key' => ['actor_id'],
'primary key' => ['uri'],
'unique keys' => [
'activitypub_actor_id_ukey' => ['actor_id'],
],
'foreign keys' => [
'activitypub_actor_actor_id_fkey' => ['actor', ['actor_id' => 'id']],
],

View File

@@ -147,7 +147,7 @@ class ActivitypubRsa extends Entity
*/
public static function getByActor(Actor $gsactor, bool $fetch = true): self
{
$apRSA = self::getByPK(['actor_id' => ($actor_id = $gsactor->getId())]);
$apRSA = DB::findOneBy(self::class, ['actor_id' => ($actor_id = $gsactor->getId())], return_null: true);
if (\is_null($apRSA)) {
// Nonexistent key pair for this profile
if ($gsactor->getIsLocal()) {
@@ -157,7 +157,7 @@ class ActivitypubRsa extends Entity
'private_key' => $private_key,
'public_key' => $public_key,
]);
DB::wrapInTransaction(fn () => DB::persist($apRSA));
DB::persist($apRSA);
} else {
// ASSERT: This should never happen, but try to recover!
Log::error('Activitypub_rsa: An impossible thing has happened... Please let the devs know.');