You are here

class ConflictTracker in Multiversion 8.2

The Conflict Tracker service.

Hierarchy

Expanded class hierarchy of ConflictTracker

1 string reference to 'ConflictTracker'
multiversion.services.yml in ./multiversion.services.yml
multiversion.services.yml
1 service uses ConflictTracker
multiversion.conflict_tracker in ./multiversion.services.yml
Drupal\multiversion\Conflict\ConflictTracker

File

src/Conflict/ConflictTracker.php, line 12

Namespace

Drupal\multiversion\Conflict
View source
class ConflictTracker implements ConflictTrackerInterface {

  /**
   * The id of current workspace to query.
   *
   * @var string
   */
  protected $workspaceId;

  /**
   * The workspace manager service.
   *
   * @var \Drupal\workspaces\WorkspaceManagerInterface
   */
  protected $workspaceManager;

  /**
   * The key value factory service.
   *
   * @var \Drupal\Core\KeyValueStore\KeyValueFactoryInterface
   */
  protected $keyValueFactory;

  /**
   * The prefix to use for workspace conflicts.
   *
   * @var string
   */
  protected $collectionPrefix = 'workspace.conflicts.';

  /**
   * @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory
   * @param \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager
   */
  public function __construct(KeyValueFactoryInterface $key_value_factory, WorkspaceManagerInterface $workspace_manager) {
    $this->keyValueFactory = $key_value_factory;
    $this->workspaceManager = $workspace_manager;

    // Set workspace to currently active workspace.
    $this->workspaceId = $this->workspaceManager
      ->getActiveWorkspace()
      ->id();
  }

  /**
   * {@inheritdoc}
   */
  public function useWorkspace(Workspace $workspace = null) {
    $this->workspaceId = 0;
    if ($workspace) {
      $this->workspaceId = $workspace
        ->id();
    }
    return $this;
  }

  /**
   * @inheritDoc
   */
  public function add($uuid, array $revision_conflicts, $replace = FALSE) {
    if (!$replace) {
      $current_conflicts = $this
        ->keyValueStore()
        ->get($uuid);
      $revision_conflicts = array_merge($current_conflicts, $revision_conflicts);
    }
    $this
      ->keyValueStore()
      ->set($uuid, $revision_conflicts);
  }

  /**
   * @inheritDoc
   */
  public function resolveAll($uuid) {
    $this
      ->keyValueStore()
      ->delete($uuid);
  }

  /**
   * @inheritDoc
   */
  public function resolve($uuid, $revision_id) {
    $conflicts = $this
      ->keyValueStore()
      ->get($uuid);
    unset($conflicts[$revision_id]);
    $this
      ->keyValueStore()
      ->set($uuid, $conflicts);
  }

  /**
   * @inheritDoc
   */
  public function get($uuid) {
    return $this
      ->keyValueStore()
      ->get($uuid, []);
  }

  /**
   * @inheritDoc
   */
  public function getAll() {
    return $this
      ->keyValueStore()
      ->getAll();
  }

  /**
   * Gets the key value store used to store conflicts.
   *
   * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface
   */
  protected function keyValueStore() {
    return $this->keyValueFactory
      ->get($this->collectionPrefix . $this->workspaceId);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConflictTracker::$collectionPrefix protected property The prefix to use for workspace conflicts.
ConflictTracker::$keyValueFactory protected property The key value factory service.
ConflictTracker::$workspaceId protected property The id of current workspace to query.
ConflictTracker::$workspaceManager protected property The workspace manager service.
ConflictTracker::add public function @inheritDoc Overrides ConflictTrackerInterface::add
ConflictTracker::get public function @inheritDoc Overrides ConflictTrackerInterface::get
ConflictTracker::getAll public function @inheritDoc Overrides ConflictTrackerInterface::getAll
ConflictTracker::keyValueStore protected function Gets the key value store used to store conflicts.
ConflictTracker::resolve public function @inheritDoc Overrides ConflictTrackerInterface::resolve
ConflictTracker::resolveAll public function @inheritDoc Overrides ConflictTrackerInterface::resolveAll
ConflictTracker::useWorkspace public function Sets the workspace to be used in subsequent queries. Overrides ConflictTrackerInterface::useWorkspace
ConflictTracker::__construct public function