2021-05-05 13:21:05 +01:00
< ? php
2021-10-10 09:26:18 +01:00
declare ( strict_types = 1 );
2021-05-05 13:21:05 +01:00
namespace App\DataFixtures ;
2021-05-23 20:56:45 +01:00
use App\Core\VisibilityScope ;
2021-09-18 03:22:27 +01:00
use App\Entity\Actor ;
2021-05-06 22:53:25 +01:00
use App\Entity\GroupInbox ;
2021-08-18 17:26:37 +01:00
use App\Entity\GroupMember ;
2021-05-05 13:21:05 +01:00
use App\Entity\LocalGroup ;
use App\Entity\LocalUser ;
2021-05-06 22:53:25 +01:00
use App\Entity\Note ;
2021-11-11 12:27:10 +00:00
use App\Entity\Subscription ;
2021-05-05 13:21:05 +01:00
use Doctrine\Bundle\FixturesBundle\Fixture ;
use Doctrine\Persistence\ObjectManager ;
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-08-18 17:26:37 +01:00
foreach ([
'taken_user' => [ LocalUser :: class , 'setId' , [ 'password' => LocalUser :: hashPassword ( 'foobar' ), 'outgoing_email' => 'email@provider' ]],
'some_user' => [ LocalUser :: class , 'setId' , []],
2021-08-04 21:05:11 +01:00
'form_personal_info_test_user' => [ LocalUser :: class , 'setId' , []],
'form_account_test_user' => [ LocalUser :: class , 'setId' , [ 'password' => LocalUser :: hashPassword ( 'some password' )]],
2021-08-18 17:26:37 +01:00
'taken_group' => [ LocalGroup :: class , 'setGroupId' , []],
] as $nick => [ $entity , $method , $extra_create ]) {
2021-09-18 03:22:27 +01:00
$actor = Actor :: create ([ 'nickname' => $nick ]);
2021-05-05 13:21:05 +01:00
$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-11-08 13:44:35 +00:00
// Add self subscriptions
$manager -> persist ( Subscription :: create ([ 'subscriber' => $actor -> getId (), 'subscribed' => $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-10-28 18:05:28 +01:00
$n = Note :: create ([ 'actor_id' => $actors [ 'taken_user' ] -> getId (), 'content' => 'some content' , 'content_type' => 'text/plain' ]);
2021-05-23 20:56:45 +01:00
$manager -> persist ( $n );
2021-11-11 12:27:10 +00:00
$notes = [];
$notes [] = Note :: create ([ 'actor_id' => $actors [ 'taken_user' ] -> getId (), 'content' => 'some other content' , 'reply_to' => $n -> getId (), 'content_type' => 'text/plain' ]);
$notes [] = Note :: create ([ 'actor_id' => $actors [ 'taken_user' ] -> getId (), 'content' => 'private note' , 'scope' => VisibilityScope :: SUBSCRIBER , 'content_type' => 'text/plain' ]);
$notes [] = $group_note = Note :: create ([ 'actor_id' => $actors [ 'taken_user' ] -> getId (), 'content' => 'group note' , 'scope' => VisibilityScope :: GROUP , 'content_type' => 'text/plain' ]);
2021-05-23 20:56:45 +01:00
foreach ( $notes as $note ) {
$manager -> persist ( $note );
}
2021-05-06 22:53:25 +01:00
2021-09-18 03:22:27 +01:00
$manager -> persist ( GroupMember :: create ([ 'group_id' => $local_entities [ 'taken_group' ] -> getGroupId (), 'actor_id' => $actors [ 'some_user' ] -> getId ()]));
2021-08-18 17:26:37 +01:00
$manager -> persist ( GroupInbox :: create ([ 'group_id' => $local_entities [ 'taken_group' ] -> getGroupId (), 'activity_id' => $group_note -> getId ()]));
2021-05-05 13:21:05 +01:00
$manager -> flush ();
}
}