-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from ticktackk/develop
1.1.0 Release Candidate 1
- Loading branch information
Showing
17 changed files
with
527 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.