[FEATURE] Automatically run the extension update script after install 12/43712/2
authorStanislas Rolland <typo3@sjbr.ca>
Thu, 1 Oct 2015 18:15:51 +0000 (14:15 -0400)
committerStanislas Rolland <typo3@sjbr.ca>
Thu, 1 Oct 2015 18:17:41 +0000 (20:17 +0200)
After install, always run the update script of base extension and
of language pack except on first install of base extension.

Resolves: #59834
Change-Id: I217c92aae4a353d0a97e4bea70bf41d22b9b217a
Reviewed-on: http://review.typo3.org/43712
Reviewed-by: Stanislas Rolland <typo3@sjbr.ca>
Tested-by: Stanislas Rolland <typo3@sjbr.ca>
ChangeLog
Classes/Slot/Extensionmanager/AfterExtensionInstall.php [new file with mode: 0644]
Resources/Private/LanguagePackTemplate/ext_conf_template.txt [deleted file]
ext_conf_template.txt
ext_localconf.php

index 796ac10..1fed9e4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2015-10-01  Stanislas Rolland  <typo3@sjbr.ca>
+
+       * Resolves #59834: Always run the extension update script except on first install of base extension
+
 2015-09-30  Stanislas Rolland  <typo3@sjbr.ca>
 
        * Resolves #70224: Import SQL parser for Dbal-free parsing with TYPO3 CMS 7.5+
diff --git a/Classes/Slot/Extensionmanager/AfterExtensionInstall.php b/Classes/Slot/Extensionmanager/AfterExtensionInstall.php
new file mode 100644 (file)
index 0000000..ec5119b
--- /dev/null
@@ -0,0 +1,85 @@
+<?php
+namespace SJBR\StaticInfoTables\Slot\Extensionmanager;
+ /***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2015 StanislasRolland <typo3(arobas)sjbr.ca>
+ *  All rights reserved
+ *
+ *  This script is part of the Typo3 project. The Typo3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+
+/**
+ * AfterExtensionInstall slot
+ *
+ * Always run the extension update script except on first install of base extension
+ */
+class AfterExtensionInstall {
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Object\ObjectManager
+        */
+       public $objectManager;
+
+       /**
+        * @var \TYPO3\CMS\Core\Registry
+        */
+       protected $registry;
+
+       /**
+        * @param \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager
+        */
+       public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager) {
+               $this->objectManager = $objectManager;
+       }
+
+       /**
+        * @param \TYPO3\CMS\Core\Registry $registry
+        */
+       public function injectRegistry(\TYPO3\CMS\Core\Registry $registry) {
+               $this->registry = $registry;
+       }
+
+       /**
+        * If the installed extension is static_info_tables or a language pack, execute the update script
+        *
+        * @param string $extensionKey: the key of the extension that was installed
+        * @param \TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility
+        * @return void
+        */
+       public function executeUpdateScript($extensionKey, \TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility) {
+               if (strpos($extensionKey, 'static_info_tables') === 0) {
+                       $extensionKeyParts = explode('_', $extensionKey);
+                       if (count($extensionKeyParts) === 3) {
+                               $extTablesStaticSqlRelFile = substr(ExtensionManagementUtility::extRelPath($extensionKey), 3) . 'ext_tables_static+adt.sql';
+                       }
+                       if (
+                               // Base extension with data already imported once
+                               (count($extensionKeyParts) === 3 && $this->registry->get('extensionDataImport', $extTablesStaticSqlRelFile))
+                               // Language pack
+                               || (count($extensionKeyParts) === 4 && strlen($extensionKeyParts[3]) === 2)
+                               || (count($extensionKeyParts) === 5 && strlen($extensionKeyParts[3]) === 2 && strlen($extensionKeyParts[4]) === 2)
+                       ) {
+                               /** @var $updateScriptUtility \TYPO3\CMS\Extensionmanager\Utility\UpdateScriptUtility */
+                               $updateScriptUtility = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\UpdateScriptUtility');
+                               $updateScriptResult = $updateScriptUtility->executeUpdateIfNeeded($extensionKey);
+                       }
+               }
+       }
+}
\ No newline at end of file
diff --git a/Resources/Private/LanguagePackTemplate/ext_conf_template.txt b/Resources/Private/LanguagePackTemplate/ext_conf_template.txt
deleted file mode 100644 (file)
index 4cf3bf4..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-
-  # cat=basic//10; type=boolean; label= ATTENTION: After installing or upgrading this extension, you should execute the update script.
-dummy = 0
index a349109..3bab9b1 100644 (file)
@@ -1,6 +1,3 @@
 
   # cat=enable; type=boolean; label=LLL:EXT:static_info_tables/Resources/Private/Language/locallang.xlf:enableStaticInfoTablesManager
-enableManager = 0
-
-  # cat=enable; type=boolean; label=LLL:EXT:static_info_tables/Resources/Private/Language/locallang.xlf:afterInstall
-dummy = 0
+enableManager = 0
\ No newline at end of file
index 6ccd38b..01c0324 100644 (file)
@@ -105,6 +105,10 @@ if (\TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(
 // Add data handling hook to manage ISO codes redundancies on records
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'SJBR\\StaticInfoTables\\Hook\\Core\\DataHandling\\ProcessDataMap';
 
+// Register slot for AfterExtensionInstall signal
+$dispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
+$dispatcher->connect('TYPO3\\CMS\\Extensionmanager\Utility\\InstallUtility', 'afterExtensionInstall', 'SJBR\\StaticInfoTables\\Slot\\Extensionmanager\\AfterExtensionInstall', 'executeUpdateScript');
+
 // Enabling the Static Info Tables Manager module
 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$_EXTKEY]['enableManager'] = isset($_EXTCONF['enableManager']) ? $_EXTCONF['enableManager'] : '0';