2021-05-05 21:21:05 +09:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2021-05-05 21:21:05 +09:00
|
|
|
namespace App\DataFixtures;
|
|
|
|
|
2022-01-23 00:02:21 +09:00
|
|
|
use App\Core\ActorLocalRoles;
|
2021-05-24 04:56:45 +09:00
|
|
|
use App\Core\VisibilityScope;
|
2021-09-18 11:22:27 +09:00
|
|
|
use App\Entity\Actor;
|
2021-05-05 21:21:05 +09:00
|
|
|
use App\Entity\LocalUser;
|
2021-05-07 06:53:25 +09:00
|
|
|
use App\Entity\Note;
|
2021-12-28 05:33:56 +09:00
|
|
|
use Component\Group\Entity\GroupInbox;
|
|
|
|
use Component\Group\Entity\GroupMember;
|
|
|
|
use Component\Group\Entity\LocalGroup;
|
2022-01-06 20:26:48 +09:00
|
|
|
use Component\Subscription\Entity\ActorSubscription;
|
2021-05-05 21:21:05 +09:00
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
|
|
use Doctrine\Persistence\ObjectManager;
|
|
|
|
|
2021-05-07 06:53:25 +09:00
|
|
|
class CoreFixtures extends Fixture
|
2021-05-05 21:21:05 +09:00
|
|
|
{
|
|
|
|
public function load(ObjectManager $manager)
|
|
|
|
{
|
2021-05-07 06:53:25 +09:00
|
|
|
$actors = [];
|
|
|
|
$local_entities = [];
|
2021-08-19 01:26:37 +09:00
|
|
|
foreach ([
|
2021-11-24 07:34:35 +09:00
|
|
|
'taken_user' => [LocalUser::class, 'setId', ['password' => LocalUser::hashPassword('foobar'), 'outgoing_email' => 'email@provider'], []],
|
|
|
|
'some_user' => [LocalUser::class, 'setId', [], []],
|
2022-01-23 00:02:21 +09:00
|
|
|
'admin' => [LocalUser::class, 'setId', [], ['roles' => ActorLocalRoles::OPERATOR | ActorLocalRoles::MODERATOR | ActorLocalRoles::PARTICIPANT | ActorLocalRoles::VISITOR]],
|
2021-11-24 07:34:35 +09:00
|
|
|
'local_user_test_user' => [LocalUser::class, 'setId', ['password' => LocalUser::hashPassword('foobar')], []],
|
|
|
|
'form_personal_info_test_user' => [LocalUser::class, 'setId', [], []],
|
|
|
|
'form_account_test_user' => [LocalUser::class, 'setId', ['password' => LocalUser::hashPassword('some password')], []],
|
|
|
|
'taken_group' => [LocalGroup::class, 'setGroupId', [], []],
|
|
|
|
] 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 21:21:05 +09:00
|
|
|
$manager->persist($actor);
|
2021-07-29 06:25:07 +09:00
|
|
|
$ent = $entity::create(array_merge(['nickname' => $nick], $extra_create)); // cannot use array spread for arrays with string keys
|
2021-05-05 21:21:05 +09:00
|
|
|
$ent->{$method}($actor->getId());
|
2021-05-07 06:53:25 +09:00
|
|
|
$local_entities[$nick] = $ent;
|
2021-05-05 21:21:05 +09:00
|
|
|
$manager->persist($ent);
|
2021-11-08 22:44:35 +09:00
|
|
|
// Add self subscriptions
|
2022-01-06 20:26:48 +09:00
|
|
|
$manager->persist(ActorSubscription::create(['subscriber' => $actor->getId(), 'subscribed' => $actor->getId()]));
|
2021-05-07 06:53:25 +09:00
|
|
|
$actors[$nick] = $actor;
|
2021-05-05 21:21:05 +09:00
|
|
|
}
|
2021-05-07 06:53:25 +09:00
|
|
|
|
2021-11-24 06:35:25 +09:00
|
|
|
$n = Note::create(['actor_id' => $actors['taken_user']->getId(), 'content' => 'some content', 'content_type' => 'text/plain', 'is_local' => true]);
|
2021-05-24 04:56:45 +09:00
|
|
|
$manager->persist($n);
|
2021-11-11 21:27:10 +09:00
|
|
|
$notes = [];
|
2021-11-24 06:35:25 +09:00
|
|
|
$notes[] = Note::create(['actor_id' => $actors['taken_user']->getId(), 'content' => 'some other content', 'content_type' => 'text/plain', 'is_local' => true]);
|
2021-12-27 00:15:00 +09:00
|
|
|
$notes[] = Note::create(['actor_id' => $actors['taken_user']->getId(), 'content' => 'private note', 'scope' => VisibilityScope::COLLECTION, 'content_type' => 'text/plain', 'is_local' => false]);
|
2021-11-24 06:35:25 +09:00
|
|
|
$notes[] = $group_note = Note::create(['actor_id' => $actors['taken_user']->getId(), 'content' => 'group note', 'scope' => VisibilityScope::GROUP, 'content_type' => 'text/plain', 'is_local' => true]);
|
2021-05-24 04:56:45 +09:00
|
|
|
foreach ($notes as $note) {
|
|
|
|
$manager->persist($note);
|
|
|
|
}
|
2021-05-07 06:53:25 +09:00
|
|
|
|
2021-09-18 11:22:27 +09:00
|
|
|
$manager->persist(GroupMember::create(['group_id' => $local_entities['taken_group']->getGroupId(), 'actor_id' => $actors['some_user']->getId()]));
|
2021-08-19 01:26:37 +09:00
|
|
|
$manager->persist(GroupInbox::create(['group_id' => $local_entities['taken_group']->getGroupId(), 'activity_id' => $group_note->getId()]));
|
2021-05-05 21:21:05 +09:00
|
|
|
$manager->flush();
|
|
|
|
}
|
|
|
|
}
|