[TYPO3-dev] script to convert Image path to new format
Roman Pretory
roman at pretory.at
Mon Apr 4 10:33:13 CEST 2016
Thanks for help
I make the covertion now step by step like this:
Check both Tables
Read out oldtable
while
-readout inset in new table with marker in this field
-get uid from new record
-make move and refernce
-check sum of files of old record und new ref to record
-update marker of new record to sum of files
..
Make ref like this:
function Createfileref($uid,$pid,$filename,$oldfiledir,$newstorgefolder,$tablenames){
# $filename = 'xyv.pdf';
$file = $this->conf['root'].'/'.$oldfiledir.'/'.$filename;
# $newstorgefolder = 'user_upload/tx_atodomains';
# $newstorgefolderroot = '/data/www/z02.ottenheim.at/html/fileadmin/';
$newstorgefolderroot = $this->conf['root'].'/fileadmin/';
# $uid= '1';
# $pid = '22';
# $tablenames ='tx_atodomains_domain_model_pi1';
if(!file_exists($file)) {echo 'Datei Existiert nicht: '.$file;exit;}
$storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
$storage = $storageRepository->findByUid(1);
if(!file_exists($newstorgefolderroot.$newstorgefolder)) { $fileObject = $storage->addFile($file,$storage->createFolder($newstorgefolder), $filename);}
else{ $fileObject = $storage->addFile($file,$storage->getFolder($newstorgefolder), $filename);}
$s1 = $fileObject->getIdentifier(); // Should output "/newFile" */
$fileref = $s1;
$someFileIdentifier = $fileref; // image name in the storage repository (e.g. directly in fileadmin/ root, otherwise specify the subdirectory here, e.ge. 'templates/image123.png'
$storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository'); // create instance to storage repository
$storage = $storageRepository->findByUid(1); // get file storage with uid 1 (this should by default point to your fileadmin/ directory)
$file1 = $storage->getFile($someFileIdentifier); // create file object for the image (the file will be indexed if necessary)
$data = array();
$data['sys_file_reference'][$fileref] = array(
'table_local' => 'sys_file',
'uid_local' => $file1->getUid(),
'tablenames' => $tablenames,
'uid_foreign' => $uid, // uid of your content record
'fieldname' => 'formalare',
'pid' => $pid, // page id of content record
);
$tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
$tce->stripslashes_values = 0;
$tce->start($data, array());
$tce->process_datamap();
return;
}
I try this job to make with the scipt execute after install,
but there I was not able to create any output, and so I make this now in the fronend with a swich in the ext_conf_template.txt
THX Roman
More information about the TYPO3-dev
mailing list