From 960c0e3cea309a4077259a694063190c9d4cb518 Mon Sep 17 00:00:00 2001 From: ticktackk Date: Wed, 10 Mar 2021 00:02:02 +0530 Subject: [PATCH] closes #49 --- CHANGELOG.md | 1 + Seed/AbstractNode.php | 20 ++++++++++++++++++++ Seed/Page.php | 25 +++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0115325..b2343cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ CHANGELOG - **New:** Seed for spam cleaner log (#47) - **New:** Seed for email bounce log (#48) - **Fix:** Threads cannot be seeded (#36) +- **Fix:** Master template is not created for page nodes (#49) ## 1.1.0 Alpha 3 (`1010013`) diff --git a/Seed/AbstractNode.php b/Seed/AbstractNode.php index 273300d..e81a797 100644 --- a/Seed/AbstractNode.php +++ b/Seed/AbstractNode.php @@ -4,6 +4,9 @@ use Faker\Provider\Lorem; use XF\Entity\Node as NodeEntity; +use XF\Entity\Page as PageEntity; +use XF\Mvc\FormAction; +use XF\Entity\AbstractNode as AbstractNodeEntity; abstract class AbstractNode extends AbstractSeed { @@ -30,6 +33,21 @@ protected function getNodeInput() : array ]; } + /** + * @since 1.1.0 Alpha 4 + * + * @param NodeEntity $node + * @param AbstractNodeEntity $data + * @param FormAction $formAction + */ + protected function setupFormAction( + NodeEntity $node, + AbstractNodeEntity $data, + FormAction $formAction + ) : void + { + } + /** * @throws \XF\PrintableException */ @@ -45,6 +63,8 @@ protected function seed(array $params = []) : bool $node->addCascadedSave($data); $form->basicEntitySave($node, $this->getNodeInput()); + $this->setupFormAction($node, $data, $form); + if (!$form->run(false)) { return false; diff --git a/Seed/Page.php b/Seed/Page.php index 74ef69f..f56297a 100644 --- a/Seed/Page.php +++ b/Seed/Page.php @@ -3,6 +3,9 @@ namespace TickTackk\Seeder\Seed; use XF\Entity\AbstractNode as AbstractNodeEntity; +use XF\Entity\Node as NodeEntity; +use XF\Mvc\FormAction; +use XF\Entity\Page as PageEntity; class Page extends AbstractNode { @@ -20,6 +23,28 @@ protected function getNodeInput() : array return $nodeInput; } + /** + * @param NodeEntity $node + * @param AbstractNodeEntity|PageEntity $data + * @param FormAction $formAction + */ + protected function setupFormAction( + NodeEntity $node, + AbstractNodeEntity $data, + FormAction $formAction + ): void + { + $template = $data->getMasterTemplate(); + + $faker = $this->faker(); + $template->template = $faker->boolean ? $faker->randomHtml() : $faker->text(); + + $formAction->apply(function () use($template) + { + $template->save(); + }); + } + protected function getRandomParentNode() :? AbstractNodeEntity { $faker = $this->faker();