Commit 1f2b394c authored by Robert Ngo's avatar Robert Ngo Committed by Adrian Cid Almaguer
Browse files

Issue #3280435 by Robert Ngo, alberto56, adriancid: Provide more feedback on...

Issue #3280435 by Robert Ngo, alberto56, adriancid: Provide more feedback on where we're at with node revision deletion
parent dbcb0e5c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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)]
      );
    }

+22 −3
Original line number Diff line number Diff line
@@ -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;

@@ -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) {
@@ -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;
  }

  /**
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ class NodeRevisionDeleteQueryAlterTest extends KernelTestBase {
  /**
   * {@inheritdoc}
   */
  public function setUp() {
  public function setUp(): void {
    parent::setUp();

    $this->installEntitySchema('node');
+1 −1
Original line number Diff line number Diff line
@@ -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)],
        ];
      }
    }