16 use Doctrine\DBAL\DBALException;
17 use Psr\Log\LoggerAwareInterface;
18 use Psr\Log\LoggerAwareTrait;
99 return 'frontendUserImageUpdateWizard';
107 return 'Migrate all file relations from fe_users.image to sys_file_references';
115 return 'This update wizard goes through all files that are referenced in the fe_users.image'
116 .
' field and adds the files to the FAL File Index. It also moves the files from'
117 .
' uploads/ to the fileadmin/_migrated/ path.';
127 $this->registry = GeneralUtility::makeInstance(Registry::class);
128 return $this->registry->get($this->registryNamespace,
'recordOffset') ===
null;
137 DatabaseUpdatedPrerequisite::class
150 if (!isset($this->recordOffset[$this->table])) {
156 foreach ($records as $record) {
159 $this->registry->set($this->registryNamespace,
'recordOffset', $this->recordOffset);
160 }
while (count($records) === self::RECORDS_PER_QUERY);
162 $this->registry->remove($this->registryNamespace,
'recordOffset');
172 protected function init()
174 $storages = GeneralUtility::makeInstance(StorageRepository::class)->findAll();
175 $this->storage = $storages[0];
176 $this->registry = GeneralUtility::makeInstance(Registry::class);
177 $this->recordOffset = $this->registry->get($this->registryNamespace,
'recordOffset', []);
190 $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
191 $queryBuilder = $connectionPool->getQueryBuilderForTable($this->table);
192 $queryBuilder->getRestrictions()
194 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
197 ->select(
'uid',
'pid', $this->fieldToMigrate)
200 $queryBuilder->expr()->isNotNull($this->fieldToMigrate),
201 $queryBuilder->expr()->neq(
202 $this->fieldToMigrate,
203 $queryBuilder->createNamedParameter(
'', \PDO::PARAM_STR)
205 $queryBuilder->expr()->comparison(
206 'CAST(CAST(' . $queryBuilder->quoteIdentifier($this->fieldToMigrate) .
' AS DECIMAL) AS CHAR)',
208 'CAST(' . $queryBuilder->quoteIdentifier($this->fieldToMigrate) .
' AS CHAR)'
212 ->setFirstResult($limit)
215 }
catch (DBALException $e) {
216 throw new \RuntimeException(
217 'Database query failed. Error was: ' . $e->getPrevious()->getMessage(),
230 $fieldItems = GeneralUtility::trimExplode(
',', $row[$this->fieldToMigrate],
true);
231 if (empty($fieldItems) || is_numeric($row[$this->fieldToMigrate])) {
234 $fileadminDirectory = rtrim(
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'fileadminDir'],
'/') .
'/';
237 $storageUid = (int)$this->storage->getUid();
239 $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
241 foreach ($fieldItems as $item) {
249 if (!is_dir($targetDirectory)) {
250 GeneralUtility::mkdir_deep($targetDirectory);
256 $queryBuilder = $connectionPool->getQueryBuilderForTable(
'sys_file');
257 $queryBuilder->getRestrictions()->removeAll();
258 $existingFileRecord = $queryBuilder->select(
'uid')->from(
'sys_file')->where(
259 $queryBuilder->expr()->eq(
261 $queryBuilder->createNamedParameter($fileSha1, \PDO::PARAM_STR)
263 $queryBuilder->expr()->eq(
265 $queryBuilder->createNamedParameter($storageUid, \PDO::PARAM_INT)
267 )->execute()->fetch();
270 if (is_array($existingFileRecord)) {
271 $fileUid = $existingFileRecord[
'uid'];
278 if ($fileUid ===
null) {
284 $file = $this->storage->getFile($this->targetPath . $item);
285 $fileUid = $file->getUid();
286 }
catch (\InvalidArgumentException $e) {
288 $this->logger->notice(
289 'File ' . $this->sourcePath . $item .
' does not exist. Reference was not migrated.',
291 'table' => $this->table,
293 'field' => $this->fieldToMigrate,
303 'table_local' =>
'sys_file',
304 'pid' => $this->table ===
'pages' ? $row[
'uid'] : $row[
'pid'],
305 'uid_foreign' => $row[
'uid'],
306 'uid_local' => $fileUid,
310 'sorting_foreign' => $i,
313 $queryBuilder = $connectionPool->getQueryBuilderForTable(
'sys_file_reference');
314 $queryBuilder->insert(
'sys_file_reference')->values(
$fields)->execute();
321 if ($i === count($fieldItems)) {
322 $queryBuilder = $connectionPool->getQueryBuilderForTable($this->table);
323 $queryBuilder->update($this->table)->where(
324 $queryBuilder->expr()->eq(
326 $queryBuilder->createNamedParameter($row[
'uid'], \PDO::PARAM_INT)
328 )->set($this->fieldToMigrate, $i)->execute();