typoscript2contentelement

Upgrading TYPO3 to the new LTS-Version 6.2 means sometimes upgrading a lot of extensions too.
Would be really nice, if we could delegate a lot of work to dedicated update scripts.

Last time i had to upgrade the small but very handy extension typoscript2contentelement.
Unfortunately a minor but neccesary change in the flexforms settings was introduced.
According to the comment on http://typo3.org/extensions/repository/view/typoscript2ce you had to reenter the path to the object. Oh no. That would have meant, updating 100 Records manually? No, of course you could run a database statement on your own.
But there is a better way. Just run an update script from Extension Manager.

!!! Make a DB-Dump before running this script !!!

Place the following class.ext_udpate.php file in your extension directory of choice, run the update script and you should be down:

class ext_update {

 /**
 * Main update function called by the extension manager.
 *
 * @return string
 */
 public function main() {
 $this->renameFlexformField('typoscript2ce_pi1', array('main', 'tsobject'), array('main', 'settings.typoscriptobjectpath'));
 }

 /**
 * Renames a flex form field
 *
 * @param string $pluginName The pluginName used in list_type
 * @param array $oldFieldPointer Pointer array the old field. E.g. array('sheetName', 'fieldName');
 * @param array $newFieldPointer Pointer array the new field. E.g. array('sheetName', 'fieldName');
 * @return void
 */
 protected function renameFlexformField($pluginName, array $oldFieldPointer, array $newFieldPointer) {
 $title = 'Renaming flexform field for "' . $pluginName . '" - ' .
 ' sheet: ' . $oldFieldPointer[0] . ', field: ' . $oldFieldPointer[1] . ' to ' .
 ' sheet: ' . $newFieldPointer[0] . ', field: ' . $newFieldPointer[1];

 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid, pi_flexform', 'tt_content', 'CType=\'list\' AND list_type=\'' . $pluginName . '\'');

 $flexformTools = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('\TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools');
 /* @var $flexformTools \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools */
 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {

 $xmlArray = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($row['pi_flexform']);

 if (!is_array($xmlArray) || !isset($xmlArray['data'])) {
 // Something went wrong
 } elseif (!$xmlArray['data'][$oldFieldPointer[0]]) {
 // Something went wrong
 } else {
 $updated = FALSE;

 foreach ($xmlArray['data'][$oldFieldPointer[0]] as $language => $fields) {
 if ($fields[$oldFieldPointer[1]]) {

 $xmlArray['data'][$newFieldPointer[0]][$language][$newFieldPointer[1]] = $fields[$oldFieldPointer[1]];
 unset($xmlArray['data'][$oldFieldPointer[0]][$language][$oldFieldPointer[1]]);

 $updated = TRUE;
 }
 }

 if ($updated === TRUE) {

 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tt_content', 'uid=' . $row['uid'], array(
 'pi_flexform' => $flexformTools->flexArray2Xml($xmlArray)
 ));
 }
 }
 }
 }
}

Veröffentlicht von

avatar

Sebastian Schreiber

Ich bin 1980 in Bergisch Gladbach geboren. Nach dem Abitur und Zivildienst habe ich 2000 an der Fachhochschule Lippe & Höxter das Studium der Medienproduktin begonnen und nach längeren Aufenthalten in Valencia und Berlin 2003 das Studium mit dem Abschluss Bachelor of Science in Medienproduktion abgeschlossen. Nach einer Festanstellung kurz nach dem Studium in einer kleinen Webagentur in Köln mit Schwerpunkt TYPO3 bin ich nun seit 2008 freiberuflicher Webentwickler.