TYPO3 CMS  TYPO3_6-2
FrontendContentAdapterService.php
Go to the documentation of this file.
1 <?php
3 
23 
29  static protected $availableMigrationFields = array(
30  'paths',
31  'titleTexts',
32  'captions',
33  'links',
34  'alternativeTexts'
35  );
36 
42  static protected $migrateFields = array(
43  'tt_content' => array(
44  'image' => array(
45  'paths' => 'image',
46  'titleTexts' => 'titleText',
47  'captions' => 'imagecaption',
48  'links' => 'image_link',
49  'alternativeTexts' => 'altText',
50  '__typeMatch' => array(
51  'typeField' => 'CType',
52  'types' => array('image', 'textpic'),
53  )
54  ),
55  'media' => array(
56  'paths' => 'media',
57  'captions' => 'imagecaption',
58  '__typeMatch' => array(
59  'typeField' => 'CType',
60  'types' => array('uploads'),
61  )
62  )
63  ),
64  'pages' => array(
65  'media' => array(
66  'paths' => 'media'
67  )
68  )
69  );
70 
83  static public function modifyDBRow(&$row, $table) {
84  if (isset($row['_MIGRATED']) && $row['_MIGRATED'] === TRUE) {
85  return;
86  }
87  if (array_key_exists($table, static::$migrateFields)) {
88  foreach (static::$migrateFields[$table] as $migrateFieldName => $oldFieldNames) {
89  if ($row !== NULL && isset($row[$migrateFieldName]) && self::fieldIsInType($migrateFieldName, $table, $row)) {
90  $files = self::getPageRepository()->getFileReferences($table, $migrateFieldName, $row);
91  $fileFieldContents = array(
92  'paths' => array(),
93  'titleTexts' => array(),
94  'captions' => array(),
95  'links' => array(),
96  'alternativeTexts' => array(),
97  $migrateFieldName . '_fileUids' => array(),
98  $migrateFieldName . '_fileReferenceUids' => array(),
99  );
100  $oldFieldNames[$migrateFieldName . '_fileUids'] = $migrateFieldName . '_fileUids';
101  $oldFieldNames[$migrateFieldName . '_fileReferenceUids'] = $migrateFieldName . '_fileReferenceUids';
102 
103  foreach ($files as $file) {
105  $fileProperties = $file->getProperties();
106  $fileFieldContents['paths'][] = '../../' . $file->getPublicUrl();
107  $fileFieldContents['titleTexts'][] = $fileProperties['title'];
108  $fileFieldContents['captions'][] = $fileProperties['description'];
109  $fileFieldContents['links'][] = $fileProperties['link'];
110  $fileFieldContents['alternativeTexts'][] = $fileProperties['alternative'];
111  $fileFieldContents[$migrateFieldName . '_fileUids'][] = $file->getOriginalFile()->getUid();
112  $fileFieldContents[$migrateFieldName . '_fileReferenceUids'][] = $file->getUid();
113  }
114  foreach ($oldFieldNames as $oldFieldType => $oldFieldName) {
115  if ($oldFieldType === '__typeMatch') {
116  continue;
117  }
118  if ($oldFieldType === 'paths' || substr($oldFieldType, -9) == '_fileUids' || substr($oldFieldType, -18) == '_fileReferenceUids') {
119  // For paths and uids, make comma separated list
120  $fieldContents = implode(',', $fileFieldContents[$oldFieldType]);
121  } else {
122  // For all other fields, separate by LF
123 
124  $value = $fileFieldContents[$oldFieldType];
125 
126  // Field content first has to be stripped of any LFs, else the concatenation
127  // will result in wrong indices upon splitting for FE rendering due to
128  // splitting on LF.
129  // LF can usually be replaced by CR to maintain formatting on browsers where
130  // possible.
131  $value = str_replace(CRLF, CR, $value);
132  $value = str_replace(LF, CR, $value);
133 
134  $fieldContents = implode(LF, $value);
135  }
136  $row[$oldFieldName] = $fieldContents;
137  }
138  }
139  }
140  }
141  $row['_MIGRATED'] = TRUE;
142  }
143 
155  static public function registerAdditionalTypeForMigration($table, $field, $additionalType) {
156 
157  if (!isset(static::$migrateFields[$table][$field]['__typeMatch'])) {
158  throw new \RuntimeException('Additional types can only be added when there is already an existing type match configuration for the given table and field.', 1377600978);
159  }
160 
161  self::$migrateFields[$table][$field]['__typeMatch']['types'][] = $additionalType;
162  }
163 
177  static public function registerFieldForMigration($table, $field, $migrationField, $oldFieldName, $typeField = NULL, array $types = array()) {
178 
179  if (array_search($migrationField, static::$availableMigrationFields) === FALSE) {
180  throw new \InvalidArgumentException('The value for $migrationField is invalid. Valid values can be found in the $availableMigrationFields array.', 1377600978);
181  }
182 
183  self::$migrateFields[$table][$field][$migrationField] = $oldFieldName;
184 
185  if (isset($typeField) && (count($types) > 0)) {
186  self::$migrateFields[$table][$field]['__typeMatch']['types'] = $types;
187  self::$migrateFields[$table][$field]['__typeMatch']['typeField'] = (string)$typeField;
188  }
189  }
190 
199  static protected function fieldIsInType($fieldName, $table, array $row) {
200  $fieldConfiguration = static::$migrateFields[$table][$fieldName];
201  if (empty($fieldConfiguration['__typeMatch'])) {
202  return TRUE;
203  } else {
204  return in_array($row[$fieldConfiguration['__typeMatch']['typeField']], $fieldConfiguration['__typeMatch']['types']);
205  }
206  }
207 
211  static protected function getPageRepository() {
212  return $GLOBALS['TSFE']->sys_page;
213  }
214 
215 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static registerFieldForMigration($table, $field, $migrationField, $oldFieldName, $typeField=NULL, array $types=array())