30 protected $title =
'Migrate file relations of tt_content "uploads"';
57 protected function init() {
58 $fileadminDirectory = rtrim(
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'fileadminDir'],
'/') .
'/';
61 $storages = $storageRepository->findAll();
63 $storageRecord = $storage->getStorageRecord();
64 $configuration = $storage->getConfiguration();
65 $isLocalDriver = $storageRecord[
'driver'] ===
'Local';
67 if ($isLocalDriver && $isOnFileadmin) {
72 if (!isset($this->storage)) {
73 throw new \RuntimeException(
'Local default storage could not be initialized - might be due to missing sys_file* tables.');
77 $this->targetDirectory = PATH_site . $fileadminDirectory . self::FOLDER_ContentUploads .
'/';
87 $updateNeeded = FALSE;
93 'COUNT(' . $mapping[
'mapFieldNames'][
'uid'] .
')',
94 $mapping[
'mapTableName'],
98 $sql = str_replace(
'WHERE 1=1', $whereClause,
$sql);
100 $notMigratedRowsCount = 0;
101 if ($resultSet !== FALSE) {
102 list($notMigratedRowsCount) =
$GLOBALS[
'TYPO3_DB']->sql_fetch_row($resultSet);
103 $notMigratedRowsCount = (int)$notMigratedRowsCount;
104 $GLOBALS[
'TYPO3_DB']->sql_free_result($resultSet);
106 if ($notMigratedRowsCount > 0) {
107 $description =
'There are Content Elements of type "upload" which are referencing files that are not using ' .
' the File Abstraction Layer. This wizard will move the files to fileadmin/' . self::FOLDER_ContentUploads .
' and index them.';
108 $updateNeeded = TRUE;
110 return $updateNeeded;
124 foreach ($records as $singleRecord) {
136 if (!$this->storage->hasFolder(self::FOLDER_ContentUploads)) {
137 $this->storage->createFolder(self::FOLDER_ContentUploads, $this->storage->getRootLevelFolder());
148 $collections = array();
149 if (trim($record[
'select_key'])) {
150 $GLOBALS[
'TYPO3_DB']->exec_INSERTquery(
'sys_file_collection', array(
151 'pid' => $record[
'pid'],
152 'title' => $record[
'select_key'],
153 'storage' => $this->storage->getUid(),
154 'folder' => ltrim(
'fileadmin/', $record[
'select_key'])
156 $collections[] =
$GLOBALS[
'TYPO3_DB']->sql_insert_id();
160 ', $record[
'imagecaption']);
162 ', $record[
'titleText']);
164 foreach ($files as $file) {
165 if (file_exists(PATH_site .
'uploads/media/' . $file)) {
167 $fileObject = $this->storage->getFile(self::FOLDER_ContentUploads .
'/' . $file);
168 $this->fileIndexRepository->add($fileObject);
170 'uid_local' => $fileObject->getUid(),
171 'tablenames' =>
'tt_content',
172 'uid_foreign' => $record[
'uid'],
175 'pid' => $record[
'pid'],
176 'fieldname' =>
'media',
177 'sorting_foreign' => $i
179 if (isset($descriptions[$i])) {
180 $dataArray[
'description'] = $descriptions[$i];
182 if (isset($titleText[$i])) {
183 $dataArray[
'alternative'] = $titleText[$i];
185 $GLOBALS[
'TYPO3_DB']->exec_INSERTquery(
'sys_file_reference', $dataArray);
186 unlink(PATH_site .
'uploads/media/' . $file);
201 protected function cleanRecord(array $record, $fileCount, array $collectionUids) {
202 $GLOBALS[
'TYPO3_DB']->exec_UPDATEquery(
'tt_content',
'uid = ' . $record[
'uid'], array(
203 'media' => $fileCount,
204 'imagecaption' =>
'',
208 'file_collections' => implode(
',', $collectionUids)
219 $reverseFieldMapping = array_flip($mapping[
'mapFieldNames']);
222 foreach (array(
'uid',
'pid',
'select_key',
'media',
'imagecaption',
'titleText') as $columnName) {
223 $fields[] = $mapping[
'mapFieldNames'][$columnName];
225 $fields = implode(
',', $fields);
229 $mapping[
'mapTableName'],
233 $sql = str_replace(
'WHERE 1=1', $whereClause,
$sql);
236 if (!
$GLOBALS[
'TYPO3_DB']->sql_error()) {
237 while (($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($resultSet)) !== FALSE) {
240 foreach ($reverseFieldMapping as $columnName => $finalColumnName) {
241 $record[$finalColumnName] = $row[$columnName];
243 $records[] = $record;
245 $GLOBALS[
'TYPO3_DB']->sql_free_result($resultSet);
263 'WHERE %s <> \'\' AND CAST(CAST(%s AS DECIMAL) AS CHAR) <> CAST(%s AS CHAR) OR (%s = \'uploads\' AND %s != \'\')',
264 $mapping[
'mapFieldNames'][
'media'],
265 $mapping[
'mapFieldNames'][
'media'],
266 $mapping[
'mapFieldNames'][
'media'],
267 $mapping[
'mapFieldNames'][
'CType'],
268 $mapping[
'mapFieldNames'][
'select_key']
281 'mapTableName' =>
'tt_content',
282 'mapFieldNames' => array(
286 'imagecaption' =>
'imagecaption',
287 'titleText' =>
'titleText',
289 'select_key' =>
'select_key',
294 if (!empty(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'dbal'][
'mapping'][
'tt_content'])) {
295 $mapping = array_merge_recursive($mapping,
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'dbal'][
'mapping'][
'tt_content']);
310 if (!
$GLOBALS[
'TYPO3_DB']->runningNative() && !
$GLOBALS[
'TYPO3_DB']->runningADOdbDriver(
'mysql')) {
311 $mapping[
'mapTableName'] =
'"' . $mapping[
'mapTableName'] .
'"';
312 foreach ($mapping[
'mapFieldNames'] as $key => &$value) {
313 $value =
'"' . $value .
'"';
performUpdate(array &$dbQueries, &$customMessages)
quoteIdentifiers(array &$mapping)
static isFirstPartOfStr($str, $partStr)
static makeInstance($className)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
cleanRecord(array $record, $fileCount, array $collectionUids)
migrateRecord(array $record)
getDbalCompliantUpdateWhereClause()
checkForUpdate(&$description)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
const FOLDER_ContentUploads
static upload_copy_move($source, $destination)