2021-05-05 13:21:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\DataFixtures;
|
|
|
|
|
2021-08-03 18:51:58 +01:00
|
|
|
use App\Core\DB\DB;
|
|
|
|
use App\Core\GSFile;
|
2021-05-23 20:56:45 +01:00
|
|
|
use App\Core\VisibilityScope;
|
2021-05-06 22:53:25 +01:00
|
|
|
use App\Entity\GroupInbox;
|
2021-05-05 13:21:05 +01:00
|
|
|
use App\Entity\GSActor;
|
|
|
|
use App\Entity\LocalGroup;
|
|
|
|
use App\Entity\LocalUser;
|
2021-05-06 22:53:25 +01:00
|
|
|
use App\Entity\Note;
|
2021-08-03 18:51:58 +01:00
|
|
|
use App\Util\Common;
|
2021-05-05 13:21:05 +01:00
|
|
|
use App\Util\Nickname;
|
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
|
|
use Doctrine\Persistence\ObjectManager;
|
2021-08-03 18:51:58 +01:00
|
|
|
use Symfony\Component\HttpFoundation\File\File;
|
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)
|
|
|
|
{
|
2021-05-06 22:53:25 +01:00
|
|
|
$actors = [];
|
|
|
|
$local_entities = [];
|
2021-07-28 22:25:07 +01:00
|
|
|
foreach ([LocalUser::class => ['taken_user', 'setId', ['password' => LocalUser::hashPassword('foobar'), 'outgoing_email' => 'email@provider']], LocalGroup::class => ['taken_group', 'setGroupId', []]]
|
|
|
|
as $entity => [$nick, $method, $extra_create]) {
|
2021-05-05 13:21:05 +01:00
|
|
|
$actor = GSActor::create(['nickname' => $nick, 'normalized_nickname' => Nickname::normalize($nick, check_already_used: false)]);
|
|
|
|
$manager->persist($actor);
|
2021-07-28 22:25:07 +01:00
|
|
|
$ent = $entity::create(array_merge(['nickname' => $nick], $extra_create)); // cannot use array spread for arrays with string keys
|
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-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-05-23 20:56:45 +01: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]);
|
|
|
|
foreach ($notes as $note) {
|
|
|
|
$manager->persist($note);
|
|
|
|
}
|
2021-05-06 22:53:25 +01:00
|
|
|
|
|
|
|
$manager->persist(GroupInbox::create(['group_id' => $local_entities['taken_group']->getGroupId(), 'activity_id' => $note->getId()]));
|
2021-05-05 13:21:05 +01:00
|
|
|
$manager->flush();
|
2021-08-03 18:51:58 +01:00
|
|
|
|
|
|
|
DB::setManager($manager);
|
|
|
|
$filepath = INSTALLDIR . '/tests/Media/sample-uploads/image.jpeg';
|
|
|
|
$copy_filepath = $filepath . '.copy';
|
|
|
|
copy($filepath, $copy_filepath);
|
|
|
|
$file = new File($copy_filepath, checkPath: true);
|
|
|
|
GSFile::validateAndStoreFileAsAttachment($file, dest_dir: Common::config('attachments', 'dir') . 'test/', title: '1x1 JPEG image title', actor_id: $actors['taken_user']->getId());
|
|
|
|
$manager->flush();
|
2021-05-05 13:21:05 +01:00
|
|
|
}
|
|
|
|
}
|