public function NodeRevisionGenerate::getRevisionCreationBatch in Node Revision Delete 8
Return the revision creation batch definition.
Parameters
array $nodes_for_revisions: The nodes for revisions array.
int $revisions_number: Number of revisions to generate.
int $revisions_age: Interval in Unix timestamp format to add to the last revision date of the node.
Return value
array The batch definition.
Overrides NodeRevisionGenerateInterface::getRevisionCreationBatch
File
- modules/
node_revision_generate/ src/ NodeRevisionGenerate.php, line 86
Class
- NodeRevisionGenerate
- Class NodeRevisionGenerate.
Namespace
Drupal\node_revision_generateCode
public function getRevisionCreationBatch(array $nodes_for_revisions, $revisions_number, $revisions_age) {
// Defining the batch builder.
$batch_builder = new BatchBuilder();
$batch_builder
->setTitle($this
->t('Generating revisions'))
->setInitMessage($this
->t('Starting to create revisions.'))
->setProgressMessage($this
->t('Processed @current out of @total (@percentage%). Estimated time: @estimate.'))
->setErrorMessage($this
->t('The revision creation process has encountered an error.'))
->setFinishCallback([
NodeRevisionGenerateBatch::class,
'finish',
]);
// Building batch operations, one per revision.
foreach ($nodes_for_revisions as $node) {
$revision_timestamp = $node->revision_timestamp;
// Initializing variables.
$i = 0;
$revision_timestamp += $revisions_age;
// Adding operations.
while ($i < $revisions_number && $revision_timestamp <= $this->time
->getRequestTime()) {
// Adding the operation.
$batch_builder
->addOperation([
NodeRevisionGenerateBatch::class,
'generateRevisions',
], [
$node->nid,
$revision_timestamp,
]);
$revision_timestamp += $revisions_age;
$i++;
}
}
return $batch_builder
->toArray();
}