2021-05-05 13:21:05 +01:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 09:26:18 +01:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2022-03-13 18:00:21 +00:00
|
|
|
namespace App\Test\Fixtures;
|
2021-05-05 13:21:05 +01:00
|
|
|
|
2022-01-22 15:02:21 +00:00
|
|
|
use App\Core\ActorLocalRoles;
|
2021-05-23 20:56:45 +01:00
|
|
|
use App\Core\VisibilityScope;
|
2022-03-06 20:16:09 +00:00
|
|
|
use App\Entity\Activity;
|
2021-09-18 03:22:27 +01:00
|
|
|
use App\Entity\Actor;
|
2021-05-05 13:21:05 +01:00
|
|
|
use App\Entity\LocalUser;
|
2021-05-06 22:53:25 +01:00
|
|
|
use App\Entity\Note;
|
2022-03-06 20:16:09 +00:00
|
|
|
use Component\Conversation\Conversation;
|
2021-12-27 20:33:56 +00:00
|
|
|
use Component\Group\Entity\GroupMember;
|
|
|
|
use Component\Group\Entity\LocalGroup;
|
2022-03-19 22:16:50 +00:00
|
|
|
use Component\Language\Entity\Language;
|
2022-03-06 20:16:09 +00:00
|
|
|
use Component\Notification\Entity\Attention;
|
|
|
|
use Component\Notification\Entity\Notification;
|
2022-01-06 11:26:48 +00:00
|
|
|
use Component\Subscription\Entity\ActorSubscription;
|
2021-05-05 13:21:05 +01:00
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
|
|
use Doctrine\Persistence\ObjectManager;
|
2022-03-19 22:16:50 +00:00
|
|
|
use Symfony\Component\Intl\Locales;
|
2021-05-05 13:21:05 +01:00
|
|
|
|
2021-05-06 22:53:25 +01:00
|
|
|
class CoreFixtures extends Fixture
|
2021-05-05 13:21:05 +01:00
|
|
|
{
|
|
|
|
public function load(ObjectManager $manager)
|
|
|
|
{
|
2022-03-19 22:16:50 +00:00
|
|
|
// Populate Initial Language values
|
|
|
|
foreach (Locales::getNames() as $key => $name) {
|
|
|
|
$manager->persist(Language::create(['locale' => $key, 'short_display' => $key, 'long_display' => $name]));
|
|
|
|
}
|
|
|
|
$manager->flush();
|
|
|
|
|
2021-05-06 22:53:25 +01:00
|
|
|
$actors = [];
|
|
|
|
$local_entities = [];
|
2021-08-18 17:26:37 +01:00
|
|
|
foreach ([
|
2022-03-06 20:16:09 +00:00
|
|
|
'taken_user' => [
|
|
|
|
LocalUser::class,
|
|
|
|
'setId',
|
|
|
|
['password' => LocalUser::hashPassword('foobar'), 'outgoing_email' => 'taken_user@provider.any'],
|
|
|
|
['roles' => ActorLocalRoles::PARTICIPANT | ActorLocalRoles::VISITOR, 'type' => Actor::PERSON],
|
|
|
|
],
|
|
|
|
'some_user' => [
|
|
|
|
LocalUser::class,
|
|
|
|
'setId',
|
|
|
|
['password' => LocalUser::hashPassword('foobar'), 'outgoing_email' => 'some_user@provider.any'],
|
|
|
|
['roles' => ActorLocalRoles::PARTICIPANT | ActorLocalRoles::VISITOR, 'type' => Actor::PERSON],
|
|
|
|
],
|
|
|
|
'admin' => [
|
|
|
|
LocalUser::class,
|
|
|
|
'setId',
|
|
|
|
['password' => LocalUser::hashPassword('foobar'), 'outgoing_email' => 'admin@provider.any'],
|
|
|
|
['roles' => ActorLocalRoles::OPERATOR | ActorLocalRoles::MODERATOR | ActorLocalRoles::PARTICIPANT | ActorLocalRoles::VISITOR, 'type' => Actor::PERSON],
|
|
|
|
],
|
|
|
|
'local_user_test_user' => [
|
|
|
|
LocalUser::class,
|
|
|
|
'setId',
|
|
|
|
['password' => LocalUser::hashPassword('foobar'), 'outgoing_email' => 'local_user_test_user@provider.any'],
|
|
|
|
['roles' => ActorLocalRoles::PARTICIPANT | ActorLocalRoles::VISITOR, 'type' => Actor::PERSON],
|
|
|
|
],
|
|
|
|
'form_personal_info_test_user' => [
|
|
|
|
LocalUser::class,
|
|
|
|
'setId',
|
|
|
|
['password' => LocalUser::hashPassword('foobar'), 'outgoing_email' => 'form_personal_info_test_user@provider.any'],
|
|
|
|
['roles' => ActorLocalRoles::PARTICIPANT | ActorLocalRoles::VISITOR, 'type' => Actor::PERSON],
|
|
|
|
],
|
|
|
|
'form_account_test_user' => [
|
|
|
|
LocalUser::class,
|
|
|
|
'setId',
|
|
|
|
['password' => LocalUser::hashPassword('foobar'), 'outgoing_email' => 'form_account_test_user@provider.any'],
|
|
|
|
['roles' => ActorLocalRoles::PARTICIPANT | ActorLocalRoles::VISITOR, 'type' => Actor::PERSON],
|
|
|
|
],
|
2022-03-08 01:46:50 +00:00
|
|
|
'taken_public_group' => [
|
2022-03-06 20:16:09 +00:00
|
|
|
LocalGroup::class,
|
|
|
|
'setActorId',
|
|
|
|
[],
|
|
|
|
['roles' => ActorLocalRoles::VISITOR, 'type' => Actor::GROUP],
|
|
|
|
],
|
2022-03-08 01:46:50 +00:00
|
|
|
'taken_private_group' => [
|
|
|
|
LocalGroup::class,
|
|
|
|
'setActorId',
|
|
|
|
[],
|
|
|
|
['roles' => ActorLocalRoles::VISITOR | ActorLocalRoles::PRIVATE_GROUP, 'type' => Actor::GROUP],
|
|
|
|
],
|
2021-11-23 22:34:35 +00:00
|
|
|
] as $nick => [$entity, $method, $extra_create, $extra_create_actor]) {
|
|
|
|
$actor = Actor::create(array_merge(['nickname' => $nick, 'is_local' => true], $extra_create_actor));
|
2021-05-05 13:21:05 +01:00
|
|
|
$manager->persist($actor);
|
2022-03-06 20:16:09 +00:00
|
|
|
// cannot use array spread for arrays with string keys
|
|
|
|
$ent = $entity::create(array_merge(['nickname' => $nick], $extra_create));
|
2021-05-05 13:21:05 +01:00
|
|
|
$ent->{$method}($actor->getId());
|
2021-05-06 22:53:25 +01:00
|
|
|
$local_entities[$nick] = $ent;
|
2021-05-05 13:21:05 +01:00
|
|
|
$manager->persist($ent);
|
2021-11-08 13:44:35 +00:00
|
|
|
// Add self subscriptions
|
2022-03-06 20:16:09 +00:00
|
|
|
$manager->persist(ActorSubscription::create(['subscriber_id' => $actor->getId(), 'subscribed_id' => $actor->getId()]));
|
2021-05-06 22:53:25 +01:00
|
|
|
$actors[$nick] = $actor;
|
2021-05-05 13:21:05 +01:00
|
|
|
}
|
2021-05-06 22:53:25 +01:00
|
|
|
|
2021-11-11 12:27:10 +00:00
|
|
|
$notes = [];
|
2021-11-23 21:35:25 +00:00
|
|
|
$notes[] = Note::create(['actor_id' => $actors['taken_user']->getId(), 'content' => 'some other content', 'content_type' => 'text/plain', 'is_local' => true]);
|
2022-03-08 01:46:50 +00:00
|
|
|
$notes[] = Note::create(['actor_id' => $actors['taken_user']->getId(), 'content' => 'private note', 'scope' => VisibilityScope::MESSAGE, 'content_type' => 'text/plain', 'is_local' => false]);
|
2021-05-23 20:56:45 +01:00
|
|
|
foreach ($notes as $note) {
|
|
|
|
$manager->persist($note);
|
2022-03-06 20:16:09 +00:00
|
|
|
$activity = Activity::create(['actor_id' => $actors['taken_user']->getId(), 'verb' => 'create', 'object_type' => 'note', 'object_id' => $note->getId(), 'source' => 'auto-test']);
|
|
|
|
Conversation::assignLocalConversation($note, null);
|
|
|
|
$manager->persist($activity);
|
2021-05-23 20:56:45 +01:00
|
|
|
}
|
2021-05-06 22:53:25 +01:00
|
|
|
|
2022-03-08 01:46:50 +00:00
|
|
|
$group_notes = [];
|
2022-03-13 15:03:03 +00:00
|
|
|
$group_notes[] = $public_group_note = Note::create(['actor_id' => $actors['taken_user']->getId(), 'content' => 'group note public', 'scope' => VisibilityScope::EVERYWHERE, 'content_type' => 'text/plain', 'is_local' => true]);
|
|
|
|
$group_notes[] = $private_group_note = Note::create(['actor_id' => $actors['taken_user']->getId(), 'content' => 'group note private', 'scope' => VisibilityScope::GROUP, 'content_type' => 'text/plain', 'is_local' => true]);
|
2022-03-08 01:46:50 +00:00
|
|
|
foreach ($group_notes as $note) {
|
|
|
|
$manager->persist($note);
|
|
|
|
$activity = Activity::create(['actor_id' => $actors['taken_user']->getId(), 'verb' => 'create', 'object_type' => 'note', 'object_id' => $note->getId(), 'source' => 'auto-test']);
|
|
|
|
Conversation::assignLocalConversation($note, null);
|
|
|
|
$manager->persist($activity);
|
|
|
|
$manager->persist(Notification::create(['activity_id' => $activity->getId(), 'target_id' => $local_entities['taken_public_group']->getActorId(), 'reason' => 'testing']));
|
|
|
|
$manager->persist(Notification::create(['activity_id' => $activity->getId(), 'target_id' => $local_entities['taken_private_group']->getActorId(), 'reason' => 'testing']));
|
|
|
|
}
|
|
|
|
|
2022-03-14 18:33:47 +00:00
|
|
|
$manager->persist(Attention::create(['object_type' => Note::schemaName(), 'object_id' => $public_group_note->getId(), 'target_id' => $local_entities['taken_public_group']->getActorId()]));
|
2022-03-08 01:46:50 +00:00
|
|
|
|
|
|
|
$manager->persist(GroupMember::create(['group_id' => $local_entities['taken_private_group']->getActorId(), 'actor_id' => $actors['some_user']->getId()]));
|
2022-03-14 18:33:47 +00:00
|
|
|
$manager->persist(Attention::create(['object_type' => Note::schemaName(), 'object_id' => $private_group_note->getId(), 'target_id' => $local_entities['taken_private_group']->getActorId()]));
|
2022-03-08 01:46:50 +00:00
|
|
|
|
2021-05-05 13:21:05 +01:00
|
|
|
$manager->flush();
|
|
|
|
}
|
|
|
|
}
|