getDifferringRevisionIdsOnSource example

$workspace_publisher = \Drupal::service('workspaces.operation_factory')->getPublisher($this->workspaces['stage']);

    // Check which revisions need to be pushed.     $expected = [
      'node' => [
        3 => 1,
        4 => 2,
        5 => 3,
        7 => 4,
      ],
    ];
    $this->assertEquals($expected$workspace_publisher->getDifferringRevisionIdsOnSource());

    $this->workspaces['stage']->publish();
    $this->assertWorkspaceStatus($test_scenarios['push_stage_to_live'], 'node');
    $this->assertWorkspaceAssociation($expected_workspace_association['push_stage_to_live'], 'node');

    // Check that all the revisions that were published to 'Live' were also     // marked as default revisions in their revision metadata field.     $published_revisions = $this->entityTypeManager->getStorage('node')->loadMultipleRevisions(array_keys($expected['node']));
    foreach ($published_revisions as $published_revision) {
      $this->assertTrue($published_revision->wasDefaultRevision());
    }

    
$workspace_merger = \Drupal::service('workspaces.operation_factory')->getMerger($this->workspaces['local_1']$this->workspaces['dev']);

    // Check that there is no content in Dev that's not also in Local 1.     $this->assertEmpty($workspace_merger->getDifferringRevisionIdsOnTarget());
    $this->assertEquals(0, $workspace_merger->getNumberOfChangesOnTarget());

    // Check that there is only one node in Local 1 that's not available in Dev,     // revision 7 created above for the fourth test article.     $expected = [
      'node' => [7 => 4],
    ];
    $this->assertEquals($expected$workspace_merger->getDifferringRevisionIdsOnSource());
    $this->assertEquals(1, $workspace_merger->getNumberOfChangesOnSource());

    // Merge the contents of Local 1 into Dev, and check that Dev, Local 1 and     // Local 2 have the same content.     $workspace_merger->merge();

    $this->assertEmpty($workspace_merger->getDifferringRevisionIdsOnTarget());
    $this->assertEquals(0, $workspace_merger->getNumberOfChangesOnTarget());
    $this->assertEmpty($workspace_merger->getDifferringRevisionIdsOnSource());
    $this->assertEquals(0, $workspace_merger->getNumberOfChangesOnSource());

    
$form = parent::buildForm($form$form_state);

    $workspace_publisher = $this->workspaceOperationFactory->getPublisher($this->workspace);

    $args = [
      '%source_label' => $this->workspace->label(),
      '%target_label' => $workspace_publisher->getTargetLabel(),
    ];
    $form['#title'] = $this->t('Publish %source_label workspace', $args);

    // List the changes that can be pushed.     if ($source_rev_diff = $workspace_publisher->getDifferringRevisionIdsOnSource()) {
      $total_count = $workspace_publisher->getNumberOfChangesOnSource();
      $form['description'] = [
        '#theme' => 'item_list',
        '#title' => $this->formatPlural($total_count, 'There is @count item that can be published from %source_label to %target_label', 'There are @count items that can be published from %source_label to %target_label', $args),
        '#items' => [],
        '#total_count' => $total_count,
      ];
      foreach ($source_rev_diff as $entity_type_id => $revision_difference) {
        $form['description']['#items'][$entity_type_id] = $this->entityTypeManager->getDefinition($entity_type_id)->getCountLabel(count($revision_difference));
      }

      
public function merge() {
    if (!$this->sourceWorkspace->hasParent() || $this->sourceWorkspace->parent->target_id != $this->targetWorkspace->id()) {
      throw new \InvalidArgumentException('The contents of a workspace can only be merged into its parent workspace.');
    }

    if ($this->checkConflictsOnTarget()) {
      throw new WorkspaceConflictException();
    }

    try {
      $transaction = $this->database->startTransaction();
      foreach ($this->getDifferringRevisionIdsOnSource() as $entity_type_id => $revision_difference) {
        $revisions_on_source = $this->entityTypeManager->getStorage($entity_type_id)
          ->loadMultipleRevisions(array_keys($revision_difference));

        /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
        foreach ($revisions_on_source as $revision) {
          // Track all the differing revisions from the source workspace in           // the context of the target workspace. This will automatically           // update all the descendants of the target workspace as well.           $this->workspaceAssociation->trackEntity($revision$this->targetWorkspace);
        }

        
$form = parent::buildForm($form$form_state);

    $workspace_merger = $this->workspaceOperationFactory->getMerger($this->sourceWorkspace, $this->targetWorkspace);

    $args = [
      '%source_label' => $this->sourceWorkspace->label(),
      '%target_label' => $this->targetWorkspace->label(),
    ];

    // List the changes that can be merged into the target.     if ($source_rev_diff = $workspace_merger->getDifferringRevisionIdsOnSource()) {
      $total_count = $workspace_merger->getNumberOfChangesOnSource();
      $form['merge'] = [
        '#theme' => 'item_list',
        '#title' => $this->formatPlural($total_count, 'There is @count item that can be merged from %source_label to %target_label', 'There are @count items that can be merged from %source_label to %target_label', $args),
        '#items' => [],
        '#total_count' => $total_count,
      ];
      foreach ($source_rev_diff as $entity_type_id => $revision_difference) {
        $form['merge']['#items'][$entity_type_id] = $this->entityTypeManager->getDefinition($entity_type_id)->getCountLabel(count($revision_difference));
      }
    }

    

  public function getNumberOfChangesOnTarget() {
    $total_changes = $this->getDifferringRevisionIdsOnTarget();
    return count($total_changes, COUNT_RECURSIVE) - count($total_changes);
  }

  /** * {@inheritdoc} */
  public function getNumberOfChangesOnSource() {
    $total_changes = $this->getDifferringRevisionIdsOnSource();
    return count($total_changes, COUNT_RECURSIVE) - count($total_changes);
  }

}
Home | Imprint | This part of the site doesn't use cookies.