Bug #53622

Updating the file content fails with the FAL API

Added by Marco Huber about 6 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
File Abstraction Layer (FAL)
Target version:
-
Start date:
2013-11-13
Due date:
% Done:

0%

TYPO3 Version:
6.1
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

Creating/Updating files with the FAL API fails because FAL want's to update a field sys_file.mimetype. But the field is called sys_file.mime_type in the database.

To reproduce:

/** @var \TYPO3\CMS\Core\Resource\StorageRepository $storageRepository */
$storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
/** @var \TYPO3\CMS\Core\Resource\ResourceStorage $storage */
$storage = $storageRepository->findByUid(1);

//Create a file (or get an existing one, that makes no difference):
/** @var \TYPO3\CMS\Core\Resource\Folder $folder */
$folder = $storage->getFolder('/user_upload/');
$fileName = '123.txt';
$file = $storage->createFile($fileName, $folder); //A new record in sys_file is created and the file is created in the filesystem.

//Update the file
$fileContent = '12345filecontent';
$file->setContents($fileContent); //The file's content in the filesystem get's updated. But the mimetype changes and can not be updated in the database.
//this one throws the same error: $storage->setFileContents($file, $fileContent);

The error:

exec_UPDATEquery
caller: TYPO3\CMS\Core\Database\DatabaseConnection::exec_UPDATEquery
ERROR: Unknown column 'mimetype' in 'field list'
lastBuiltQuery: UPDATE sys_file SET mimetype='text/plain' WHERE uid=2071
debug_backtrace:
include(ysext/extbase/Scripts/CommandLineLauncher.php),li_dispatch.phpsh#65 
TYPO3\CMS\Extbase\Core\Bootstrap->run#32 
TYPO3\CMS\Extbase\Core\Bootstrap->handleRequest#197 
TYPO3\CMS\Extbase\Mvc\Cli\RequestHandler->handleRequest#208 
TYPO3\CMS\Extbase\Mvc\Dispatcher->dispatch#96 
TYPO3\CMS\Extbase\Mvc\Controller\CommandController->processRequest#100 
TYPO3\CMS\Extbase\Mvc\Controller\CommandController->callCommandMethod#114 
call_user_func_array#212 
BGM\MyExt\Command\MyCommandController->createFileCommand# 
TYPO3\CMS\Core\Resource\File->setContents#84 
TYPO3\CMS\Core\Resource\ResourceStorage->setFileContents#140 
TYPO3\CMS\Core\Resource\FileRepository->update#952 
TYPO3\CMS\Core\Database\DatabaseConnection->exec_UPDATEquery#263 
TYPO3\CMS\Core\Database\DatabaseConnection->debug#247

The problem is $file->setContents which calls TYPO3\CMS\Core\Resource\FileRepository->update, but I have no idea how to fix this.


Related issues

Related to TYPO3 Core - Bug #49386: ResourceStorage::setFileContents does not properly translate file info properties Closed 2013-06-24

History

#1 Updated by Markus Klein about 6 years ago

  • Assignee set to Steffen Ritter
  • Target version set to next-patchlevel

#2 Updated by Marco Huber about 6 years ago

As a workaround I replaced $file->setContents($fileContent) with:

\TYPO3\CMS\Core\Utility\GeneralUtility::writeFile(PATH_site . $file->getPublicUrl(), $fileContent, TRUE);
/** @var \TYPO3\CMS\Core\Resource\Service\IndexerService $indexerService */
$indexerService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService');
$indexerService->indexFile($file);

#3 Updated by Marc Bastian Heinrichs about 6 years ago

  • Status changed from New to Needs Feedback
  • Assignee deleted (Steffen Ritter)

Was rather fixed in #49386 and should be in 6.1.5. Which version to you use?

#4 Updated by Marco Huber about 6 years ago

Shame on me, on the development server I was still using 6.1.3, on live 6.1.5. After updating the development server everything is ok. So this issue can be closed.

Thank you Marc!

#5 Updated by Alexander Opitz about 6 years ago

  • Status changed from Needs Feedback to Closed
  • Target version deleted (next-patchlevel)

Also available in: Atom PDF