TYPO3 CMS  TYPO3_6-2
MediaFlexformUpdate.php
Go to the documentation of this file.
1 <?php
3 
21 
25  protected $title = 'FlexForm Data from Media Element';
26 
30  protected $db;
31 
35  public function __construct() {
36  $this->db = $GLOBALS['TYPO3_DB'];
37  }
38 
46  public function checkForUpdate(&$description, &$showUpdate = 0) {
47  $mediaElements = $this->db->exec_SELECTcountRows('*', $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'], 'CType = ' . $this->db->fullQuoteStr('media', $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']) . ' AND pi_flexform LIKE ' . $this->db->fullQuoteStr('%<sheet index="sDEF">%', $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']));
48  if ($mediaElements > 0) {
49  $description = 'You have media elements within your installation. As the structure of the flexform changed, your data needs to be migrated.';
50  $showUpdate = 1;
51  } else {
52  $description = 'You currently have no media elements within your installation. Therefore nothing to be migrated';
53  $showUpdate = 0;
54  }
55  return $showUpdate > 0;
56  }
57 
65  public function performUpdate(array &$dbQueries, &$customMessages) {
66  $rows = $this->db->exec_SELECTgetRows(
67  'uid,pi_flexform',
68  $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'],
69  'CType = ' . $this->db->fullQuoteStr('media', $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']) . ' AND pi_flexform LIKE ' . $this->db->fullQuoteStr('%<sheet index="sDEF">%', $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'])
70  );
72  $flexformTools = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\FlexForm\\FlexFormTools');
73  foreach ($rows as $row) {
74  $flexFormXML = $row['pi_flexform'];
76  $sDEF = $data['data']['sDEF']['lDEF'];
77  unset($data['data']['sDEF']);
78  $type = $sDEF['mmType']['vDEF'];
79  $data['data']['sGeneral'] = array(
80  'lDEF' => array(
81  'mmType' => array('vDEF' => $type)
82  )
83  );
84  $width = $sDEF['mmWidth']['vDEF'];
85  if ($width) {
86  $data['data']['sGeneral']['lDEF']['mmWidth'] = array('vDEF' => (int)$width);
87  }
88  $height = $sDEF['mmHeight']['vDEF'];
89  if ($height) {
90  $data['data']['sGeneral']['lDEF']['mmHeight'] = array('vDEF' => (int)$height);
91  }
92  switch ($type) {
93  case 'video':
94  $data['data']['sVideo'] = array('lDEF' => array('mmFile' => array('vDEF' => $sDEF['mmFile']['vDEF'])));
95  break;
96  case 'audio':
97  $data['data']['sAudio'] = array('lDEF' => array('mmAudioFallback' => array('vDEF' => $sDEF['mmFile']['vDEF'])));
98  break;
99  default:
100  continue;
101  }
102  $newXML = $flexformTools->flexArray2Xml($data, TRUE);
103  $newXML = str_replace('encoding=""', 'encoding="utf-8"', $newXML);
104  $this->db->exec_UPDATEquery(
105  $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'],
106  'uid = ' . $row['uid'],
107  array('pi_flexform' => $newXML)
108  );
109  }
110  return TRUE;
111  }
112 
113 }
performUpdate(array &$dbQueries, &$customMessages)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static xml2array($string, $NSprefix='', $reportDocTag=FALSE)