TYPO3 CMS  TYPO3_7-6
MigrateMediaToAssetsForTextMediaCe.php
Go to the documentation of this file.
1 <?php
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 
21 {
25  protected $title = 'Migrate CTypes textmedia database field "media" to "assets"';
26 
33  public function checkForUpdate(&$description)
34  {
35  $updateNeeded = true;
36 
37  if ($this->isWizardDone()) {
38  $updateNeeded = false;
39  } else {
40  // No need to join the sys_file_references table here as we can rely on the reference
41  // counter to check if the wizards has any textmedia content elements to upgrade.
42  $textmediaCount = $this->getDatabaseConnection()->exec_SELECTcountRows(
43  'uid',
44  'tt_content',
45  'CType = \'textmedia\' AND media > 0'
46  );
47 
48  if ($textmediaCount === 0) {
49  $updateNeeded = false;
50  $this->markWizardAsDone();
51  }
52  }
53 
54  $description = 'The extension "fluid_styled_content" is using a new database field for mediafile references. ' .
55  'This update wizard migrates these old references to use the new database field.';
56 
57  return $updateNeeded;
58  }
59 
67  public function performUpdate(array &$databaseQueries, &$customMessages)
68  {
69  $databaseConnection = $this->getDatabaseConnection();
70 
71  // Update 'textmedia'
72  $query = '
73  UPDATE sys_file_reference
74  LEFT JOIN tt_content
75  ON sys_file_reference.uid_foreign = tt_content.uid
76  AND sys_file_reference.tablenames =\'tt_content\'
77  AND sys_file_reference.fieldname = \'media\'
78  SET tt_content.assets = tt_content.media,
79  tt_content.media = 0,
80  sys_file_reference.fieldname = \'assets\'
81  WHERE
82  tt_content.CType = \'textmedia\'
83  AND tt_content.media > 0
84  ';
85  $databaseConnection->sql_query($query);
86 
87  // Store last executed query
88  $databaseQueries[] = str_replace(chr(10), ' ', $query);
89  // Check for errors
90  if ($databaseConnection->sql_error()) {
91  $customMessages = 'SQL-ERROR: ' . htmlspecialchars($databaseConnection->sql_error());
92  return false;
93  }
94 
95  $this->markWizardAsDone();
96 
97  return true;
98  }
99 }