[TASK] Have EM only evaluate current ext_tables.sql on installation 73/57173/4
authorBenni Mack <benni@typo3.org>
Mon, 11 Jun 2018 06:34:19 +0000 (08:34 +0200)
committerNicole Cordes <typo3@cordes.co>
Mon, 11 Jun 2018 09:47:11 +0000 (11:47 +0200)
The EM changes due to the new automatic DB fields addition for TCA-based
tables come with a small side-effect, namely that all extensions are
now evaluated when doing the SQL create queries.

The introduced changes now only do execute "safe" DB updates, but not
limited to an extension, but for all installed extensions.
Thus, non-safe DB operations are not taken into account for an extension
installation/upgrade anymore.

The patch reverts the changes to the original behaviour, so that a
follow-up patch can introduce the following behaviour:
- Install extension
- Do _safe_ DB updates for the whole system
- Do breaking DB updates for the extensions to be installed/upgraded
- Execute ext_tables_*adt.sql files + imports

Resolves: #85215
Releases: master
Change-Id: Ief1118319eb0afcd586efdff506cf44d00e02fb7
Reviewed-on: https://review.typo3.org/57173
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
typo3/sysext/core/Documentation/Changelog/9.3/Important-85160-NonDesctructiveDatabaseSchemaChangesInExtensionManager.rst [deleted file]
typo3/sysext/extensionmanager/Classes/Controller/ActionController.php
typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php
typo3/sysext/extensionmanager/Tests/Unit/Utility/InstallUtilityTest.php

diff --git a/typo3/sysext/core/Documentation/Changelog/9.3/Important-85160-NonDesctructiveDatabaseSchemaChangesInExtensionManager.rst b/typo3/sysext/core/Documentation/Changelog/9.3/Important-85160-NonDesctructiveDatabaseSchemaChangesInExtensionManager.rst
deleted file mode 100644 (file)
index ebaf056..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-.. include:: ../../Includes.txt
-
-================================================================================
-Important: #85160 - Non destructive database schema changes in extension manager
-================================================================================
-
-See :issue:`85160`
-
-Description
-===========
-
-When loading or updating an extension using the backend extension manager, only
-non destructive database schema changes are applied.
-
-If for example a new version of an extension brings a **new** column, index or table
-that does not exist locally yet, it will be **added**.
-
-If the extension however for example **changes** the length of an existing field
-or **removes** a column, index or table definition, these changes are
-**not automatically applied** when loading or updating the extension. Administrators use
-the database analyzer in Admin Tools -> Maintenance view to review and perform these
-potentially destructive changes manually.
-
-Additionally, missing fields or tables from other extensions are also added if an
-extension is loaded, even if the extension that is loaded does not touch the
-table in its :file:`ext_tables.sql` file.
-
-.. index:: Database, TCA, ext:extensionmanager
\ No newline at end of file
index f9c48c1..5a8db9a 100644 (file)
@@ -170,7 +170,7 @@ class ActionController extends AbstractController
         $registry = GeneralUtility::makeInstance(Registry::class);
         $registry->remove('extensionDataImport', $registryKey);
 
-        $this->installUtility->importStaticSqlFile($extension['siteRelPath']);
+        $this->installUtility->processDatabaseUpdates($extension);
 
         $this->redirect('index', 'List');
     }
index 1c665b2..b176edc 100644 (file)
@@ -360,7 +360,7 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface
         }
         if ($extTablesSqlContent !== '') {
             try {
-                $this->updateDbWithExtTablesSql();
+                $this->updateDbWithExtTablesSql($extTablesSqlContent);
             } catch (\TYPO3\CMS\Core\Database\Schema\Exception\StatementException $e) {
                 throw new ExtensionManagerException(
                     $e->getMessage(),
@@ -449,18 +449,13 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface
      *
      * @param string $rawDefinitions The raw SQL statements from ext_tables.sql
      */
-    public function updateDbWithExtTablesSql($rawDefinitions = null)
+    public function updateDbWithExtTablesSql($rawDefinitions)
     {
         $sqlReader = GeneralUtility::makeInstance(SqlReader::class);
-        if ($rawDefinitions !== null) {
-            $statements = $sqlReader->getCreateTableStatementArray($rawDefinitions);
-        } else {
-            // Read all ext_tables.sql files including new loaded extension
-            $statements = $sqlReader->getCreateTableStatementArray($sqlReader->getTablesDefinitionString());
-        }
+        $statements = $sqlReader->getCreateTableStatementArray($rawDefinitions);
         if (count($statements) !== 0) {
             $schemaMigrationService = GeneralUtility::makeInstance(SchemaMigrator::class);
-            $schemaMigrationService->install($statements, true);
+            $schemaMigrationService->install($statements);
         }
     }
 
@@ -606,7 +601,7 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface
      *
      * @param string $extensionSiteRelPath
      */
-    public function importStaticSqlFile($extensionSiteRelPath)
+    protected function importStaticSqlFile($extensionSiteRelPath)
     {
         $extTablesStaticSqlRelFile = $extensionSiteRelPath . 'ext_tables_static+adt.sql';
         if (!$this->registry->get('extensionDataImport', $extTablesStaticSqlRelFile)) {
index 2419052..0aa6278 100644 (file)
@@ -223,12 +223,12 @@ class InstallUtilityTest extends UnitTestCase
     /**
      * @test
      */
-    public function processDatabaseUpdatesCallsUpdateDb()
+    public function processDatabaseUpdatesCallsUpdateDbWithExtTablesSql()
     {
         $extKey = $this->createFakeExtension();
         $extPath = PATH_site . 'typo3temp/var/tests/' . $extKey . '/';
         $extTablesFile = $extPath . 'ext_tables.sql';
-        $fileContent = 'DUMMY TEXT';
+        $fileContent = 'DUMMY TEXT TO COMPARE';
         file_put_contents($extTablesFile, $fileContent);
         $installMock = $this->getAccessibleMock(
             InstallUtility::class,
@@ -240,7 +240,7 @@ class InstallUtilityTest extends UnitTestCase
         $dependencyUtility = $this->getMockBuilder(DependencyUtility::class)->getMock();
         $installMock->_set('dependencyUtility', $dependencyUtility);
 
-        $installMock->expects($this->once())->method('updateDbWithExtTablesSql');
+        $installMock->expects($this->once())->method('updateDbWithExtTablesSql')->with($this->stringStartsWith($fileContent));
         $installMock->processDatabaseUpdates($this->fakedExtensions[$extKey]);
     }