ConflictTracker.php in Multiversion 8
File
src/Workspace/ConflictTracker.php
View source
<?php
namespace Drupal\multiversion\Workspace;
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
use Drupal\multiversion\Entity\WorkspaceInterface;
class ConflictTracker implements ConflictTrackerInterface {
protected $workspaceId;
protected $workspaceManager;
protected $keyValueFactory;
protected $collectionPrefix = 'workspace.conflicts.';
public function __construct(KeyValueFactoryInterface $key_value_factory, WorkspaceManagerInterface $workspace_manager) {
$this->keyValueFactory = $key_value_factory;
$this->workspaceManager = $workspace_manager;
$this->workspaceId = $this->workspaceManager
->getActiveWorkspaceId();
}
public function useWorkspace(WorkspaceInterface $workspace = null) {
$this->workspaceId = 0;
if ($workspace) {
$this->workspaceId = $workspace
->id();
}
return $this;
}
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);
}
public function resolveAll($uuid) {
$this
->keyValueStore()
->delete($uuid);
}
public function resolve($uuid, $revision_id) {
$conflicts = $this
->keyValueStore()
->get($uuid);
unset($conflicts[$revision_id]);
$this
->keyValueStore()
->set($uuid, $conflicts);
}
public function get($uuid) {
return $this
->keyValueStore()
->get($uuid, []);
}
public function getAll() {
return $this
->keyValueStore()
->getAll();
}
protected function keyValueStore() {
return $this->keyValueFactory
->get($this->collectionPrefix . $this->workspaceId);
}
}