-
-
Notifications
You must be signed in to change notification settings - Fork 244
FEATURE: Command to delete stale workspaces #5770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sachera
wants to merge
19
commits into
neos:9.2
Choose a base branch
from
sachera:feature/delete-inactive-workspace
base: 9.2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e62cb5f
FEATURE: Command to delete stale workspaces
sachera 6a2f20e
TASK: Move stale workspace detection logic to WorkspaceService
sachera 09c92e2
TASK: Refactor checking if a workspace has workspaces depending on them
sachera 97836c2
TASK: Remove `@throws` annotations which have no effect on a Flow CLI…
mhsdesign 3db6be5
TASK: Keep time calculation logic in command controller to have Works…
mhsdesign 5e6100a
TASK: Use static `PHPUnit\Framework\Assert` as in other places
mhsdesign 865bea7
TASK: Simplify api of `getStaleWorkspaceNames()` to not include unuse…
mhsdesign adaa2bc
TASK: Introduce typed collections for `WorkspaceNames` and `UserIds`
mhsdesign 8e7240b
TASK: Rename `getStaleWorkspaceNames` to `getStalePersonalWorkspaceNa…
mhsdesign e350988
TASK: countable WorkspaceNames
mhsdesign 28a9527
TASK: Move feature from `ContentRepository` context to own `User` con…
mhsdesign e0e8d44
TASK: Ensure WorkspaceService fully encapsulates stale workspace dele…
mhsdesign 64f9112
WIP: Add failing test that `createPersonalWorkspaceForUserIfMissing()…
mhsdesign 321a7ef
TASK: Do not force specific order in tests for stale workspaces and u…
sachera 336be2f
TASK: Allow any order for set of existing workspaces in tests
sachera 5e988ab
TASK: Recreate personal Workspaces if Metadata still exists but the W…
sachera be9a9d4
TASK: Run WorkspaceMetadata Cleanup after test rather than before to …
sachera 70e390d
WIP: Add testcase to show stale workspace recreation works for "live"…
sachera 445a6eb
Task: Fix linting errors
sachera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
Neos.ContentRepository.Core/Classes/SharedModel/Workspace/WorkspaceNames.php
This file contains hidden or 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,56 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Neos\ContentRepository\Core\SharedModel\Workspace; | ||
|
|
||
| /** | ||
| * @implements \IteratorAggregate<int,WorkspaceName> | ||
| * @api | ||
| */ | ||
| final readonly class WorkspaceNames implements \IteratorAggregate, \Countable | ||
| { | ||
| /** @param array<string,WorkspaceName> $items */ | ||
| private function __construct( | ||
| private array $items | ||
| ) { | ||
| } | ||
|
|
||
| public static function create( | ||
| WorkspaceName ...$items | ||
| ): self { | ||
| $indexed = []; | ||
| foreach ($items as $item) { | ||
| $indexed[$item->value] = $item; | ||
| } | ||
| return new self( | ||
| $indexed | ||
| ); | ||
| } | ||
|
|
||
| public static function fromWorkspaces(Workspaces $workspaces): self | ||
| { | ||
| return WorkspaceNames::create(...$workspaces->map(fn (Workspace $workspace) => $workspace->workspaceName)); | ||
| } | ||
|
|
||
| public function contain(WorkspaceName $workspaceName): bool | ||
| { | ||
| return array_key_exists($workspaceName->value, $this->items); | ||
| } | ||
|
|
||
| /** @return list<string> */ | ||
| public function toStringArray(): array | ||
| { | ||
| return array_keys($this->items); | ||
| } | ||
|
|
||
| public function getIterator(): \Traversable | ||
| { | ||
| yield from array_values($this->items); | ||
| } | ||
|
|
||
| public function count(): int | ||
| { | ||
| return count($this->items); | ||
| } | ||
| } |
63 changes: 63 additions & 0 deletions
63
Neos.ContentRepository.Core/Tests/Unit/SharedModel/Workspace/WorkspaceNamesTest.php
This file contains hidden or 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,63 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Neos\ContentRepository\Core\Tests\Unit\SharedModel\Workspace; | ||
|
|
||
| use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; | ||
| use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace; | ||
| use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; | ||
| use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceNames; | ||
| use Neos\ContentRepository\Core\SharedModel\Workspace\Workspaces; | ||
| use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceStatus; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| class WorkspaceNamesTest extends TestCase | ||
| { | ||
| /** | ||
| * @test | ||
| */ | ||
| public function contain() | ||
| { | ||
| $workspaceNames = WorkspaceNames::create( | ||
| $nameInstance = WorkspaceName::fromString('foo'), | ||
| WorkspaceName::fromString('bar'), | ||
| ); | ||
|
|
||
| self::assertTrue($workspaceNames->contain($nameInstance)); | ||
| self::assertTrue($workspaceNames->contain(WorkspaceName::fromString('foo'))); | ||
| self::assertFalse($workspaceNames->contain(WorkspaceName::fromString('not-included'))); | ||
| } | ||
|
|
||
| /** | ||
| * @test | ||
| */ | ||
| public function fromWorkspaces() | ||
| { | ||
| $workspaces = Workspaces::fromArray([ | ||
| self::workspace('root', null), | ||
| self::workspace('regular', 'root'), | ||
| self::workspace('other-root', null), | ||
| ]); | ||
|
|
||
| self::assertEquals( | ||
| WorkspaceNames::create( | ||
| WorkspaceName::fromString('root'), | ||
| WorkspaceName::fromString('regular'), | ||
| WorkspaceName::fromString('other-root'), | ||
| ), | ||
| WorkspaceNames::fromWorkspaces($workspaces) | ||
| ); | ||
| } | ||
|
|
||
| private static function workspace(string $name): Workspace | ||
| { | ||
| return Workspace::create( | ||
| WorkspaceName::fromString($name), | ||
| null, | ||
| ContentStreamId::create(), | ||
| WorkspaceStatus::UP_TO_DATE, | ||
| false | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,45 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Neos\Neos\Domain\Model; | ||
|
|
||
| /** | ||
| * @implements \IteratorAggregate<int,UserId> | ||
| */ | ||
| final readonly class UserIds implements \IteratorAggregate | ||
| { | ||
| /** @param array<string,UserId> $items */ | ||
| private function __construct( | ||
| private array $items | ||
| ) { | ||
| } | ||
|
|
||
| public static function create( | ||
| UserId ...$items | ||
| ): self { | ||
| $indexed = []; | ||
| foreach ($items as $item) { | ||
| $indexed[$item->value] = $item; | ||
| } | ||
| return new self( | ||
| $indexed | ||
| ); | ||
| } | ||
|
|
||
| public function contain(UserId $userId): bool | ||
| { | ||
| return array_key_exists($userId->value, $this->items); | ||
| } | ||
|
|
||
| /** @return list<string> */ | ||
| public function toStringArray(): array | ||
| { | ||
| return array_keys($this->items); | ||
| } | ||
|
|
||
| public function getIterator(): \Traversable | ||
| { | ||
| yield from array_values($this->items); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest a different naming for the command. The command sounds it removes any stale workspace, but the comment correctly explains its only certain user workspaces. Though a note on their automatic recreation would also be helpful here in the comment.
If we hopefully soonish can extend the removal to other types of workspaces with potential different rules, we have a naming clash. Or what did you think about future future extensions?