Skip to content

Commit

Permalink
closes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
ticktackk committed Aug 26, 2020
1 parent 520a594 commit 464da43
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
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 comment (#17)

## 1.1.0 Alpha 1 (`1010011`)

Expand Down
18 changes: 18 additions & 0 deletions Cli/Command/Seed/SeedProfilePostComment.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 SeedProfilePostComment extends AbstractSeedCommand
{
protected function getSeedName() : string
{
return 'profile-post-comment';
}

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

namespace TickTackk\Seeder\Seed;

use XF\Entity\ProfilePost as ProfilePostEntity;
use XF\Service\ProfilePostComment\Creator as ProfilePostCommentCreatorSvc;
use XF\Repository\ThreadWatch as ThreadWatchRepo;
use XF\Service\Thread\Replier as ThreadReplierSvc;

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

$faker = $this->faker();

$profilePostCommentCreatorSvc = $this->getProfileProfileCommentCreator($randomProfilePost);

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

$profilePostCommentCreatorSvc->setContent($faker->text);

if (!$profilePostCommentCreatorSvc->validate())
{
return false;
}

$profilePostCommentCreatorSvc->save();

return true;
}

protected function getProfileProfileCommentCreator(ProfilePostEntity $profilePost) : ProfilePostCommentCreatorSvc
{
return $this->service('XF:ProfilePostComment\Creator', $profilePost);
}
}

0 comments on commit 464da43

Please sign in to comment.