Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile post seed #24

Merged
merged 1 commit into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
- **New:** Seed for media gallery item reaction (#13)
- **New:** Seed for media gallery comment reaction (#14)
- **New:** Seed for media gallery album reaction (#15)
- **New:** Seed for profile post (#16)

## 1.1.0 Alpha 1 (`1010011`)

Expand Down
18 changes: 18 additions & 0 deletions Cli/Command/Seed/SeedProfilePost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace TickTackk\Seeder\Cli\Command\Seed;

use Symfony\Component\Console\Input\InputInterface;

class SeedProfilePost extends AbstractSeedCommand
{
protected function getSeedName() : string
{
return 'profile-post';
}

protected function getContentTypePlural(InputInterface $input = null) : string
{
return 'Profile posts';
}
}
50 changes: 50 additions & 0 deletions Seed/ProfilePost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace TickTackk\Seeder\Seed;

use XF\Entity\User as UserEntity;
use XF\Entity\UserProfile as UserProfileEntity;
use XF\Repository\ThreadWatch as ThreadWatchRepo;
use XF\Service\ProfilePost\Creator as ProfilePostCreatorSvc;
use XF\Service\Thread\Replier as ThreadReplierSvc;

class ProfilePost extends AbstractSeed
{
protected function seed(array $params = []): bool
{
/** @var UserEntity $randomUser */
$randomUser = $this->finderWithRandomOrder('XF:User')->fetchOne();
if (!$randomUser)
{
return false;
}

$faker = $this->faker();

$profilePostCreatorSvc = $this->getProfilePostCreatorSvc($randomUser->Profile);

if ($faker->boolean)
{
$profilePostCreatorSvc->logIp($faker->boolean ? $faker->ipv4 : $faker->ipv6);
}
else
{
$profilePostCreatorSvc->logIp(false);
}

$profilePostCreatorSvc->setContent($faker->text);
if (!$profilePostCreatorSvc->validate())
{
return false;
}

$profilePostCreatorSvc->save();

return true;
}

protected function getProfilePostCreatorSvc(UserProfileEntity $userProfile) : ProfilePostCreatorSvc
{
return $this->service('XF:ProfilePost\Creator', $userProfile);
}
}