Skip to content

Commit

Permalink
closes #52
Browse files Browse the repository at this point in the history
  • Loading branch information
ticktackk committed Mar 10, 2021
1 parent 81dcf05 commit 0ab61fb
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG

- **New:** Seed for thread prefix (#50)
- **New:** Seed for resource prefix (#51)
- **New:** Seed for thread prefix group (#52)

## 1.1.0 Alpha 4 (`1010014`)

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

namespace TickTackk\Seeder\Cli\Command\Seed;

use Symfony\Component\Console\Input\InputInterface;

/**
* @since 1.1.0 Release Candidate 1
*/
class SeedThreadPrefixGroup extends AbstractSeedCommand
{
protected function getSeedName() : string
{
return 'thread-prefix-group';
}

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

namespace TickTackk\Seeder\Seed;

use XF\Mvc\Entity\Entity;
use XF\Entity\AbstractPrefixGroup as AbstractPrefixGroupEntity;

/**
* @since 1.1.0 Release Candidate 1
*/
abstract class AbstractContentPrefixGroup extends AbstractSeed
{
abstract protected function getClassIdentifier() : string;

/**
* @return Entity|AbstractPrefixGroupEntity
*/
protected function getEntity() : AbstractPrefixGroupEntity
{
return $this->em()->create($this->getClassIdentifier());
}

protected function getInput() : array
{
return [
'display_order' => $this->faker()->randomNumber()
];
}

/**
* @param array $params
*
* @return bool
*
* @throws \XF\PrintableException
*/
protected function seed(array $params = []): bool
{
$formAction = $this->formAction();
$prefixGroup = $this->getEntity();

$formAction->basicEntitySave($prefixGroup, $this->getInput());

$formAction->apply(function() use ($prefixGroup)
{
$phrase = $prefixGroup->getMasterPhrase();
$phrase->phrase_text = $this->faker()->words(3, true);
$phrase->save();
});

if (!$formAction->run(false))
{
return false;
}

return true;
}
}
14 changes: 14 additions & 0 deletions Seed/ThreadPrefixGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace TickTackk\Seeder\Seed;

/**
* @since 1.1.0 Release Candidate 1
*/
class ThreadPrefixGroup extends AbstractContentPrefixGroup
{
protected function getClassIdentifier(): string
{
return 'XF:ThreadPrefixGroup';
}
}

0 comments on commit 0ab61fb

Please sign in to comment.