[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / MediaFlexformUpdate.php
1 <?php
2 namespace TYPO3\CMS\Install\Updates;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Migrates the old media FlexForm to the new
19 */
20 class MediaFlexformUpdate extends AbstractUpdate {
21
22 /**
23 * @var string
24 */
25 protected $title = 'FlexForm Data from Media Element';
26
27 /**
28 * Checks whether updates need to be performed
29 *
30 * @param string &$description The description for the update
31 * @param integer &$showUpdate 0=dont show update; 1=show update and next button; 2=only show description
32 * @return boolean
33 */
34 public function checkForUpdate(&$description, &$showUpdate = 0) {
35 $mediaElements = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'], 'CType = "media" AND pi_flexform LIKE "%<sheet index=\\"sDEF\\">%"');
36 if ($mediaElements > 0) {
37 $description = 'You have media elements within your installation. As the structure of the flexform changed, your data needs to be migrated.';
38 $showUpdate = 1;
39 } else {
40 $description = 'You currently have no media elements within your installation. Therefore nothing to be migrated';
41 $showUpdate = 0;
42 }
43 return $showUpdate > 0;
44 }
45
46 /**
47 * Perform update
48 *
49 * @param array &$dbQueries Queries done in this update
50 * @param mixed &$customMessages Custom messages
51 * @return boolean Whether the updated was made or not
52 */
53 public function performUpdate(array &$dbQueries, &$customMessages) {
54 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
55 'uid,pi_flexform',
56 $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'],
57 'CType = "media" AND pi_flexform LIKE "%<sheet index=\\"sDEF\\">%"'
58 );
59 /** @var $flexformTools \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools */
60 $flexformTools = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\FlexForm\\FlexFormTools');
61 foreach ($rows as $row) {
62 $flexFormXML = $row['pi_flexform'];
63 $data = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($flexFormXML);
64 $sDEF = $data['data']['sDEF']['lDEF'];
65 unset($data['data']['sDEF']);
66 $type = $sDEF['mmType']['vDEF'];
67 $data['data']['sGeneral'] = array(
68 'lDEF' => array(
69 'mmType' => array('vDEF' => $type)
70 )
71 );
72 $width = $sDEF['mmWidth']['vDEF'];
73 if ($width) {
74 $data['data']['sGeneral']['lDEF']['mmWidth'] = array('vDEF' => (int)$width);
75 }
76 $height = $sDEF['mmHeight']['vDEF'];
77 if ($height) {
78 $data['data']['sGeneral']['lDEF']['mmHeight'] = array('vDEF' => (int)$height);
79 }
80 switch ($type) {
81 case 'video':
82 $data['data']['sVideo'] = array('lDEF' => array('mmFile' => array('vDEF' => $sDEF['mmFile']['vDEF'])));
83 break;
84 case 'audio':
85 $data['data']['sAudio'] = array('lDEF' => array('mmAudioFallback' => array('vDEF' => $sDEF['mmFile']['vDEF'])));
86 break;
87 default:
88 continue;
89 }
90 $newXML = $flexformTools->flexArray2Xml($data, TRUE);
91 $newXML = str_replace('encoding=""', 'encoding="utf-8"', $newXML);
92 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
93 $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'],
94 'uid = ' . $row['uid'],
95 array('pi_flexform' => $newXML)
96 );
97 }
98 return TRUE;
99 }
100
101 }