-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from punktDe/bugfix/handle-internal-and-private…
…-workspaces !!! TASK: Ignore internal and private workspaces on calculating changes
- Loading branch information
Showing
2 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace PunktDe\EditConflictPrevention\Service; | ||
|
||
/* | ||
* (c) 2021 punkt.de GmbH - Karlsruhe, Germany - http://punkt.de | ||
* All rights reserved. | ||
*/ | ||
|
||
use Neos\ContentRepository\Domain\Model\Workspace; | ||
use Neos\ContentRepository\Domain\Repository\WorkspaceRepository; | ||
use Neos\Flow\Annotations as Flow; | ||
|
||
/** | ||
* @Flow\Scope("singleton") | ||
*/ | ||
class WorkspaceService | ||
{ | ||
|
||
/** | ||
* @Flow\Inject | ||
* @var WorkspaceRepository | ||
*/ | ||
protected $workspaceRepository; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $internalWorkspaceNames = null; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $privateWorkspaceNames = null; | ||
|
||
public function getInternalWorkspaceNames(): array | ||
{ | ||
if (is_array($this->internalWorkspaceNames)) { | ||
return $this->internalWorkspaceNames; | ||
} | ||
|
||
$query = $this->workspaceRepository->createQuery(); | ||
$result = $query->matching( | ||
$query->logicalAnd( | ||
$query->logicalNot($query->equals('baseWorkspace', null)), | ||
$query->equals('owner', null) | ||
) | ||
)->execute(); | ||
|
||
$this->internalWorkspaceNames = array_map(static function (Workspace $workspace) { | ||
return $workspace->getName(); | ||
}, $result->toArray()); | ||
|
||
return $this->internalWorkspaceNames; | ||
} | ||
|
||
public function getPrivateWorkspaceNames(): array | ||
{ | ||
if (is_array($this->privateWorkspaceNames)) { | ||
return $this->privateWorkspaceNames; | ||
} | ||
|
||
$query = $this->workspaceRepository->createQuery(); | ||
$result = $query->matching( | ||
$query->logicalAnd( | ||
$query->logicalNot($query->equals('baseWorkspace', null)), | ||
$query->logicalNot($query->equals('owner', null)), | ||
$query->logicalNot('name', Workspace::PERSONAL_WORKSPACE_PREFIX . '%') | ||
) | ||
)->execute(); | ||
|
||
$this->privateWorkspaceNames = array_map(static function (Workspace $workspace) { | ||
return $workspace->getName(); | ||
}, $result->toArray()); | ||
|
||
return $this->privateWorkspaceNames; | ||
} | ||
} |