[BUGFIX] Restore support for Update script 80/16780/8
authorFrancois Suter <francois@typo3.org>
Tue, 29 Jan 2013 19:31:52 +0000 (20:31 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 1 Feb 2013 22:34:41 +0000 (23:34 +0100)
The new EM is missing support for the class.ext_update.php script.
This patch restores it, giving it its own icon in the extension
list view.

Change-Id: Id5ea243bb689882959aa85cdbe700e784d83b2c0
Resolves: #43244
Releases: 6.1, 6.0
Reviewed-on: https://review.typo3.org/16780
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/extensionmanager/Classes/Controller/UpdateScriptController.php [new file with mode: 0644]
typo3/sysext/extensionmanager/Classes/Utility/UpdateScriptUtility.php [new file with mode: 0644]
typo3/sysext/extensionmanager/Classes/ViewHelpers/UpdateScriptViewHelper.php [new file with mode: 0644]
typo3/sysext/extensionmanager/Resources/Private/Language/locallang.xlf
typo3/sysext/extensionmanager/Resources/Private/Templates/List/Index.html
typo3/sysext/extensionmanager/Resources/Private/Templates/UpdateScript/Show.html [new file with mode: 0644]
typo3/sysext/extensionmanager/Resources/Public/Images/Icons/ExtensionUpdateScript.png [new file with mode: 0644]
typo3/sysext/extensionmanager/ext_tables.php
typo3/sysext/extensionmanager/info.txt

diff --git a/typo3/sysext/extensionmanager/Classes/Controller/UpdateScriptController.php b/typo3/sysext/extensionmanager/Classes/Controller/UpdateScriptController.php
new file mode 100644 (file)
index 0000000..df2af69
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+namespace TYPO3\CMS\Extensionmanager\Controller;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Francois Suter, <francois.suter@typo3.org>
+ *  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.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  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!
+ ***************************************************************/
+
+/**
+ * Controller for configuration related actions.
+ *
+ * @author Francois Suter <francois.suter@typo3.org>
+ */
+class UpdateScriptController extends \TYPO3\CMS\Extensionmanager\Controller\AbstractController {
+
+       /**
+        * Show the content of the update script (if any).
+        *
+        * @param string $extensionKey Extension key
+        * @return void
+        * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
+        */
+       public function showAction($extensionKey) {
+               \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Request for update script', 'extensionmanager', 0, $extensionKey);
+
+               /** @var $updateScriptUtility \TYPO3\CMS\Extensionmanager\Utility\UpdateScriptUtility */
+               $updateScriptUtility = $this->objectManager->create('TYPO3\\CMS\\Extensionmanager\\Utility\\UpdateScriptUtility');
+               $updateScriptResult = $updateScriptUtility->executeUpdateIfNeeded($extensionKey);
+               $this->view
+                       ->assign('updateScriptResult', $updateScriptResult)
+                       ->assign('extensionKey', $extensionKey);
+       }
+}
+
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extensionmanager/Classes/Utility/UpdateScriptUtility.php b/typo3/sysext/extensionmanager/Classes/Utility/UpdateScriptUtility.php
new file mode 100644 (file)
index 0000000..44e3dfd
--- /dev/null
@@ -0,0 +1,127 @@
+<?php
+namespace TYPO3\CMS\Extensionmanager\Utility;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
+ *  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.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  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!
+ ***************************************************************/
+
+/**
+ * Utility to find and execute class.ext_update.php scripts of extensions
+ *
+ * @author Christian Kuhn <lolli@schwarzbu.ch>
+ */
+class UpdateScriptUtility {
+
+       /**
+        * Returns true, if ext_update class says it wants to run.
+        *
+        * @param string $extensionKey extension key
+        * @return mixed NULL, if update is not availabel, else update script return
+        */
+       public function executeUpdateIfNeeded($extensionKey) {
+               $this->requireUpdateScript($extensionKey);
+               $scriptObject = new \ext_update;
+               // old em always assumed the method exist, we do so too.
+               // @TODO: Make this smart, let scripts implement interfaces
+               // @TODO: Enforce different update class script names per extension
+               // @TODO: With different class names it would be easily possible to check for updates in list view.
+               $accessReturnValue = $scriptObject->access();
+
+               $result = NULL;
+               if ($accessReturnValue === TRUE) {
+                       // @TODO: With current ext_update construct it is impossible
+                       // @TODO: to enforce some type of return
+                       $result = $scriptObject->main();
+               }
+
+               return $result;
+       }
+
+       /**
+        * Require update script.
+        * Throws exception if update script does not exist, so checkUpdateScriptExists()
+        * should be called before
+        *
+        * @param string $extensionKey
+        * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
+        */
+       protected function requireUpdateScript($extensionKey) {
+               if (class_exists('ext_update')) {
+                       throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(
+                               'class ext_update for this run does already exist, requiring impossible',
+                               1359748085
+                       );
+               }
+
+               $fileLocation = $this->getUpdateFileLocation($extensionKey);
+
+               if (!$this->checkUpdateScriptExists($extensionKey)) {
+                       throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(
+                               'Requested update script of extension does not exist',
+                               1359747976
+                       );
+
+               }
+               require $fileLocation;
+
+               if (!class_exists('ext_update')) {
+                       throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(
+                               'class.ext_update.php of extension did not declare ext_update class',
+                               1359748132
+                       );
+               }
+       }
+
+       /**
+        * Checks if an update class file exists.
+        * Does not check if some update is needed.
+        *
+        * @param string $extensionKey Extension key
+        * @return boolean True, if there is some update script
+        */
+       public function checkUpdateScriptExists($extensionKey) {
+               $updateScriptFileExists = FALSE;
+               if (file_exists($this->getUpdateFileLocation($extensionKey))) {
+                       $updateScriptFileExists = TRUE;
+               }
+               return $updateScriptFileExists;
+       }
+
+       /**
+        * Determines location of update file.
+        * Does not check if the file exists.
+        *
+        * @param string $extensionKey Extension key
+        * @return string Absolute path to possible update file of extension
+        */
+       protected function getUpdateFileLocation($extensionKey) {
+               return \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(
+                       'EXT:' . $extensionKey . '/class.ext_update.php',
+                       FALSE
+               );
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extensionmanager/Classes/ViewHelpers/UpdateScriptViewHelper.php b/typo3/sysext/extensionmanager/Classes/ViewHelpers/UpdateScriptViewHelper.php
new file mode 100644 (file)
index 0000000..1af0038
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+namespace TYPO3\CMS\Extensionmanager\ViewHelpers;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Francois Suter, <francois.suter@typo3.org>
+ *  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.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  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!
+ ***************************************************************/
+
+/**
+ * View helper for update script link
+ *
+ * @author Francois Suter <francois.suter@typo3.org>
+ */
+class UpdateScriptViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Link\ActionViewHelper {
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
+        * @inject
+        */
+       protected $objectManager;
+
+       /**
+        * @var string
+        */
+       protected $tagName = 'a';
+
+       /**
+        * Renders a link to the update script screen if the extension has one
+        *
+        * @param string $extensionKey Extension key
+        * @return string The rendered a tag
+        */
+       public function render($extensionKey) {
+               $tag = '';
+
+               // If the "class.ext_update.php" file exists, build link to the update script screen
+               /** @var $updateScriptUtility \TYPO3\CMS\Extensionmanager\Utility\UpdateScriptUtility */
+               $updateScriptUtility = $this->objectManager->create('TYPO3\\CMS\\Extensionmanager\\Utility\\UpdateScriptUtility');
+               if ($updateScriptUtility->checkUpdateScriptExists($extensionKey)) {
+                       $uriBuilder = $this->controllerContext->getUriBuilder();
+                       $action = 'show';
+                       $uri = $uriBuilder->reset()->uriFor(
+                               $action,
+                               array('extensionKey' => $extensionKey),
+                               'UpdateScript'
+                       );
+                       $this->tag->addAttribute('href', $uri);
+                       $this->tag->addAttribute('title', \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('extensionList.update.script', 'extensionmanager'));
+                       $this->tag->setContent(\TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('extensions-extensionmanager-update-script'));
+                       $tag = $this->tag->render();
+               }
+               return $tag;
+       }
+
+}
+
+
+?>
\ No newline at end of file
index df16c6b..5342ed5 100644 (file)
                        <trans-unit id="extConfTemplate.submitButton" xml:space="preserve">
                                <source>Submit</source>
                        </trans-unit>
+                       <trans-unit id="updateScript.headline" xml:space="preserve">
+                               <source>Update script for %s</source>
+                       </trans-unit>
+                       <trans-unit id="updateScript.none" xml:space="preserve">
+                               <source>No update necessary.</source>
+                       </trans-unit>
                        <trans-unit id="extensionList.configure" xml:space="preserve">
                                <source>Configure</source>
                        </trans-unit>
+                       <trans-unit id="extensionList.update.script" xml:space="preserve">
+                               <source>Execute the update script</source>
+                       </trans-unit>
                        <trans-unit id="extensionList.downloadsql" xml:space="preserve">
                                <source>Download SQL Dump</source>
                        </trans-unit>
index 576fa09..6e822a2 100644 (file)
@@ -67,6 +67,7 @@
                                </td>
                                <td>
                                        <em:configureExtension extension="{extension}" />
+                                       <em:updateScript extensionKey="{extension.key}" />
                                        <em:removeExtension extension="{extension}" />
                                        <f:be.buttons.icon uri="{f:uri.action(action:'downloadExtensionZip',controller:'Action',arguments:'{extension:extension.key}')}" icon="actions-system-extension-download" title="{f:translate(key:'extensionList.downloadzip')}"/>
                                        <em:downloadExtensionData extension="{extension}" />
diff --git a/typo3/sysext/extensionmanager/Resources/Private/Templates/UpdateScript/Show.html b/typo3/sysext/extensionmanager/Resources/Private/Templates/UpdateScript/Show.html
new file mode 100644 (file)
index 0000000..0a3ab7f
--- /dev/null
@@ -0,0 +1,28 @@
+{namespace em=TYPO3\CMS\Extensionmanager\ViewHelpers}
+
+<f:layout name="main" />
+
+<f:section name="docHeaderRow1">
+       <f:be.buttons.icon uri="{f:uri.action(action:'index',controller:'List',additionalParams:{search:extensionKey})}" icon="actions-view-go-back" title="{f:translate(key:'extConfTemplate.backToList')}" />
+</f:section>
+
+<f:section name="docHeaderRow2">
+</f:section>
+
+<f:section name="Content">
+       <div id="typo3-extension-configuration-forms">
+               <h2>
+                       <f:translate key="updateScript.headline" arguments="{0: extensionKey}" />
+               </h2>
+               <div class="update-script">
+                       <f:if condition="{updateScriptResult}">
+                               <f:then>
+                                       <f:format.raw>{updateScriptResult}</f:format.raw>
+                               </f:then>
+                               <f:else>
+                                       <f:translate key="updateScript.none" />
+                               </f:else>
+                       </f:if>
+               </div>
+       </div>
+</f:section>
diff --git a/typo3/sysext/extensionmanager/Resources/Public/Images/Icons/ExtensionUpdateScript.png b/typo3/sysext/extensionmanager/Resources/Public/Images/Icons/ExtensionUpdateScript.png
new file mode 100644 (file)
index 0000000..46c75aa
Binary files /dev/null and b/typo3/sysext/extensionmanager/Resources/Public/Images/Icons/ExtensionUpdateScript.png differ
index c7c97f9..878d920 100644 (file)
@@ -32,6 +32,7 @@ if (TYPO3_MODE === 'BE') {
                        'Action' => 'toggleExtensionInstallationState,removeExtension,downloadExtensionZip,downloadExtensionData',
                        'Configuration' => 'showConfigurationForm,save',
                        'Download' => 'checkDependencies,installFromTer,updateExtension,updateCommentForUpdatableVersions',
+                       'UpdateScript' => 'show',
                        'UpdateFromTer' => 'updateExtensionListFromTer',
                        'UploadExtensionFile' => 'form,extract'
                ),
@@ -45,5 +46,13 @@ if (TYPO3_MODE === 'BE') {
        // Register extension status report system
        $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers']['Extension Manager'][] =
                'TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus';
+
+       // Register specific icon for update script button
+       t3lib_SpriteManager::addSingleIcons(
+               array(
+                       'update-script' => t3lib_extMgm::extRelPath($_EXTKEY) . 'Resources/Public/Images/Icons/ExtensionUpdateScript.png'
+               ),
+               $_EXTKEY
+       );
 }
 ?>
\ No newline at end of file
index 6092d7a..ea5c6fa 100644 (file)
@@ -2,5 +2,4 @@
 - uploadFolder is currently not supported
 - conflicts dependency is not resolved
 - circular dependencies are not resolved
-- update script is missing
 - custom mirror / repository selection