[Actor] Refactor GSActor into Actor

This commit is contained in:
Diogo Peralta Cordeiro 2021-09-18 03:22:27 +01:00
parent 6c899b7b61
commit 941cbe6599
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
73 changed files with 489 additions and 484 deletions

View File

@ -51,7 +51,7 @@ foreach ($files as $file) {
foreach ($schema['fields'] as $field => $opts) {
if (isset($opts['foreign key'])) {
[$foreign_entity, $foreign_key] = explode('.', $opts['target']);
$foreign_table = Formatting::camelCaseToSnakeCase(preg_replace('/GSActor/', 'gsactor', $foreign_entity));
$foreign_table = Formatting::camelCaseToSnakeCase(preg_replace('/Actor/', 'actor', $foreign_entity));
$edges[] = "{$table}:{$field} -- {$foreign_table}:{$foreign_key}";
}
}

View File

@ -50,7 +50,7 @@ foreach ($files as $file) {
$nullable = !@$schema['fields'][$field]['not null'] ? '?' : '';
$type = types[$schema['fields'][$field]['type']];
$type = $type !== '' ? $nullable . $type : $type;
$method_name = str_replace([' ', 'Gsactor'], ['', 'GSActor'], ucwords(str_replace('_', ' ', $field)));
$method_name = str_replace([' ', 'actor'], ['', 'Actor'], ucwords(str_replace('_', ' ', $field)));
$default = @$schema['fields'][$field]['default'];
if (isset($default) && $nullable != '?' && $type != '\DateTimeInterface') {

View File

@ -38,7 +38,7 @@ class Avatar extends Component
public function onAddRoute($r): bool
{
$r->connect('avatar', '/actor/{gsactor_id<\d+>}/avatar/{size<full|big|medium|small>?full}', [Controller\Avatar::class, 'avatar_view']);
$r->connect('avatar', '/actor/{actor_id<\d+>}/avatar/{size<full|big|medium|small>?full}', [Controller\Avatar::class, 'avatar_view']);
$r->connect('settings_avatar', '/settings/avatar', [Controller\Avatar::class, 'settings_avatar']);
return Event::next;
}
@ -63,64 +63,64 @@ class Avatar extends Component
return Event::next;
}
public function onGetAvatarUrl(int $gsactor_id, ?string &$url): bool
public function onGetAvatarUrl(int $actor_id, ?string &$url): bool
{
$url = self::getAvatarUrl($gsactor_id);
$url = self::getAvatarUrl($actor_id);
return Event::next;
}
public function onAvatarUpdate(int $gsactor_id): bool
public function onAvatarUpdate(int $actor_id): bool
{
Cache::delete('avatar-' . $gsactor_id);
Cache::delete('avatar-url-' . $gsactor_id);
Cache::delete('avatar-file-info-' . $gsactor_id);
Cache::delete('avatar-' . $actor_id);
Cache::delete('avatar-url-' . $actor_id);
Cache::delete('avatar-file-info-' . $actor_id);
return Event::next;
}
// UTILS ----------------------------------
/**
* Get the avatar associated with the given GSActor id
* Get the avatar associated with the given Actor id
*/
public static function getAvatar(?int $gsactor_id = null): Entity\Avatar
public static function getAvatar(?int $actor_id = null): Entity\Avatar
{
$gsactor_id = $gsactor_id ?: Common::userId();
$actor_id = $actor_id ?: Common::userId();
return GSFile::error(NoAvatarException::class,
$gsactor_id,
Cache::get("avatar-{$gsactor_id}",
function () use ($gsactor_id) {
$actor_id,
Cache::get("avatar-{$actor_id}",
function () use ($actor_id) {
return DB::dql('select a from Component\Avatar\Entity\Avatar a ' .
'where a.gsactor_id = :gsactor_id',
['gsactor_id' => $gsactor_id]);
'where a.actor_id = :actor_id',
['actor_id' => $actor_id]);
}));
}
/**
* Get the cached avatar associated with the given GSActor id, or the current user if not given
* Get the cached avatar associated with the given Actor id, or the current user if not given
*/
public static function getAvatarUrl(?int $gsactor_id = null, string $size = 'full'): string
public static function getAvatarUrl(?int $actor_id = null, string $size = 'full'): string
{
$gsactor_id = $gsactor_id ?: Common::userId();
return Cache::get("avatar-url-{$gsactor_id}", function () use ($gsactor_id) {
return Router::url('avatar', ['gsactor_id' => $gsactor_id, 'size' => 'full']);
$actor_id = $actor_id ?: Common::userId();
return Cache::get("avatar-url-{$actor_id}", function () use ($actor_id) {
return Router::url('avatar', ['actor_id' => $actor_id, 'size' => 'full']);
});
}
/**
* Get the cached avatar file info associated with the given GSActor id
* Get the cached avatar file info associated with the given Actor id
*
* Returns the avatar file's hash, mimetype, title and path.
* Ensures exactly one cached value exists
*/
public static function getAvatarFileInfo(int $gsactor_id): array
public static function getAvatarFileInfo(int $actor_id): array
{
$res = Cache::get("avatar-file-info-{$gsactor_id}",
function () use ($gsactor_id) {
$res = Cache::get("avatar-file-info-{$actor_id}",
function () use ($actor_id) {
return DB::dql('select f.id, f.filename, a.filename title, f.mimetype ' .
'from App\Entity\Attachment f ' .
'join Component\Avatar\Entity\Avatar a with f.id = a.attachment_id ' .
'where a.gsactor_id = :gsactor_id',
['gsactor_id' => $gsactor_id]);
'where a.actor_id = :actor_id',
['actor_id' => $actor_id]);
}
);
if ($res === []) { // Avatar not found

View File

@ -48,11 +48,11 @@ class Avatar extends Controller
/**
* @throws Exception
*/
public function avatar_view(Request $request, int $gsactor_id, string $size): Response
public function avatar_view(Request $request, int $actor_id, string $size): Response
{
switch ($size) {
case 'full':
$res = \Component\Avatar\Avatar::getAvatarFileInfo($gsactor_id);
$res = \Component\Avatar\Avatar::getAvatarFileInfo($actor_id);
return M::sendFile($res['filepath'], $res['mimetype'], $res['title']);
default:
throw new Exception('Not implemented');
@ -74,12 +74,12 @@ class Avatar extends Controller
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$user = Common::user();
$gsactor_id = $user->getId();
$data = $form->getData();
$user = Common::user();
$actor_id = $user->getId();
if ($data['remove'] == true) {
try {
$avatar = DB::findOneBy('avatar', ['gsactor_id' => $gsactor_id]);
$avatar = DB::findOneBy('avatar', ['actor_id' => $actor_id]);
$avatar->delete();
Event::handle('AvatarUpdate', [$user->getId()]);
} catch (NotFoundException) {
@ -109,12 +109,12 @@ class Avatar extends Controller
throw new ClientException('Invalid form');
}
// Delete current avatar if there's one
$avatar = DB::find('avatar', ['gsactor_id' => $gsactor_id]);
$avatar = DB::find('avatar', ['actor_id' => $actor_id]);
$avatar?->delete();
DB::persist($attachment);
// Can only get new id after inserting
DB::flush();
DB::persist(AvatarEntity::create(['gsactor_id' => $gsactor_id, 'attachment_id' => $attachment->getId()]));
DB::persist(AvatarEntity::create(['actor_id' => $actor_id, 'attachment_id' => $attachment->getId()]));
DB::flush();
Event::handle('AvatarUpdate', [$user->getId()]);
}

View File

@ -46,21 +46,21 @@ class Avatar extends Entity
{
// {{{ Autocode
// @codeCoverageIgnoreStart
private int $gsactor_id;
private int $actor_id;
private int $attachment_id;
private ?string $filename;
private DateTimeInterface $created;
private DateTimeInterface $modified;
public function setGSActorId(int $gsactor_id): self
public function setActorId(int $actor_id): self
{
$this->gsactor_id = $gsactor_id;
$this->actor_id = $actor_id;
return $this;
}
public function getGSActorId(): int
public function getActorId(): int
{
return $this->gsactor_id;
return $this->actor_id;
}
public function setAttachmentId(int $attachment_id): self
@ -119,7 +119,7 @@ class Avatar extends Entity
public function getUrl(): string
{
return Router::url('avatar', ['gsactor_id' => $this->gsactor_id]);
return Router::url('avatar', ['actor_id' => $this->actor_id]);
}
public function getAttachment(): Attachment
@ -157,13 +157,13 @@ class Avatar extends Entity
return [
'name' => 'avatar',
'fields' => [
'gsactor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'GSActor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to gsactor table'],
'actor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to actor table'],
'attachment_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Attachment.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to attachment table'],
'filename' => ['type' => 'varchar', 'length' => 191, 'description' => 'file name of resource when available'],
'created' => ['type' => 'datetime', 'not null' => true, 'description' => 'date this record was created', 'default' => 'CURRENT_TIMESTAMP'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified', 'default' => 'CURRENT_TIMESTAMP'],
],
'primary key' => ['gsactor_id'],
'primary key' => ['actor_id'],
'indexes' => [
'avatar_attachment_id_idx' => ['attachment_id'],
],

View File

@ -27,8 +27,8 @@ use App\Core\Event;
use App\Core\Form;
use function App\Core\I18n\_m;
use App\Core\Modules\Component;
use App\Entity\Actor;
use App\Entity\Attachment;
use App\Entity\GSActor;
use App\Entity\Note;
use App\Util\Common;
use App\Util\Exception\ClientException;
@ -60,7 +60,7 @@ class Posting extends Component
$actor_id = $user->getId();
$to_tags = [];
$tags = Cache::get("actor-circle-{$actor_id}",
fn () => DB::dql('select c.tag from App\Entity\GSActorCircle c where c.tagger = :tagger', ['tagger' => $actor_id]));
fn () => DB::dql('select c.tag from App\Entity\ActorCircle c where c.tagger = :tagger', ['tagger' => $actor_id]));
foreach ($tags as $t) {
$t = $t['tag'];
$to_tags[$t] = $t;
@ -109,12 +109,12 @@ class Posting extends Component
return Event::next;
}
public static function storeLocalNote(GSActor $actor, string $content, string $content_type, array $attachments, ?Note $reply_to = null, ?Note $repeat_of = null)
public static function storeLocalNote(Actor $actor, string $content, string $content_type, array $attachments, ?Note $reply_to = null, ?Note $repeat_of = null)
{
$rendered = null;
Event::handle('RenderNoteContent', [$content, $content_type, &$rendered, $actor, $reply_to]);
$note = Note::create([
'gsactor_id' => $actor->getId(),
'actor_id' => $actor->getId(),
'content' => $content,
'content_type' => $content_type,
'rendered' => $rendered,
@ -125,7 +125,7 @@ class Posting extends Component
DB::flush();
}
public function onRenderNoteContent(string $content, string $content_type, ?string &$rendered, GSActor $author, ?Note $reply_to = null)
public function onRenderNoteContent(string $content, string $content_type, ?string &$rendered, Actor $author, ?Note $reply_to = null)
{
if ($content_type === 'text/plain') {
$content = Formatting::renderPlainText($content);

View File

@ -22,7 +22,7 @@ Store
```php
/**
* Get the cached avatar file info associated with the given GSActor id
* Get the cached avatar file info associated with the given Actor id
*
* Returns the avatar file's hash, mimetype, title and path.
* Ensures exactly one cached value exists

View File

@ -42,19 +42,19 @@ class ActivityStreamsTwo extends Plugin
switch ($route) {
case 'actor_view_id':
case 'actor_view_nickname':
$response = ActorResponse::handle($vars['gsactor']);
$response = ActorResponse::handle($vars['actor']);
return Event::stop;
case 'note_view':
$response = NoteResponse::handle($vars['note']);
return Event::stop;
case 'actor_favourites':
$response = LikeResponse::handle($vars['gsactor']);
$response = LikeResponse::handle($vars['actor']);
return Event::stop;
case 'actor_subscriptions':
$response = FollowingResponse::handle($vars['gsactor']);
$response = FollowingResponse::handle($vars['actor']);
return Event::stop;
case 'actor_subscribers':
$response = FollowersResponse::handle($vars['gsactor']);
$response = FollowersResponse::handle($vars['actor']);
return Event::stop;
default:
return Event::next;

View File

@ -3,7 +3,7 @@
namespace Plugin\ActivityStreamsTwo\Util\Model\EntityToType;
use App\Core\Router\Router;
use App\Entity\GSActor;
use App\Entity\Actor;
use DateTimeInterface;
use Exception;
use Plugin\ActivityStreamsTwo\Util\Type;
@ -11,13 +11,14 @@ use Plugin\ActivityStreamsTwo\Util\Type;
class GSActorToType
{
/**
* @param GSActor $gsactor
* @param Actor $gsactor
*
* @throws Exception
*@throws Exception
*
* @return Type
*
*/
public static function translate(GSActor $gsactor)
public static function translate(Actor $gsactor)
{
$uri = Router::url('actor_view_id', ['id' => $gsactor->getId()], Router::ABSOLUTE_URL);
$attr = [

View File

@ -2,21 +2,22 @@
namespace Plugin\ActivityStreamsTwo\Util\Response;
use App\Entity\GSActor;
use App\Entity\Actor;
use Exception;
use Plugin\ActivityStreamsTwo\Util\Model\EntityToType\GSActorToType;
abstract class ActorResponse
{
/**
* @param GSActor $gsactor
* @param int $status The response status code
* @param Actor $gsactor
* @param int $status The response status code
*
* @throws Exception
*@throws Exception
*
* @return TypeResponse
*
*/
public static function handle(GSActor $gsactor, int $status = 200): TypeResponse
public static function handle(Actor $gsactor, int $status = 200): TypeResponse
{
$gsactor->getLocalUser(); // This throws exception if not a local user, which is intended
return new TypeResponse(data: GSActorToType::translate($gsactor), status: $status);

View File

@ -98,7 +98,7 @@ class Cover
}
$file = GSFile::sanitizeAndStoreFileAsAttachment($sfile);
$old_file = null;
$cover = DB::find('cover', ['gsactor_id' => $actor_id]);
$cover = DB::find('cover', ['gctor_id' => $actor_id]);
// Must get old id before inserting another one
if ($cover != null) {
$old_file = $cover->delete();
@ -107,7 +107,7 @@ class Cover
DB::persist($file);
// Can only get new id after inserting
DB::flush();
$cover = CoverEntity::create(['gsactor_id' => $actor_id, 'file_id' => $file->getId()]);
$cover = CoverEntity::create(['actor_id' => $actor_id, 'file_id' => $file->getId()]);
DB::persist($cover);
DB::flush();
// Only delete files if the commit went through
@ -118,7 +118,7 @@ class Cover
}
$removeForm = null;
$cover = DB::find('cover', ['gsactor_id' => $actor_id]);
$cover = DB::find('cover', ['actor_id' => $actor_id]);
if ($cover != null) {
$form2 = Form::create([
['remove', SubmitType::class, ['label' => _m('Remove')]],
@ -143,7 +143,7 @@ class Cover
*/
public function cover()
{
// $cover = DB::find('cover', ['gsactor_id' => Common::user()->getId()]);
// $cover = DB::find('cover', ['actor_id' => Common::user()->getId()]);
// if ($cover == null) {
// return new Response('Cover not found',Response::HTTP_NOT_FOUND);
// }

View File

@ -75,7 +75,7 @@ class Cover extends Plugin
public function onStartTwigPopulateVars(array &$vars): bool
{
/*if (Common::user() != null) {
$cover = DB::find('cover', ['gsactor_id' => Common::user()->getId()]);
$cover = DB::find('cover', ['actor_id' => Common::user()->getId()]);
if ($cover != null) {
$vars['profile_extras'][] = ['name' => 'cover', 'vars' => ['img' => '/cover']];
} else {

View File

@ -41,20 +41,20 @@ class Cover extends Entity
{
// {{{ Autocode
// @codeCoverageIgnoreStart
private int $gsactor_id;
private int $actor_id;
private int $attachment_id;
private \DateTimeInterface $created;
private \DateTimeInterface $modified;
public function setGSActorId(int $gsactor_id): self
public function setActorId(int $actor_id): self
{
$this->gsactor_id = $gsactor_id;
$this->actor_id = $actor_id;
return $this;
}
public function getGSActorId(): int
public function getActorId(): int
{
return $this->gsactor_id;
return $this->actor_id;
}
public function setAttachmentId(int $attachment_id): self
@ -131,7 +131,7 @@ class Cover extends Entity
if (!$cascading) {
$attachments = $this->getAttachment()->kill();
} else {
DB::remove(DB::getReference('cover', ['gsactor_id' => $this->gsactor_id]));
DB::remove(DB::getReference('cover', ['actor_id' => $this->actor_id]));
$attachment_path = $this->getAttachmentPath();
$attachments[] = $attachment_path;
if ($flush) {
@ -147,12 +147,12 @@ class Cover extends Entity
return [
'name' => 'cover',
'fields' => [
'gsactor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'GSActor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to gsactor table'],
'actor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to actor table'],
'attachment_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Attachment.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to attachment table'],
'created' => ['type' => 'datetime', 'not null' => true, 'description' => 'date this record was created', 'default' => 'CURRENT_TIMESTAMP'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified', 'default' => 'CURRENT_TIMESTAMP'],
],
'primary key' => ['gsactor_id'],
'primary key' => ['actor_id'],
'indexes' => [
'cover_attachment_id_idx' => ['attachment_id'],
],

View File

@ -35,7 +35,7 @@ class Directory
*/
public function actors(Request $request)
{
return ['_template' => 'directory/actors.html.twig', 'actors' => DB::dql('select g from App\Entity\GSActor g order by g.nickname ASC')];
return ['_template' => 'directory/actors.html.twig', 'actors' => DB::dql('select g from App\Entity\Actor g order by g.nickname ASC')];
}
/**

View File

@ -32,7 +32,7 @@ class Favourite
$notes = DB::dql(
'select n from App\Entity\Note n, Plugin\Favourite\Entity\Favourite f ' .
'where n.id = f.note_id ' .
'and f.gsactor_id = :id ' .
'and f.actor_id = :id ' .
'order by f.created DESC',
['id' => $id]
);
@ -64,8 +64,8 @@ class Favourite
{
$notes = DB::dql('select n from App\Entity\Note n, Plugin\Favourite\Entity\Favourite f ' .
'where n.id = f.note_id ' .
'and f.gsactor_id != :id ' .
'and n.gsactor_id = :id ' .
'and f.actor_id != :id ' .
'and n.actor_id = :id ' .
'order by f.created DESC' ,
['id' => $id]
);

View File

@ -27,7 +27,7 @@ class Favourite extends Entity
// {{{ Autocode
// @codeCoverageIgnoreStart
private int $note_id;
private int $gsactor_id;
private int $actor_id;
private \DateTimeInterface $created;
private \DateTimeInterface $modified;
@ -42,15 +42,15 @@ class Favourite extends Entity
return $this->note_id;
}
public function setGSActorId(int $gsactor_id): self
public function setActorId(int $actor_id): self
{
$this->gsactor_id = $gsactor_id;
$this->actor_id = $actor_id;
return $this;
}
public function getGSActorId(): int
public function getActorId(): int
{
return $this->gsactor_id;
return $this->actor_id;
}
public function setCreated(DateTimeInterface $created): self
@ -83,15 +83,15 @@ class Favourite extends Entity
return [
'name' => 'favourite',
'fields' => [
'note_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'App\Entity\Note.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'note that is the favorite of'],
'gsactor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'App\Entity\GSActor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'actor who favourited this note'], // note: formerly referenced notice.id, but we can now record remote users' favorites
'created' => ['type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'],
'note_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'App\Entity\Note.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'note that is the favorite of'],
'actor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'App\Entity\Actor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'actor who favourited this note'], // note: formerly referenced notice.id, but we can now record remote users' favorites
'created' => ['type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'],
],
'primary key' => ['note_id', 'gsactor_id'],
'primary key' => ['note_id', 'actor_id'],
'indexes' => [
'fave_note_id_idx' => ['note_id'],
'fave_actor_id_idx' => ['gsactor_id', 'modified'],
'fave_actor_id_idx' => ['actor_id', 'modified'],
'fave_modified_idx' => ['modified'],
],
];

View File

@ -61,7 +61,7 @@ class Favourite extends NoteHandlerPlugin
}
// if note is favoured, "is_set" is 1
$opts = ['note_id' => $note->getId(), 'gsactor_id' => $user->getId()];
$opts = ['note_id' => $note->getId(), 'actor_id' => $user->getId()];
$is_set = DB::find('favourite', $opts) !== null;
$form_fav = Form::create([
['submit_favourite', SubmitType::class,

View File

@ -65,8 +65,8 @@ class FileQuota extends Plugin
$query = <<<END
select sum(at.size) as total
from attachment at
join gsactor_to_attachment ua with at.id = ua.attachment_id
where ua.gsactor_id = :actor_id and at.size is not null
join actor_to_attachment ua with at.id = ua.attachment_id
where ua.actor_id = :actor_id and at.size is not null
END;
$max_file_size = Common::config('attachments', 'file_quota');

View File

@ -82,7 +82,7 @@ class AnswerPoll
if (PollResponse::exits($poll->getId(), $user->getId())) {
throw new ServerException('User already responded to poll');
}
$pollResponse = PollResponse::create(['poll_id' => $poll->getId(), 'gsactor_id' => $user->getId(), 'selection' => $selection]);
$pollResponse = PollResponse::create(['poll_id' => $poll->getId(), 'actor_id' => $user->getId(), 'selection' => $selection]);
DB::persist($pollResponse);
DB::flush();

View File

@ -83,7 +83,7 @@ class NewPoll
if ($form->isValid()) {
$data = $form->getData();
$note = Note::create(['gsactor_id' => $user->getId(), $is_local = true]);
$note = Note::create(['actor_id' => $user->getId(), $is_local = true]);
DB::persist($note);
Security::sanitize($question = $data['Question']);
@ -92,7 +92,7 @@ class NewPoll
}
$options = implode("\n",$opt);
$poll = Poll::create(['gsactor_id' => $user->getId(), 'question' => $question, 'options' => $options, 'note_id' => $note->getId()]);
$poll = Poll::create(['actor_id' => $user->getId(), 'question' => $question, 'options' => $options, 'note_id' => $note->getId()]);
DB::persist($poll);
DB::flush();
throw new RedirectException('root');

View File

@ -41,7 +41,7 @@ class Poll extends Entity
// @codeCoverageIgnoreStart
private int $id;
private ?string $uri;
private ?int $gsactor_id;
private ?int $actor_id;
private int $note_id;
private ?string $question;
private ?string $options;
@ -70,15 +70,15 @@ class Poll extends Entity
return $this->uri;
}
public function setGSActorId(?int $gsactor_id): self
public function setActorId(?int $actor_id): self
{
$this->gsactor_id = $gsactor_id;
$this->actor_id = $actor_id;
return $this;
}
public function getGSActorId(): ?int
public function getActorId(): ?int
{
return $this->gsactor_id;
return $this->actor_id;
}
public function setNoteId(int $note_id): self
@ -150,14 +150,14 @@ class Poll extends Entity
'name' => 'poll',
'description' => 'Per-notice poll data for Poll plugin',
'fields' => [
'id' => ['type' => 'serial', 'not null' => true],
'uri' => ['type' => 'varchar', 'length' => 191],
'gsactor_id' => ['type' => 'int'],
'note_id' => ['type' => 'int', 'not null' => true],
'question' => ['type' => 'text'],
'options' => ['type' => 'text'],
'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'],
'id' => ['type' => 'serial', 'not null' => true],
'uri' => ['type' => 'varchar', 'length' => 191],
'actor_id' => ['type' => 'int'],
'note_id' => ['type' => 'int', 'not null' => true],
'question' => ['type' => 'text'],
'options' => ['type' => 'text'],
'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' => ['id'],
'unique keys' => [

View File

@ -42,7 +42,7 @@ class PollResponse extends Entity
private int $id;
private ?string $uri;
private int $poll_id;
private ?int $gsactor_id;
private ?int $actor_id;
private ?int $selection;
private \DateTimeInterface $created;
private \DateTimeInterface $modified;
@ -80,15 +80,15 @@ class PollResponse extends Entity
return $this->poll_id;
}
public function setGSActorId(?int $gsactor_id): self
public function setActorId(?int $actor_id): self
{
$this->gsactor_id = $gsactor_id;
$this->actor_id = $actor_id;
return $this;
}
public function getGSActorId(): ?int
public function getActorId(): ?int
{
return $this->gsactor_id;
return $this->actor_id;
}
public function setSelection(?int $selection): self
@ -140,25 +140,25 @@ class PollResponse extends Entity
'fields' => [
'id' => ['type' => 'serial', 'not null' => true],
//'uri' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'UUID to the response notice'),
'uri' => ['type' => 'varchar', 'length' => 191, 'description' => 'UUID to the response notice'],
'poll_id' => ['type' => 'int', 'length' => 36, 'not null' => true, 'description' => 'UUID of poll being responded to'],
'gsactor_id' => ['type' => 'int'],
'selection' => ['type' => 'int'],
'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'],
'uri' => ['type' => 'varchar', 'length' => 191, 'description' => 'UUID to the response notice'],
'poll_id' => ['type' => 'int', 'length' => 36, 'not null' => true, 'description' => 'UUID of poll being responded to'],
'actor_id' => ['type' => 'int'],
'selection' => ['type' => 'int'],
'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' => ['id'],
'unique keys' => [
//'poll_uri_key' => array('uri'),
//'poll_response_poll_id_gsactor_id_key' => ['poll_id', 'gsactor_id'], //doctrine bug?
//'poll_response_poll_id_actor_id_key' => ['poll_id', 'actor_id'], //doctrine bug?
],
'foreign keys' => [
'foreign_poll' => ['poll', ['poll_id' => 'id']],
],
'indexes' => [
'poll_response_gsactor_id_poll_id_index' => ['gsactor_id', 'poll_id'],
'poll_response_actor_id_poll_id_index' => ['actor_id', 'poll_id'],
],
];
}
@ -167,15 +167,15 @@ class PollResponse extends Entity
* Checks if a user already responded to the poll
*
* @param int $pollId
* @param int $gsactorId user
* @param int $actorId user
*
* @return bool
*/
public static function exits(int $pollId, int $gsactorId): bool
public static function exits(int $pollId, int $actorId): bool
{
$res = DB::dql('select pr from App\Entity\PollResponse pr
where pr.poll_id = :pollId and pr.gsactor_id = :gsactorId',
['pollId' => $pollId, 'gsactorId' => $gsactorId]);
where pr.poll_id = :pollId and pr.actor_id = :actorId',
['pollId' => $pollId, 'actorId' => $actorId]);
return count($res) != 0;
}
}

View File

@ -153,7 +153,7 @@ class Poll extends NoteHandlerPlugin
if (Entity\PollResponse::exits($poll->getId(), $user->getId())) {
throw new ServerException('User already responded to poll');
}
$pollResponse = Entity\PollResponse::create(['poll_id' => $poll->getId(), 'gsactor_id' => $user->getId(), 'selection' => $selection]);
$pollResponse = Entity\PollResponse::create(['poll_id' => $poll->getId(), 'actor_id' => $user->getId(), 'selection' => $selection]);
DB::persist($pollResponse);
DB::flush();

View File

@ -57,7 +57,7 @@ class ProfileColor
{
$user = Common::user();
$actor_id = $user->getId();
$pcolor = DB::find('profile_color', ['gsactor_id' => $actor_id]);
$pcolor = DB::find('profile_color', ['actor_id' => $actor_id]);
$color = '#000000';
if ($pcolor != null) {
$color = $pcolor->getColor();
@ -78,7 +78,7 @@ class ProfileColor
DB::flush();
}
$pcolor = Entity\ProfileColor::create(['gsactor_id' => $actor_id, 'color' => $data['color']]);
$pcolor = Entity\ProfileColor::create(['actor_id' => $actor_id, 'color' => $data['color']]);
DB::persist($pcolor);
DB::flush();
throw new RedirectException();

View File

@ -38,20 +38,20 @@ class ProfileColor extends Entity
{
// {{{ Autocode
// @codeCoverageIgnoreStart
private int $gsactor_id;
private int $actor_id;
private string $color;
private \DateTimeInterface $created;
private \DateTimeInterface $modified;
public function setGSActorId(int $gsactor_id): self
public function setActorId(int $actor_id): self
{
$this->gsactor_id = $gsactor_id;
$this->actor_id = $actor_id;
return $this;
}
public function getGSActorId(): int
public function getActorId(): int
{
return $this->gsactor_id;
return $this->actor_id;
}
public function setColor(string $color): self
@ -94,12 +94,12 @@ class ProfileColor extends Entity
return [
'name' => 'profile_color',
'fields' => [
'gsactor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'GSActor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to gsactor table'],
'color' => ['type' => 'text', 'not null' => true, 'description' => 'color hex code'],
'created' => ['type' => 'datetime', 'not null' => true, 'description' => 'date this record was created', 'default' => 'CURRENT_TIMESTAMP'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified', 'default' => 'CURRENT_TIMESTAMP'],
'actor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to actor table'],
'color' => ['type' => 'text', 'not null' => true, 'description' => 'color hex code'],
'created' => ['type' => 'datetime', 'not null' => true, 'description' => 'date this record was created', 'default' => 'CURRENT_TIMESTAMP'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified', 'default' => 'CURRENT_TIMESTAMP'],
],
'primary key' => ['gsactor_id'],
'primary key' => ['actor_id'],
];
}
}

View File

@ -80,7 +80,7 @@ class ProfileColor extends Plugin
'path' => 'profilecolor/profilecolor.html.twig',
];*/
if (Common::user() != null) {
$color = DB::find('profile_color', ['gsactor_id' => Common::user()->getId()]);
$color = DB::find('profile_color', ['actor_id' => Common::user()->getId()]);
if ($color != null) {
$vars['profile_extras'][] = ['name' => 'profilecolor', 'vars' => ['color' => $color->getColor()]];
}

View File

@ -22,6 +22,7 @@ namespace Plugin\Repeat;
use App\Core\DB\DB;
use App\Core\Event;
use App\Core\Form;
use function App\Core\I18n\_m;
use App\Core\Modules\NoteHandlerPlugin;
use App\Entity\Note;
use App\Util\Common;
@ -29,7 +30,6 @@ use App\Util\Exception\RedirectException;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;
use function App\Core\I18n\_m;
class Repeat extends NoteHandlerPlugin
{
@ -45,7 +45,7 @@ class Repeat extends NoteHandlerPlugin
return Event::next;
}
$opts = ['gsactor_id' => $user->getId(), 'repeat_of' => $note->getId()];
$opts = ['actor_id' => $user->getId(), 'repeat_of' => $note->getId()];
$is_set = DB::count('note', $opts) == 1;
$form_repeat = Form::create([
['submit_repeat', SubmitType::class,
@ -66,13 +66,13 @@ class Repeat extends NoteHandlerPlugin
$request, $form_repeat, $note, "repeat-{$note->getId()}", function ($note, $data, $user) {
if ($data["repeat-{$note->getId()}"] === '0') {
DB::persist(Note::create([
'gsactor_id' => $user->getId(),
'repeat_of' => $note->getId(),
'content' => $note->getContent(),
'is_local' => true,
'actor_id' => $user->getId(),
'repeat_of' => $note->getId(),
'content' => $note->getContent(),
'is_local' => true,
]));
} else {
DB::remove(DB::findOneBy('note', ['gsactor_id' => $user->getId(), 'repeat_of' => $note->getId()]));
DB::remove(DB::findOneBy('note', ['actor_id' => $user->getId(), 'repeat_of' => $note->getId()]));
}
DB::flush();

View File

@ -27,43 +27,43 @@ use function App\Core\I18n\_m;
use App\Util\Exception\ClientException;
use Symfony\Component\HttpFoundation\Request;
class GSActor extends Controller
class Actor extends Controller
{
/**
* Generic function that handles getting a representation for an actor from id
*/
private function GSActorById(int $id, callable $handle)
private function ActorById(int $id, callable $handle)
{
$gsactor = DB::findOneBy('gsactor', ['id' => $id]);
if (empty($gsactor)) {
$actor = DB::findOneBy('actor', ['id' => $id]);
if (empty($actor)) {
throw new ClientException(_m('No such actor.'), 404);
} else {
return $handle($gsactor);
return $handle($actor);
}
}
/**
* Generic function that handles getting a representation for an actor from nickname
*/
private function GSActorByNickname(string $nickname, callable $handle)
private function ActorByNickname(string $nickname, callable $handle)
{
$user = DB::findOneBy('local_user', ['nickname' => $nickname]);
$gsactor = DB::findOneBy('gsactor', ['id' => $user->getId()]);
if (empty($gsactor)) {
$user = DB::findOneBy('local_user', ['nickname' => $nickname]);
$actor = DB::findOneBy('actor', ['id' => $user->getId()]);
if (empty($actor)) {
throw new ClientException(_m('No such actor.'), 404);
} else {
return $handle($gsactor);
return $handle($actor);
}
}
/**
* The page where the actor's info is shown
*/
public function GSActorShowId(Request $request, int $id)
public function ActorShowId(Request $request, int $id)
{
return $this->GSActorById($id, fn ($gsactor) => ['_template' => 'actor/view.html.twig', 'gsactor' => $gsactor]);
return $this->ActorById($id, fn ($actor) => ['_template' => 'actor/view.html.twig', 'actor' => $actor]);
}
public function GSActorShowNickname(Request $request, string $nickname)
public function ActorShowNickname(Request $request, string $nickname)
{
return $this->GSActorByNickname($nickname, fn ($gsactor) => ['_template' => 'actor/view.html.twig', 'gsactor' => $gsactor]);
return $this->ActorByNickname($nickname, fn ($actor) => ['_template' => 'actor/view.html.twig', 'actor' => $actor]);
}
}

View File

@ -68,7 +68,7 @@ class Network extends Controller
public function home(Request $request, string $nickname)
{
try {
$target = DB::findOneBy('gsactor', ['nickname' => $nickname]);
$target = DB::findOneBy('actor', ['nickname' => $nickname]);
} catch (NotFoundException) {
throw new ClientException(_m('User {nickname} doesn\'t exist', ['{nickname}' => $nickname]));
}
@ -78,7 +78,7 @@ class Network extends Controller
select note.* from note left join -- left join ensures all returned notes' ids are not null
(
-- Followed by target
select n.id from note n inner join follow f on n.gsactor_id = f.followed
select n.id from note n inner join follow f on n.actor_id = f.followed
where f.follower = :target_actor_id
union all
-- Replies to notes by target
@ -89,7 +89,7 @@ class Network extends Controller
union all
-- Notes in groups target follows
select gi.activity_id from group_inbox gi inner join group_member gm on gi.group_id = gm.group_id
where gm.gsactor_id = :target_actor_id
where gm.actor_id = :target_actor_id
)
as s on s.id = note.id
where
@ -125,7 +125,7 @@ END;
{
$actor_id = Common::ensureLoggedIn()->getId();
$notes = DB::dql('select n from App\Entity\Note n ' .
'where n.reply_to is not null and n.gsactor_id = :id ' .
'where n.reply_to is not null and n.actor_id = :id ' .
'order by n.created DESC', ['id' => $actor_id]);
$notes_out = null;

View File

@ -5,25 +5,24 @@ namespace App\Controller;
use App\Core\Controller;
use App\Core\DB\DB;
use App\Core\Form;
use App\Util\Exception\DuplicateFoundException;
use App\Util\Exception\NicknameEmptyException;
use App\Util\Exception\NicknameReservedException;
use App\Util\Exception\NicknameTooLongException;
use App\Util\Exception\NicknameTooShortException;
use App\Util\Exception\NotImplementedException;
use Symfony\Component\HttpFoundation\Response;
use function App\Core\I18n\_m;
use App\Core\Log;
use App\Core\VisibilityScope;
use App\Entity\Actor;
use App\Entity\Follow;
use App\Entity\GSActor;
use App\Entity\LocalUser;
use App\Entity\Note;
use App\Security\Authenticator;
use App\Security\EmailVerifier;
use App\Util\Common;
use App\Util\Exception\DuplicateFoundException;
use App\Util\Exception\EmailTakenException;
use App\Util\Exception\NicknameEmptyException;
use App\Util\Exception\NicknameReservedException;
use App\Util\Exception\NicknameTakenException;
use App\Util\Exception\NicknameTooLongException;
use App\Util\Exception\NicknameTooShortException;
use App\Util\Exception\NotImplementedException;
use App\Util\Exception\ServerException;
use App\Util\Form\FormFields;
use App\Util\Nickname;
@ -32,6 +31,7 @@ use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Validator\Constraints\Length;
@ -69,16 +69,15 @@ class Security extends Controller
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
/**
*
* Register a user, making sure the nickname is not reserved and
* possibly sending a confirmation email
*
* @param Request $request
* @param Request $request
* @param GuardAuthenticatorHandler $guard_handler
* @param Authenticator $authenticator
* @return array|Response|null
* @param Authenticator $authenticator
*
* @throws EmailTakenException
* @throws NicknameTakenException
* @throws ServerException
@ -88,10 +87,12 @@ class Security extends Controller
* @throws NicknameTooLongException
* @throws NicknameTooShortException
* @throws NotImplementedException
*
* @return null|array|Response
*/
public function register(Request $request,
public function register(Request $request,
GuardAuthenticatorHandler $guard_handler,
Authenticator $authenticator)
Authenticator $authenticator)
{
$form = Form::create([
['nickname', TextType::class, [
@ -105,16 +106,16 @@ class Security extends Controller
'max' => Nickname::MAX_LEN,
'maxMessage' => _m(['Your nickname must be at most # characters long'], ['count' => Nickname::MAX_LEN]), ]),
],
'block_name' => 'nickname',
'label_attr' => ['class' => 'section-form-label'],
'block_name' => 'nickname',
'label_attr' => ['class' => 'section-form-label'],
'invalid_message' => _m('Nickname not valid. Please provide a valid nickname.'),
]],
['email', EmailType::class, [
'label' => _m('Email'),
'help' => _m('Desired email for this account (e.g., john@provider.com)'),
'constraints' => [ new NotBlank(['message' => _m('Please enter an email') ])],
'block_name' => 'email',
'label_attr' => ['class' => 'section-form-label'],
'label' => _m('Email'),
'help' => _m('Desired email for this account (e.g., john@provider.com)'),
'constraints' => [ new NotBlank(['message' => _m('Please enter an email') ])],
'block_name' => 'email',
'label_attr' => ['class' => 'section-form-label'],
'invalid_message' => _m('Email not valid. Please provide a valid email.'),
]],
FormFields::repeated_password(),
@ -134,11 +135,11 @@ class Security extends Controller
// If we do find something, there's a duplicate
if ($user->getNickname() === $data['nickname']) {
// Register page feedback on nickname already in use
$this->addFlash("verify_nickname_error", _m('Nickname is already in use on this server.'));
$this->addFlash('verify_nickname_error', _m('Nickname is already in use on this server.'));
throw new NicknameTakenException;
} else {
// Register page feedback on email already in use
$this->addFlash("verify_email_error", _m('Email is already taken.'));
$this->addFlash('verify_email_error', _m('Email is already taken.'));
throw new EmailTakenException;
}
}
@ -147,7 +148,7 @@ class Security extends Controller
try {
// This already checks if the nickname is being used
$actor = GSActor::create(['nickname' => $valid_nickname]);
$actor = Actor::create(['nickname' => $valid_nickname]);
$user = LocalUser::create([
'nickname' => $valid_nickname,
'outgoing_email' => $data['email'],

View File

@ -32,38 +32,38 @@ class Subscribers extends Controller
/**
* Generic function that handles getting a representation for an actor from id
*/
private function GSActorById(int $id, callable $handle)
private function ActorById(int $id, callable $handle)
{
$gsactor = DB::findOneBy('gsactor', ['id' => $id]);
if (empty($gsactor)) {
$actor = DB::findOneBy('actor', ['id' => $id]);
if (empty($actor)) {
throw new ClientException(_m('No such actor.'), 404);
} else {
return $handle($gsactor);
return $handle($actor);
}
}
/**
* Generic function that handles getting a representation for an actor from nickname
*/
private function GSActorByNickname(string $nickname, callable $handle)
private function ActorByNickname(string $nickname, callable $handle)
{
$user = DB::findOneBy('local_user', ['nickname' => $nickname]);
$gsactor = DB::findOneBy('gsactor', ['id' => $user->getId()]);
if (empty($gsactor)) {
$user = DB::findOneBy('local_user', ['nickname' => $nickname]);
$actor = DB::findOneBy('actor', ['id' => $user->getId()]);
if (empty($actor)) {
throw new ClientException(_m('No such actor.'), 404);
} else {
return $handle($gsactor);
return $handle($actor);
}
}
/**
* Collection of an actor's subscribers
*/
public function GSActorShowId(Request $request, int $id)
public function ActorShowId(Request $request, int $id)
{
return $this->GSActorById($id, fn ($gsactor) => ['_template' => 'subscribers/view.html.twig', 'gsactor' => $gsactor]);
return $this->ActorById($id, fn ($actor) => ['_template' => 'subscribers/view.html.twig', 'actor' => $actor]);
}
public function GSActorShowNickname(Request $request, string $nickname)