Skip to content
Permalink
Browse files

[create:nodes] Added the revision option (#4091)

  • Loading branch information...
harold20 authored and enzolutions committed Jun 17, 2019
1 parent e03c085 commit e076e833414cd21800439e692325880d4da76bf6
Showing with 38 additions and 0 deletions.
  1. +17 −0 src/Command/Create/NodesCommand.php
  2. +21 −0 src/Utils/Create/NodeData.php
@@ -87,6 +87,12 @@ protected function configure()
InputOption::VALUE_OPTIONAL,
$this->trans('commands.create.nodes.options.time-range')
)
->addOption(
'revision',
null,
InputOption::VALUE_NONE,
$this->trans('commands.create.nodes.options.revision')
)
->addOption(
'language',
null,
@@ -151,6 +157,15 @@ function ($contentType) use ($bundles) {
$input->setOption('time-range', array_search($timeRange, $timeRanges));
}
$revision = is_null($input->getOption('revision'));
if (!$revision) {
$revision = $this->getIo()->confirm(
$this->trans('commands.create.nodes.questions.revision')
);
$input->setOption('revision', $revision);
}
// Language module is enabled or not.
$languageModuleEnabled = \Drupal::moduleHandler()
->moduleExists('language');
@@ -193,6 +208,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$limit = $input->getOption('limit')?:25;
$titleWords = $input->getOption('title-words')?:5;
$timeRange = $input->getOption('time-range')?:31536000;
$revision = $input->getOption('revision');
$available_types = array_keys($this->drupalApi->getBundles());
$language = $input->getOption('language')?:'und';
@@ -211,6 +227,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$limit,
$titleWords,
$timeRange,
$revision,
$language
);
@@ -24,6 +24,7 @@ class NodeData extends Base
* @param $limit
* @param $titleWords
* @param $timeRange
* @param $revision
*
* @return array
*/
@@ -32,6 +33,7 @@ public function create(
$limit,
$titleWords,
$timeRange,
$revision,
$language = LanguageInterface::LANGCODE_NOT_SPECIFIED
) {
$nodes = [];
@@ -55,6 +57,13 @@ public function create(
$this->generateFieldSampleData($node);
$node->save();
if($revision) {
for ($a = 0; $a < 3; $a++) {
$this->addRevision($node, $a);
}
}
$nodes['success'][] = [
'nid' => $node->id(),
'node_type' => $bundles[$contentType],
@@ -72,4 +81,16 @@ public function create(
return $nodes;
}
/**
* @param $node
* @param $count
*/
private function addRevision($node, $count) {
$node->setTitle($this->getRandom()->sentences(mt_rand(1, 5), true));
$node->setNewRevision(TRUE);
$node->revision_log = "Revision number $count was created";
$node->setRevisionCreationTime(REQUEST_TIME);
$node->save();
}
}

0 comments on commit e076e83

Please sign in to comment.
You can’t perform that action at this time.