38 protected $title =
'Migrate all file relations from tt_content.image and pages.media';
60 'tt_content' => array(
62 'sourcePath' =>
'uploads/pics/',
64 'targetPath' =>
'_migrated/pics/',
65 'titleTexts' =>
'titleText',
66 'captions' =>
'imagecaption',
67 'links' =>
'image_link',
68 'alternativeTexts' =>
'altText' 73 'sourcePath' =>
'uploads/media/',
75 'targetPath' =>
'_migrated/media/' 78 'pages_language_overlay' => array(
80 'sourcePath' =>
'uploads/media/',
82 'targetPath' =>
'_migrated/media/' 105 public function __construct() {
108 $this->logger = $logManager->getLogger(__CLASS__);
109 $this->database =
$GLOBALS[
'TYPO3_DB'];
115 public function init() {
118 $storages = $storageRepository->findAll();
119 $this->storage = $storages[0];
121 $this->recordOffset = $this->registry->get($this->registryNamespace,
'recordOffset', array());
131 $description =
'This update wizard goes through all files that are referenced in the tt_content.image and ' 132 .
'pages.media / pages_language_overlay.media field and adds the files to the new File Index.<br />' 133 .
'It also moves the files from uploads/ to the fileadmin/_migrated/ path.<br /><br />' 134 .
'This update wizard can be called multiple times in case it didn\'t finish after running once.';
136 if ($this->versionNumber < 6000000) {
142 if (count($finishedFields) === 0) {
147 $numberOfFieldsToMigrate = 0;
148 foreach ($this->tables as $table => $tableConfiguration) {
150 foreach (array_keys($tableConfiguration) as $fieldToMigrate) {
151 $fieldKey = $table .
':' . $fieldToMigrate;
152 if (!in_array($fieldKey, $finishedFields)) {
153 $numberOfFieldsToMigrate++;
157 return $numberOfFieldsToMigrate > 0;
168 if ($this->versionNumber < 6000000) {
175 foreach ($this->tables as $table => $tableConfiguration) {
177 foreach ($tableConfiguration as $fieldToMigrate => $fieldConfiguration) {
178 $fieldKey = $table .
':' . $fieldToMigrate;
179 if (in_array($fieldKey, $finishedFields)) {
183 $fieldsToGet = array($fieldToMigrate);
184 if (isset($fieldConfiguration[
'titleTexts'])) {
185 $fieldsToGet[] = $fieldConfiguration[
'titleTexts'];
187 if (isset($fieldConfiguration[
'alternativeTexts'])) {
188 $fieldsToGet[] = $fieldConfiguration[
'alternativeTexts'];
190 if (isset($fieldConfiguration[
'captions'])) {
191 $fieldsToGet[] = $fieldConfiguration[
'captions'];
193 if (isset($fieldConfiguration[
'links'])) {
194 $fieldsToGet[] = $fieldConfiguration[
'links'];
197 if (!isset($this->recordOffset[$table])) {
198 $this->recordOffset[$table] = 0;
202 $limit = $this->recordOffset[$table] .
',' . self::RECORDS_PER_QUERY;
204 foreach ($records as $record) {
205 $this->migrateField($table, $record, $fieldToMigrate, $fieldConfiguration, $customMessages);
207 $this->registry->set($this->registryNamespace,
'recordOffset', $this->recordOffset);
208 }
while (count($records) === self::RECORDS_PER_QUERY);
211 if (is_array($records)) {
212 $finishedFields[] = $fieldKey;
217 $this->registry->remove($this->registryNamespace,
'recordOffset');
219 $customMessages .= PHP_EOL . $e->getMessage();
221 return empty($customMessages);
231 $className =
'TYPO3\\CMS\\Install\\Updates\\TceformsUpdateWizard';
232 return isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'INSTALL'][
'wizardDone'][$className])
233 ? explode(
',',
$GLOBALS[
'TYPO3_CONF_VARS'][
'INSTALL'][
'wizardDone'][$className])
249 $fields = implode(
',', array_merge($relationFields, array(
'uid',
'pid')));
250 $deletedCheck = isset(
$GLOBALS[
'TCA'][$table][
'ctrl'][
'delete'])
251 ?
' AND ' .
$GLOBALS[
'TCA'][$table][
'ctrl'][
'delete'] .
'=0' 253 $where = $fieldToMigrate .
' IS NOT NULL' 254 .
' AND ' . $fieldToMigrate .
' != \'\'' 255 .
' AND CAST(CAST(' . $fieldToMigrate .
' AS DECIMAL) AS CHAR) <> CAST(' . $fieldToMigrate .
' AS CHAR)' 257 $result = $this->database->exec_SELECTgetRows($fields, $table, $where,
'',
'uid', $limit);
259 throw new \RuntimeException(
'Database query failed. Error was: ' . $this->database->sql_error());
275 protected function migrateField($table, $row, $fieldname, $fieldConfiguration, &$customMessages) {
276 $titleTextContents = array();
277 $alternativeTextContents = array();
278 $captionContents = array();
279 $linkContents = array();
282 if (empty($fieldItems) || is_numeric($row[$fieldname])) {
285 if (isset($fieldConfiguration[
'titleTexts'])) {
286 $titleTextField = $fieldConfiguration[
'titleTexts'];
287 $titleTextContents = explode(LF, $row[$titleTextField]);
290 if (isset($fieldConfiguration[
'alternativeTexts'])) {
291 $alternativeTextField = $fieldConfiguration[
'alternativeTexts'];
292 $alternativeTextContents = explode(LF, $row[$alternativeTextField]);
294 if (isset($fieldConfiguration[
'captions'])) {
295 $captionField = $fieldConfiguration[
'captions'];
296 $captionContents = explode(LF, $row[$captionField]);
298 if (isset($fieldConfiguration[
'links'])) {
299 $linkField = $fieldConfiguration[
'links'];
300 $linkContents = explode(LF, $row[$linkField]);
302 $fileadminDirectory = rtrim(
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'fileadminDir'],
'/') .
'/';
307 throw new \Exception(
'PATH_site was undefined.');
310 $storageUid = (int)$this->storage->getUid();
312 foreach ($fieldItems as $item) {
314 $sourcePath = PATH_site . $fieldConfiguration[
'sourcePath'] . $item;
315 $targetDirectory = PATH_site . $fileadminDirectory . $fieldConfiguration[
'targetPath'];
316 $targetPath = $targetDirectory . basename($item);
319 if (file_exists($sourcePath)) {
320 if (!is_dir($targetDirectory)) {
325 $fileSha1 = sha1_file($sourcePath);
327 $existingFileRecord = $this->database->exec_SELECTgetSingleRow(
330 'sha1=' . $this->database->fullQuoteStr($fileSha1,
'sys_file') .
' AND storage=' . $storageUid
333 if (is_array($existingFileRecord)) {
334 $fileUid = $existingFileRecord[
'uid'];
337 rename($sourcePath, $targetPath);
341 if ($fileUid === NULL) {
347 $file = $this->storage->getFile($fieldConfiguration[
'targetPath'] . $item);
348 $fileUid = $file->getUid();
350 }
catch (\InvalidArgumentException $e) {
353 $this->logger->notice(
354 'File ' . $fieldConfiguration[
'sourcePath'] . $item .
' does not exist. Reference was not migrated.',
355 array(
'table' => $table,
'record' => $row,
'field' => $fieldname)
358 $format =
'File \'%s\' does not exist. Referencing field: %s.%d.%s. The reference was not migrated.';
359 $message = sprintf($format, $fieldConfiguration[
'sourcePath'] . $item, $table, $row[
'uid'], $fieldname);
360 $customMessages .= PHP_EOL . $message;
369 'fieldname' => $fieldname,
370 'table_local' =>
'sys_file',
373 'pid' => ($table ===
'pages' ? $row[
'uid'] : $row[
'pid']),
374 'uid_foreign' => $row[
'uid'],
375 'uid_local' => $fileUid,
376 'tablenames' => $table,
379 'sorting' => ($i + 256),
380 'sorting_foreign' => $i,
382 if (isset($titleTextField)) {
383 $fields[
'title'] = trim($titleTextContents[$i]);
385 if (isset($alternativeTextField)) {
386 $fields[
'alternative'] = trim($alternativeTextContents[$i]);
388 if (isset($captionField)) {
389 $fields[
'description'] = trim($captionContents[$i]);
391 if (isset($linkField)) {
392 $fields[
'link'] = trim($linkContents[$i]);
394 $this->database->exec_INSERTquery(
'sys_file_reference', $fields);
395 $queries[] = str_replace(LF,
' ', $this->database->debug_lastBuiltQuery);
402 if ($i === count($fieldItems)) {
403 $this->database->exec_UPDATEquery($table,
'uid=' . $row[
'uid'], array($fieldname => $i));
404 $queries[] = str_replace(LF,
' ', $this->database->debug_lastBuiltQuery);
406 $this->recordOffset[$table]++;
static mkdir_deep($directory, $deepDirectory='')
static makeInstance($className)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren't numeric.
markWizardAsDone($confValue=1)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]