2021-05-05 21:21:05 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\DataFixtures;
|
|
|
|
|
2021-05-24 04:56:45 +09:00
|
|
|
use App\Core\VisibilityScope;
|
2021-08-19 01:26:37 +09:00
|
|
|
use App\Entity\Follow;
|
2021-05-07 06:53:25 +09:00
|
|
|
use App\Entity\GroupInbox;
|
2021-08-19 01:26:37 +09:00
|
|
|
use App\Entity\GroupMember;
|
2021-05-05 21:21:05 +09:00
|
|
|
use App\Entity\GSActor;
|
|
|
|
use App\Entity\LocalGroup;
|
|
|
|
use App\Entity\LocalUser;
|
2021-05-07 06:53:25 +09:00
|
|
|
use App\Entity\Note;
|
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 ([
|
|
|
|
'taken_user' => [LocalUser::class, 'setId', ['password' => LocalUser::hashPassword('foobar'), 'outgoing_email' => 'email@provider']],
|
|
|
|
'some_user' => [LocalUser::class, 'setId', []],
|
2021-08-05 05:05:11 +09:00
|
|
|
'form_personal_info_test_user' => [LocalUser::class, 'setId', []],
|
|
|
|
'form_account_test_user' => [LocalUser::class, 'setId', ['password' => LocalUser::hashPassword('some password')]],
|
2021-08-19 01:26:37 +09:00
|
|
|
'taken_group' => [LocalGroup::class, 'setGroupId', []],
|
|
|
|
] as $nick => [$entity, $method, $extra_create]) {
|
2021-08-05 05:05:11 +09:00
|
|
|
$actor = GSActor::create(['nickname' => $nick]);
|
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-08-19 01:26:37 +09:00
|
|
|
// Add self follows
|
|
|
|
$manager->persist(Follow::create(['follower' => $actor->getId(), 'followed' => $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-05-24 04:56:45 +09:00
|
|
|
$n = Note::create(['gsactor_id' => $actors['taken_user']->getId(), 'content' => 'some content']);
|
|
|
|
$manager->persist($n);
|
|
|
|
$notes[] = Note::create(['gsactor_id' => $actors['taken_user']->getId(), 'content' => 'some other content', 'reply_to' => $n->getId()]);
|
|
|
|
$notes[] = Note::create(['gsactor_id' => $actors['taken_user']->getId(), 'content' => 'private note', 'scope' => VisibilityScope::FOLLOWER]);
|
2021-08-19 01:26:37 +09:00
|
|
|
$notes[] = $group_note = Note::create(['gsactor_id' => $actors['taken_user']->getId(), 'content' => 'group note', 'scope' => VisibilityScope::GROUP]);
|
2021-05-24 04:56:45 +09:00
|
|
|
foreach ($notes as $note) {
|
|
|
|
$manager->persist($note);
|
|
|
|
}
|
2021-05-07 06:53:25 +09:00
|
|
|
|
2021-08-19 01:26:37 +09:00
|
|
|
$manager->persist(GroupMember::create(['group_id' => $local_entities['taken_group']->getGroupId(), 'gsactor_id' => $actors['some_user']->getId()]));
|
|
|
|
$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();
|
|
|
|
}
|
|
|
|
}
|