Skip to content

Commit

Permalink
Merge pull request #55 from ticktackk/develop
Browse files Browse the repository at this point in the history
1.1.0 Release Candidate 1
  • Loading branch information
ticktackk authored Mar 10, 2021
2 parents cb72ba2 + 4dd71ec commit 4cf4baf
Show file tree
Hide file tree
Showing 17 changed files with 527 additions and 80 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
CHANGELOG
==========================

## 1.1.0 Release Candidate 1 (`1010051`)

- **New:** Seed for thread prefix (#50)
- **New:** Seed for resource prefix (#51)
- **New:** Seed for thread prefix group (#52)
- **New:** Seed for resource prefix group (#53)
- **Change:** Switch to `fakerphp/faker` package (#54)

## 1.1.0 Alpha 4 (`1010014`)

- **New:** Seed for threadmark category (#37)
Expand Down
21 changes: 21 additions & 0 deletions Cli/Command/Seed/SeedResourceManagerItemPrefix.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 SeedResourceManagerItemPrefix extends AbstractSeedCommand
{
protected function getSeedName() : string
{
return 'resource-manager-item-prefix';
}

protected function getContentTypePlural(InputInterface $input = null) : string
{
return 'Resource manager item prefixes';
}
}
21 changes: 21 additions & 0 deletions Cli/Command/Seed/SeedResourceManagerItemPrefixGroup.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 SeedResourceManagerItemPrefixGroup extends AbstractSeedCommand
{
protected function getSeedName() : string
{
return 'resource-manager-item-prefix-group';
}

protected function getContentTypePlural(InputInterface $input = null) : string
{
return 'Resource manager item prefix groups';
}
}
21 changes: 21 additions & 0 deletions Cli/Command/Seed/SeedThreadPrefix.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 SeedThreadPrefix extends AbstractSeedCommand
{
protected function getSeedName() : string
{
return 'thread-prefix';
}

protected function getContentTypePlural(InputInterface $input = null) : string
{
return 'Thread prefixes';
}
}
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';
}
}
76 changes: 40 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,46 @@ Requirements
CLI Commands
------------

| Command | Description |
| ------------------------------------------------- | -------------------------------------- |
| `tck-seeder:seed-conversation` | Seeds conversations |
| `tck-seeder:seed-media-gallery-item` | Seeds media gallery media items |
| `tck-seeder:seed-user-reject` | Seeds user rejects |
| `tck-seeder:seed-profile-post-comment-reaction` | Seeds profile post comment reactions |
| `tck-seeder:seed-spam-cleaner-log` | Seeds spam cleaner log |
| `tck-seeder:seed-resource-manager-update` | Seeds resource manager updates |
| `tck-seeder:seed-media-gallery-item-reaction` | Seeds media gallery item reactions |
| `tck-seeder:seed-media-gallery-comment-reaction` | Seeds media gallery comment reactions |
| `tck-seeder:seed-media-gallery-album` | Seeds media gallery albums |
| `tck-seeder:seed-thread` | Seeds threads |
| `tck-seeder:seed-spam-trigger` | Seeds spam triggers |
| `tck-seeder:seed-error-log` | Seeds error logs |
| `tck-seeder:seed-page` | Seeds pages |
| `tck-seeder:seed-post-reaction` | Seeds post reactions |
| `tck-seeder:seed-post-threadmark` | Seeds post threadmarks |
| `tck-seeder:seed-post` | Seeds posts |
| `tck-seeder:seed-category` | Seeds categories |
| `tck-seeder:seed-media-gallery-comment` | Seeds media gallery comments |
| `tck-seeder:seed-conversation-message` | Seeds conversation messages |
| `tck-seeder:seed-ip-address-ban` | Seeds ip address bans |
| `tck-seeder:seed-media-gallery-category` | Seeds media gallery categories |
| `tck-seeder:seed-forum` | Seeds forums |
| `tck-seeder:seed-user-ban` | Seeds user bans |
| `tck-seeder:seed-user` | Seeds users |
| `tck-seeder:seed-discouraged-ip-address` | Seeds discouraged ip addresses |
| `tck-seeder:seed-conversation-message-threadmark` | Seeds conversation message threadmarks |
| `tck-seeder:seed-email-bounce-log` | Seeds email bounce logs |
| `tck-seeder:seed-profile-post-comment` | Seeds profile post comments |
| `tck-seeder:seed-resource-manager-item` | Seeds resource manager items |
| `tck-seeder:seed-media-gallery-album-reaction` | Seeds media gallery album reactions |
| `tck-seeder:seed-profile-post` | Seeds profile posts |
| `tck-seeder:seed-resource-manager-category` | Seeds resource manager categories |
| `tck-seeder:seed-threadmark-category` | Seeds threadmark categories |
| `tck-seeder:seed-profile-post-reaction` | Seeds profile post reactions |
| Command | Description |
| ---------------------------------------------------- | ----------------------------------------- |
| `tck-seeder:seed-conversation` | Seeds conversations |
| `tck-seeder:seed-media-gallery-item` | Seeds media gallery media items |
| `tck-seeder:seed-user-reject` | Seeds user rejects |
| `tck-seeder:seed-resource-manager-item-prefix-group` | Seeds resource manager item prefix groups |
| `tck-seeder:seed-profile-post-comment-reaction` | Seeds profile post comment reactions |
| `tck-seeder:seed-spam-cleaner-log` | Seeds spam cleaner log |
| `tck-seeder:seed-resource-manager-update` | Seeds resource manager updates |
| `tck-seeder:seed-media-gallery-item-reaction` | Seeds media gallery item reactions |
| `tck-seeder:seed-media-gallery-comment-reaction` | Seeds media gallery comment reactions |
| `tck-seeder:seed-media-gallery-album` | Seeds media gallery albums |
| `tck-seeder:seed-thread` | Seeds threads |
| `tck-seeder:seed-spam-trigger` | Seeds spam triggers |
| `tck-seeder:seed-error-log` | Seeds error logs |
| `tck-seeder:seed-page` | Seeds pages |
| `tck-seeder:seed-post-reaction` | Seeds post reactions |
| `tck-seeder:seed-post-threadmark` | Seeds post threadmarks |
| `tck-seeder:seed-post` | Seeds posts |
| `tck-seeder:seed-category` | Seeds categories |
| `tck-seeder:seed-media-gallery-comment` | Seeds media gallery comments |
| `tck-seeder:seed-thread-prefix-group` | Seeds thread prefix groups |
| `tck-seeder:seed-conversation-message` | Seeds conversation messages |
| `tck-seeder:seed-ip-address-ban` | Seeds ip address bans |
| `tck-seeder:seed-media-gallery-category` | Seeds media gallery categories |
| `tck-seeder:seed-forum` | Seeds forums |
| `tck-seeder:seed-user-ban` | Seeds user bans |
| `tck-seeder:seed-user` | Seeds users |
| `tck-seeder:seed-discouraged-ip-address` | Seeds discouraged ip addresses |
| `tck-seeder:seed-conversation-message-threadmark` | Seeds conversation message threadmarks |
| `tck-seeder:seed-email-bounce-log` | Seeds email bounce logs |
| `tck-seeder:seed-resource-manager-item-prefix` | Seeds resource manager item prefixes |
| `tck-seeder:seed-profile-post-comment` | Seeds profile post comments |
| `tck-seeder:seed-resource-manager-item` | Seeds resource manager items |
| `tck-seeder:seed-media-gallery-album-reaction` | Seeds media gallery album reactions |
| `tck-seeder:seed-profile-post` | Seeds profile posts |
| `tck-seeder:seed-thread-prefix` | Seeds thread prefixes |
| `tck-seeder:seed-resource-manager-category` | Seeds resource manager categories |
| `tck-seeder:seed-threadmark-category` | Seeds threadmark categories |
| `tck-seeder:seed-profile-post-reaction` | Seeds profile post reactions |

License
-------
Expand Down
179 changes: 179 additions & 0 deletions Seed/AbstractContentPrefix.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php

namespace TickTackk\Seeder\Seed;

use XF\Entity\AbstractPrefixGroup as AbstractPrefixGroupEntity;
use XF\Mvc\Entity\Entity;
use XF\Mvc\Entity\Repository;
use XF\Repository\AbstractPrefix as AbstractPrefixRepo;
use XF\Entity\AbstractPrefix as AbstractPrefixEntity;
use XF\Repository\AbstractPrefixMap as AbstractPrefixMapRepo;

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

abstract protected function getGroupClassIdentifier() : string;

abstract protected function getMapIdentifier() : string;

abstract protected function getContainerIdentifier() : string;

protected function getRandomContainerIds() : array
{
$containerIds = $this->finderWithRandomOrder($this->getContainerIdentifier())->fetch()->keys();
\shuffle($containerIds);

return \array_slice($containerIds, $this->faker()->numberBetween(0, \count($containerIds)));
}

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

/**
* @return Repository|AbstractPrefixRepo
*/
protected function getRepo() : AbstractPrefixRepo
{
return $this->repository($this->getClassIdentifier());
}

/**
* @return Repository|AbstractPrefixMapRepo
*/
protected function getMapRepo() : AbstractPrefixMapRepo
{
return $this->repository($this->getMapIdentifier());
}

protected function getRandomCssClass() : string
{
$faker = $this->faker();

$cssClass = '';

if ($faker->boolean)
{
$cssClasses = $this->getRepo()->getDefaultDisplayStyles();
if (\count($cssClasses))
{
\shuffle($cssClasses);
$cssClass = $cssClasses[\array_rand($cssClasses)];
}
}
else
{
$cssClass = 'label label--' . $faker->word;
}

return \substr($cssClass, 0, 50);
}

/**
* @return Entity|AbstractPrefixGroupEntity|null
*/
protected function getRandomPrefixGroup() :? AbstractPrefixGroupEntity
{
if (!$this->faker()->boolean)
{
return null;
}

return $this->finderWithRandomOrder($this->getGroupClassIdentifier())->fetchOne();
}

protected function getRandomPrefixGroupId() : int
{
$randomPrefixGroup = $this->getRandomPrefixGroup();
if (!$randomPrefixGroup)
{
return 0;
}

return $randomPrefixGroup->prefix_group_id;
}

protected function getAllowedUserGroupIds() : array
{
return $this->faker()->boolean ? [-1] : $this->getRandomUserGroupIds();
}

protected function getInput() : array
{
return [
'css_class' => $this->getRandomCssClass(),
'prefix_group_id' => $this->getRandomPrefixGroupId(),
'display_order' => $this->faker()->randomNumber(),
'allowed_user_group_ids' => $this->getAllowedUserGroupIds()
];
}

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

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

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

if (\XF::$versionId >= 2020010)
{
if ($faker->boolean)
{
$formAction->apply(function() use ($faker, $prefix)
{
$phrase = $prefix->getDescriptionMasterPhrase();
$phrase->phrase_text = $faker->text;
$phrase->save();
});
}

if ($faker->boolean)
{
$formAction->apply(function() use ($faker, $prefix)
{
$phrase = $prefix->getUsageHelpMasterPhrase();
$phrase->phrase_text = $faker->text;
$phrase->save();
});
}
}

$formAction->complete(function () use($prefix)
{
$this->getMapRepo()->updatePrefixAssociations(
$prefix,
$this->getRandomContainerIds()
);
});

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

return true;
}
}
Loading

0 comments on commit 4cf4baf

Please sign in to comment.