[BUGFIX] Restore update wizard to add TER repository in EM 03/46303/6
authorWouter Wolters <typo3@wouterwolters.nl>
Thu, 28 Jan 2016 22:29:23 +0000 (23:29 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 15 Feb 2016 10:37:58 +0000 (11:37 +0100)
This adds the update wizard again for TER repository in EM.

Resolves: #72917
Releases: master, 7.6
Change-Id: I1d4d6750c1e989a4ca3fadbcf6e753555ae26f5f
Reviewed-on: https://review.typo3.org/46303
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Markus Sommer <markussom@posteo.de>
Tested-by: Markus Sommer <markussom@posteo.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/install/Classes/Updates/ExtensionManagerTables.php [new file with mode: 0644]
typo3/sysext/install/ext_localconf.php

diff --git a/typo3/sysext/install/Classes/Updates/ExtensionManagerTables.php b/typo3/sysext/install/Classes/Updates/ExtensionManagerTables.php
new file mode 100644 (file)
index 0000000..0727911
--- /dev/null
@@ -0,0 +1,153 @@
+<?php
+namespace TYPO3\CMS\Install\Updates;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Contains the update class for filling the basic repository record of the extension manager
+ */
+class ExtensionManagerTables extends AbstractUpdate
+{
+
+    /**
+     * @var string
+     */
+    protected $title = 'Add the default Extension Manager database tables';
+
+    /**
+     * @var NULL|\TYPO3\CMS\Install\Service\SqlSchemaMigrationService
+     */
+    protected $installToolSqlParser = null;
+
+    /**
+     * @return \TYPO3\CMS\Install\Service\SqlSchemaMigrationService
+     */
+    protected function getInstallToolSqlParser()
+    {
+        if ($this->installToolSqlParser === null) {
+            $this->installToolSqlParser = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Service\SqlSchemaMigrationService::class);
+        }
+
+        return $this->installToolSqlParser;
+    }
+
+    /**
+     * Gets all create, add and change queries from ext_tables.sql
+     *
+     * @return array
+     */
+    protected function getUpdateStatements()
+    {
+        $updateStatements = array();
+
+        // Get all necessary statements for ext_tables.sql file
+        $rawDefinitions = GeneralUtility::getUrl(ExtensionManagementUtility::extPath('extensionmanager') . '/ext_tables.sql');
+        $fieldDefinitionsFromFile = $this->getInstallToolSqlParser()->getFieldDefinitions_fileContent($rawDefinitions);
+        if (count($fieldDefinitionsFromFile)) {
+            $fieldDefinitionsFromCurrentDatabase = $this->getInstallToolSqlParser()->getFieldDefinitions_database();
+            $diff = $this->getInstallToolSqlParser()->getDatabaseExtra($fieldDefinitionsFromFile, $fieldDefinitionsFromCurrentDatabase);
+            $updateStatements = $this->getInstallToolSqlParser()->getUpdateSuggestions($diff);
+        }
+
+        return $updateStatements;
+    }
+
+    /**
+     * Checks if an update is needed
+     *
+     * @param string &$description The description for the update
+     * @return bool Whether an update is needed (TRUE) or not (FALSE)
+     */
+    public function checkForUpdate(&$description)
+    {
+        $result = false;
+        $description = 'Creates necessary database tables and adds static data for the Extension Manager.';
+
+        // First check necessary database update
+        $updateStatements = $this->getUpdateStatements();
+        if (empty($updateStatements)) {
+            // Get count of rows in repository database table
+            $count = $this->getDatabaseConnection()->exec_SELECTcountRows('*', 'tx_extensionmanager_domain_model_repository');
+            if ($count === 0) {
+                $result = true;
+            }
+        } else {
+            $result = true;
+        }
+
+        return $result;
+    }
+
+    /**
+     * @param mixed &$customMessages Custom messages
+     *
+     * @return bool
+     */
+    protected function hasError(&$customMessages)
+    {
+        $result = false;
+        if ($this->getDatabaseConnection()->sql_error()) {
+            $customMessages .= '<br /><br />SQL-ERROR: ' . htmlspecialchars($this->getDatabaseConnection()->sql_error());
+            $result = true;
+        }
+
+        return $result;
+    }
+
+    /**
+     * Performs the database update.
+     *
+     * @param array &$dbQueries Queries done in this update
+     * @param mixed &$customMessages Custom messages
+     * @return bool Whether it worked (TRUE) or not (FALSE)
+     */
+    public function performUpdate(array &$dbQueries, &$customMessages)
+    {
+        $result = false;
+
+        // First perform all create, add and change queries
+        $updateStatements = $this->getUpdateStatements();
+        foreach ((array)$updateStatements['add'] as $string) {
+            $this->getDatabaseConnection()->admin_query($string);
+            $dbQueries[] = $string;
+            $result = ($result || $this->hasError($customMessages));
+        }
+        foreach ((array)$updateStatements['change'] as $string) {
+            $this->getDatabaseConnection()->admin_query($string);
+            $dbQueries[] = $string;
+            $result = ($result || $this->hasError($customMessages));
+        }
+        foreach ((array)$updateStatements['create_table'] as $string) {
+            $this->getDatabaseConnection()->admin_query($string);
+            $dbQueries[] = $string;
+            $result = ($result || $this->hasError($customMessages));
+        }
+
+        // Perform statis import anyway
+        $rawDefinitions = GeneralUtility::getUrl(ExtensionManagementUtility::extPath('extensionmanager') . 'ext_tables_static+adt.sql');
+        $statements = $this->getInstallToolSqlParser()->getStatementarray($rawDefinitions, 1);
+        foreach ($statements as $statement) {
+            if (trim($statement) !== '') {
+                $this->getDatabaseConnection()->admin_query($statement);
+                $dbQueries[] = $statement;
+                $result = ($result || $this->hasError($customMessages));
+            }
+        }
+
+        return !$result;
+    }
+}
index 96fbc2b..42fbd93 100644 (file)
@@ -15,6 +15,10 @@ $signalSlotDispatcher->connect(
     'addCategoryDatabaseSchemaToTablesDefinition'
 );
 
+// Do not delete this wizard. This makes sure new installations get the TER repository set in the database.
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][\TYPO3\CMS\Install\Updates\ExtensionManagerTables::class]
+    = \TYPO3\CMS\Install\Updates\ExtensionManagerTables::class;
 
-$TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update'][\TYPO3\CMS\Install\Updates\BackendUserStartModuleUpdateAboutModule::class]
+// Add update wizards below this line
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][\TYPO3\CMS\Install\Updates\BackendUserStartModuleUpdateAboutModule::class]
     = \TYPO3\CMS\Install\Updates\BackendUserStartModuleUpdateAboutModule::class;