Loading src/NodeRevisionDelete.php +1 −1 Original line number Diff line number Diff line Loading @@ -511,7 +511,7 @@ class NodeRevisionDelete implements NodeRevisionDeleteInterface { // Adding the operation. $batch_builder->addOperation( [NodeRevisionDeleteBatch::class, 'deleteRevision'], [$revision, $dry_run] [$revision, $dry_run, count($revisions)] ); } Loading src/NodeRevisionDeleteBatch.php +22 −3 Original line number Diff line number Diff line Loading @@ -20,13 +20,17 @@ class NodeRevisionDeleteBatch { * @param bool $dry_run * Indicate if we need to delete or not the revision. TRUE for test purpose * FALSE to delete the revision. * @param int $total * The total number of items to be processed. * @param mixed $context * The context of the current batch. * * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ public static function deleteRevision($revision, bool $dry_run, &$context): void { public static function deleteRevision($revision, bool $dry_run, int $total, &$context): void { $node_storage = \Drupal::entityTypeManager()->getStorage('node'); if (empty($context['results'])) { $context['results']['revisions'] = 0; Loading @@ -34,6 +38,9 @@ class NodeRevisionDeleteBatch { // Update context of the current node. $context['results']['node'] = $revision; } else { $context['results']['node'] = $node_storage->loadRevision($revision); } } if ($revision instanceof Node) { Loading @@ -43,13 +50,25 @@ class NodeRevisionDeleteBatch { // Checking if this is a dry run or we really need to delete the variable. if (!$dry_run) { // Delete the revision. \Drupal::entityTypeManager()->getStorage('node')->deleteRevision($revision); $node_storage->deleteRevision($revision); } // Count the number of revisions deleted. $context['results']['revisions']++; // Adding a message for the actual revision being deleted. $context['message'] = t('Processing revision: @id', ['@id' => $revision]); /** @var \Drupal\node\NodeInterface $node */ $node = $context['results']['node']; $message = t('@current / @total - Revision @rid of node @nid - @lang - @title', [ '@rid' => $revision, '@nid' => $node->id(), '@lang' => $node->language()->getId(), '@title' => $node->label(), '@current' => $context['results']['revisions'], '@total' => $total, ]); $context['message'] = $dry_run ? '[DRY-RUN] - ' . $message : $message; } /** Loading tests/src/Kernel/NodeRevisionDeleteQueryAlterTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ class NodeRevisionDeleteQueryAlterTest extends KernelTestBase { /** * {@inheritdoc} */ public function setUp() { public function setUp(): void { parent::setUp(); $this->installEntitySchema('node'); Loading tests/src/Unit/NodeRevisionDeleteTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -358,7 +358,7 @@ class NodeRevisionDeleteTest extends UnitTestCase { foreach ($revisions as $revision) { $expected[$set]['operations'][] = [ [NodeRevisionDeleteBatch::class, 'deleteRevision'], [$revision, $dry_run_set[$set]], [$revision, $dry_run_set[$set], count($revisions)], ]; } } Loading Loading
src/NodeRevisionDelete.php +1 −1 Original line number Diff line number Diff line Loading @@ -511,7 +511,7 @@ class NodeRevisionDelete implements NodeRevisionDeleteInterface { // Adding the operation. $batch_builder->addOperation( [NodeRevisionDeleteBatch::class, 'deleteRevision'], [$revision, $dry_run] [$revision, $dry_run, count($revisions)] ); } Loading
src/NodeRevisionDeleteBatch.php +22 −3 Original line number Diff line number Diff line Loading @@ -20,13 +20,17 @@ class NodeRevisionDeleteBatch { * @param bool $dry_run * Indicate if we need to delete or not the revision. TRUE for test purpose * FALSE to delete the revision. * @param int $total * The total number of items to be processed. * @param mixed $context * The context of the current batch. * * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ public static function deleteRevision($revision, bool $dry_run, &$context): void { public static function deleteRevision($revision, bool $dry_run, int $total, &$context): void { $node_storage = \Drupal::entityTypeManager()->getStorage('node'); if (empty($context['results'])) { $context['results']['revisions'] = 0; Loading @@ -34,6 +38,9 @@ class NodeRevisionDeleteBatch { // Update context of the current node. $context['results']['node'] = $revision; } else { $context['results']['node'] = $node_storage->loadRevision($revision); } } if ($revision instanceof Node) { Loading @@ -43,13 +50,25 @@ class NodeRevisionDeleteBatch { // Checking if this is a dry run or we really need to delete the variable. if (!$dry_run) { // Delete the revision. \Drupal::entityTypeManager()->getStorage('node')->deleteRevision($revision); $node_storage->deleteRevision($revision); } // Count the number of revisions deleted. $context['results']['revisions']++; // Adding a message for the actual revision being deleted. $context['message'] = t('Processing revision: @id', ['@id' => $revision]); /** @var \Drupal\node\NodeInterface $node */ $node = $context['results']['node']; $message = t('@current / @total - Revision @rid of node @nid - @lang - @title', [ '@rid' => $revision, '@nid' => $node->id(), '@lang' => $node->language()->getId(), '@title' => $node->label(), '@current' => $context['results']['revisions'], '@total' => $total, ]); $context['message'] = $dry_run ? '[DRY-RUN] - ' . $message : $message; } /** Loading
tests/src/Kernel/NodeRevisionDeleteQueryAlterTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ class NodeRevisionDeleteQueryAlterTest extends KernelTestBase { /** * {@inheritdoc} */ public function setUp() { public function setUp(): void { parent::setUp(); $this->installEntitySchema('node'); Loading
tests/src/Unit/NodeRevisionDeleteTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -358,7 +358,7 @@ class NodeRevisionDeleteTest extends UnitTestCase { foreach ($revisions as $revision) { $expected[$set]['operations'][] = [ [NodeRevisionDeleteBatch::class, 'deleteRevision'], [$revision, $dry_run_set[$set]], [$revision, $dry_run_set[$set], count($revisions)], ]; } } Loading