From 827469b264c3d226d8c43cbcb841b6599ae34d8c Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Tue, 3 Oct 2017 01:01:55 +0200
Subject: [PATCH] [TASK] Migrate lowlevel command for workspace cleanup

The workspace-related CLI command is moved to EXT:workspaces.

This way, an unneeded "isLoaded" check gets removed - and the command
only makes sense with workspaces enabled.

Resolves: #82653
Releases: master
Change-Id: Ifb1f069d8222d86be637bd2d182536310a88db3c
Reviewed-on: https://review.typo3.org/54265
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
---
 composer.json                                 |  3 ++-
 composer.lock                                 |  2 +-
 .../lowlevel/Configuration/Commands.php       |  7 ++---
 .../WorkspaceVersionRecordsCommand.php        | 27 +++++++++----------
 .../workspaces/Configuration/Commands.php     | 12 +++++++++
 .../Migrations/Code/ClassAliasMap.php         |  4 +++
 typo3/sysext/workspaces/composer.json         |  5 ++++
 7 files changed, 38 insertions(+), 22 deletions(-)
 rename typo3/sysext/{lowlevel => workspaces}/Classes/Command/WorkspaceVersionRecordsCommand.php (97%)
 create mode 100644 typo3/sysext/workspaces/Configuration/Commands.php
 create mode 100644 typo3/sysext/workspaces/Migrations/Code/ClassAliasMap.php

diff --git a/composer.json b/composer.json
index 669d42779f19..242503bd059f 100644
--- a/composer.json
+++ b/composer.json
@@ -76,7 +76,8 @@
 				"typo3/sysext/extbase/Migrations/Code/ClassAliasMap.php",
 				"typo3/sysext/fluid/Migrations/Code/ClassAliasMap.php",
 				"typo3/sysext/info/Migrations/Code/ClassAliasMap.php",
