Skip to content

Commit

Permalink
[create:nodes] Added the revision option (#4091)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjuarez20 authored and enzolutions committed Jun 17, 2019
1 parent e03c085 commit e076e83
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Command/Create/NodesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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';

Expand All @@ -211,6 +227,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$limit,
$titleWords,
$timeRange,
$revision,
$language
);

Expand Down
21 changes: 21 additions & 0 deletions src/Utils/Create/NodeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class NodeData extends Base
* @param $limit
* @param $titleWords
* @param $timeRange
* @param $revision
*
* @return array
*/
Expand All @@ -32,6 +33,7 @@ public function create(
$limit,
$titleWords,
$timeRange,
$revision,
$language = LanguageInterface::LANGCODE_NOT_SPECIFIED
) {
$nodes = [];
Expand All @@ -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],
Expand All @@ -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.