[TASK] Add update-wizard for Media Flexform
authorSteffen Ritter <info@rs-websystems.de>
Wed, 11 Apr 2012 21:46:40 +0000 (23:46 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 30 Jun 2012 14:22:08 +0000 (16:22 +0200)
While adding the new media stuff the flexform has been altered.
Therefore a update wizard needs to be provided to not lose the
old media elements.

Change-Id: I60943b2f9eee84d768bce8b5a5f38b6f83c027f3
Resolves: #35879
Releases: 6.0, 4.7
Reviewed-on: http://review.typo3.org/10308
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/install/ext_localconf.php
typo3/sysext/install/mod/class.tx_install.php
typo3/sysext/install/updates/class.tx_coreupdates_mediaflexform.php [new file with mode: 0644]

index c665c95..03f8b01 100644 (file)
@@ -58,4 +58,6 @@ $TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['sysext_file_images'] =
 $TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['sysext_file_uploads'] = 'Tx_Install_Updates_File_TtContentUploadsUpdateWizard';
 $TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['sysext_file_filemounts'] = 'Tx_Install_Updates_File_FilemountUpdateWizard';
 
+       // Version 4.7: Migrate the flexforms of MediaElement
+$TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['mediaElementFlexform'] = 'tx_coreupdates_mediaFlexform';
 ?>
\ No newline at end of file
index 238c9cd..23b95b2 100644 (file)
@@ -53,6 +53,7 @@ require_once(t3lib_extMgm::extPath('install') . 'updates/class.tx_coreupdates_mi
 require_once(t3lib_extMgm::extPath('install') . 'updates/class.tx_coreupdates_flagsfromsprite.php');
 require_once(t3lib_extMgm::extPath('install') . 'updates/class.tx_coreupdates_addflexformstoacl.php');
 require_once(t3lib_extMgm::extPath('install') . 'updates/class.tx_coreupdates_imagelink.php');
+require_once(t3lib_extMgm::extPath('install') . 'updates/class.tx_coreupdates_mediaflexform.php');
 
 /**
  * Install Tool module
@@ -8472,4 +8473,4 @@ $out="
                }
        }
 }
-?>
+?>
\ No newline at end of file
diff --git a/typo3/sysext/install/updates/class.tx_coreupdates_mediaflexform.php b/typo3/sysext/install/updates/class.tx_coreupdates_mediaflexform.php
new file mode 100644 (file)
index 0000000..affc17e
--- /dev/null
@@ -0,0 +1,105 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Steffen Ritter <steffen.ritter@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!
+***************************************************************/
+
+/**
+ * Migrates the old media FlexForm to the new
+ */
+class tx_coreupdates_mediaFlexform extends Tx_Install_Updates_Base {
+       protected $title = 'FlexForm Data from Media Element';
+
+       /**
+        * Checks wether updates need to be performed
+        *
+        * @param string &$description The description for the update
+        * @param integer &$showUpdate 0=dont show update; 1=show update and next button; 2=only show description
+        * @return boolean
+        */
+       public function checkForUpdate(&$description, &$showUpdate = 0) {
+               $mediaElements = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'], 'CType = "media" AND pi_flexform LIKE "%<sheet index=\"sDEF\">%"');
+               if ($mediaElements > 0) {
+                       $description = "You have media elements within your installation. As the structure of the flexform changed, your data needs to be migrated.";
+                       $showUpdate = 1;
+               } else {
+                       $description = "You currently have no media elements within your installation. Therefore nothing to be migrated";
+                       $showUpdate = 0;
+               }
+               return $showUpdate > 0;
+       }
+
+
+       /**
+        *
+        *
+        * @param       array           &$dbQueries: queries done in this update
+        * @param       mixed           &$customMessages: custom messages
+        * @return      boolean         whether the updated was made or not
+        */
+       public function performUpdate(array &$dbQueries, &$customMessages) {
+               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,pi_flexform', $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'], 'CType = "media" AND pi_flexform LIKE "%<sheet index=\"sDEF\">%"');
+               /** @var $flexformTools t3lib_flexformtools */
+               $flexformTools = t3lib_div::makeInstance('t3lib_flexformtools');
+               foreach ($rows AS $row) {
+                       $flexFormXML = $row['pi_flexform'];
+                       $data = t3lib_div::xml2array($flexFormXML);
+                       $sDEF = $data['data']['sDEF']['lDEF'];
+                       unset($data['data']['sDEF']);
+                       $type = $sDEF['mmType']['vDEF'];
+
+                       $data['data']['sGeneral'] = array('lDEF' => array(
+                               'mmType'=> array('vDEF' => $type)
+                       ));
+
+                       $width = $sDEF['mmWidth']['vDEF'];
+                       if ($width) {
+                               $data['data']['sGeneral']['lDEF']['mmWidth'] = array('vDEF' => intval($width));
+                       }
+
+                       $height = $sDEF['mmHeight']['vDEF'];
+                       if ($height) {
+                               $data['data']['sGeneral']['lDEF']['mmHeight'] = array('vDEF' => intval($height));
+                       }
+
+                       switch ($type) {
+                               case 'video':
+                                       $data['data']['sVideo'] = array('lDEF' => array('mmFile' => array('vDEF' => $sDEF['mmFile']['vDEF'])));
+                                       break;
+                               case 'audio':
+                                       $data['data']['sAudio'] = array('lDEF' => array('mmAudioFallback' => array('vDEF' => $sDEF['mmFile']['vDEF'])));
+                                       break;
+                               default:
+                                       continue;
+                       }
+                       $newXML = $flexformTools->flexArray2Xml($data, TRUE);
+                       $newXML = str_replace('encoding=""', 'encoding="utf-8"', $newXML);
+
+                       $GLOBALS['TYPO3_DB']->exec_UPDATEquery($GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'], 'uid = ' . $row['uid'], array('pi_flexform' => $newXML));
+               }
+               return TRUE;
+       }
+}
+
+?>
\ No newline at end of file