-				"typo3/sysext/version/Migrations/Code/ClassAliasMap.php"
+				"typo3/sysext/version/Migrations/Code/ClassAliasMap.php",
+				"typo3/sysext/workspaces/Migrations/Code/ClassAliasMap.php"
 			]
 		},
 		"branch-alias": {
diff --git a/composer.lock b/composer.lock
index 751f5f2d2b7a..8929c741778d 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "content-hash": "6b7e97c3d79b771c8920dcd06a0eede9",
+    "content-hash": "39fb5729c819eb6e537ecb0896070c60",
     "packages": [
         {
             "name": "cogpowered/finediff",
diff --git a/typo3/sysext/lowlevel/Configuration/Commands.php b/typo3/sysext/lowlevel/Configuration/Commands.php
index 0f39cdd549e5..258d4c245729 100644
--- a/typo3/sysext/lowlevel/Configuration/Commands.php
+++ b/typo3/sysext/lowlevel/Configuration/Commands.php
@@ -1,7 +1,7 @@
 <?php
 /**
- * Commands to be executed by typo3, where the key of the array
- * is the name of the command (to be called as the first argument after typo3).
+ * Commands to be executed by the typo3 CLI binary, where the key of the array
+ * is the name of the command (to be called as the first argument after "bin/typo3").
  * Required parameter is the "class" of the command which needs to be a subclass
  * of Symfony/Console/Command.
  */
@@ -32,8 +32,5 @@ return [
     ],
     'cleanup:flexforms' => [
         'class' => \TYPO3\CMS\Lowlevel\Command\CleanFlexFormsCommand::class,
-    ],
-    'cleanup:versions' => [
-        'class' => \TYPO3\CMS\Lowlevel\Command\WorkspaceVersionRecordsCommand::class,
     ]
 ];
diff --git a/typo3/sysext/lowlevel/Classes/Command/WorkspaceVersionRecordsCommand.php b/typo3/sysext/workspaces/Classes/Command/WorkspaceVersionRecordsCommand.php
similarity index 97%
rename from typo3/sysext/lowlevel/Classes/Command/WorkspaceVersionRecordsCommand.php
rename to typo3/sysext/workspaces/Classes/Command/WorkspaceVersionRecordsCommand.php
index 70e8e63e1377..c8b1149c13d6 100644
--- a/typo3/sysext/lowlevel/Classes/Command/WorkspaceVersionRecordsCommand.php
+++ b/typo3/sysext/workspaces/Classes/Command/WorkspaceVersionRecordsCommand.php
@@ -1,6 +1,6 @@
 <?php
 declare(strict_types=1);
-namespace TYPO3\CMS\Lowlevel\Command;
+namespace TYPO3\CMS\Workspaces\Command;
 
 /*
  * This file is part of the TYPO3 CMS project.
@@ -25,7 +25,6 @@ use TYPO3\CMS\Core\Core\Bootstrap;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\DataHandling\DataHandler;
-use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Core\Versioning\VersionState;
@@ -659,22 +658,20 @@ class WorkspaceVersionRecordsCommand extends Command
      */
     protected function loadAllWorkspaceRecords(): array
     {
-        if (ExtensionManagementUtility::isLoaded('workspaces')) {
-            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
-                ->getQueryBuilderForTable('sys_workspace');
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
+            ->getQueryBuilderForTable('sys_workspace');
 
-            $queryBuilder->getRestrictions()
-                ->removeAll()
-                ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+        $queryBuilder->getRestrictions()
+            ->removeAll()
+            ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
 
-            $result = $queryBuilder
-                ->select('uid', 'title')
-                ->from('sys_workspace')
-                ->execute();
+        $result = $queryBuilder
+            ->select('uid', 'title')
+            ->from('sys_workspace')
+            ->execute();
 
-            while ($workspaceRecord = $result->fetch()) {
-                $this->allWorkspaces[(int)$workspaceRecord['uid']] = $workspaceRecord['title'];
-            }
+        while ($workspaceRecord = $result->fetch()) {
+            $this->allWorkspaces[(int)$workspaceRecord['uid']] = $workspaceRecord['title'];
         }
         return $this->allWorkspaces;
     }
diff --git a/typo3/sysext/workspaces/Configuration/Commands.php b/typo3/sysext/workspaces/Configuration/Commands.php
new file mode 100644
index 000000000000..0eca60804a34
--- /dev/null
+++ b/typo3/sysext/workspaces/Configuration/Commands.php
@@ -0,0 +1,12 @@
+<?php
+/**
+ * Commands to be executed by the typo3 CLI binary, where the key of the array
+ * is the name of the command (to be called as the first argument after "bin/typo3").
+ * Required parameter is the "class" of the command which needs to be a subclass
+ * of Symfony/Console/Command.
+ */
+return [
+    'cleanup:versions' => [
+        'class' => \TYPO3\CMS\Workspaces\Command\WorkspaceVersionRecordsCommand::class,
+    ]
+];
diff --git a/typo3/sysext/workspaces/Migrations/Code/ClassAliasMap.php b/typo3/sysext/workspaces/Migrations/Code/ClassAliasMap.php
new file mode 100644
index 000000000000..38a19d0d9229
--- /dev/null
+++ b/typo3/sysext/workspaces/Migrations/Code/ClassAliasMap.php
@@ -0,0 +1,4 @@
+<?php
+return [
+    'TYPO3\\CMS\\Lowlevel\\Command\\WorkspaceVersionRecordsCommand' => \TYPO3\CMS\Workspaces\Command\WorkspaceVersionRecordsCommand::class,
+];
diff --git a/typo3/sysext/workspaces/composer.json b/typo3/sysext/workspaces/composer.json
index f25527a0d8e3..1f5d2f4a80ab 100644
--- a/typo3/sysext/workspaces/composer.json
+++ b/typo3/sysext/workspaces/composer.json
@@ -24,6 +24,11 @@
 		"branch-alias": {
 			"dev-master": "9.x-dev"
 		},
+		"typo3/class-alias-loader": {
+			"class-alias-maps": [
+				"Migrations/Code/ClassAliasMap.php"
+			]
+		},
 		"typo3/cms": {
 			"extension-key": "workspaces"
 		}
-- 
GitLab