30 protected $title =
'Migrate all file links of RTE-enabled fields to FAL';
77 public function init() {
81 $storages = $storageRepository->findAll();
82 $this->storage = $storages[0];
83 $this->fileAdminDir =
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'fileadminDir'];
95 $description =
'This update wizard goes through all file links in all rich-text fields and changes them to FAL references.';
96 $description .=
'If the process times out, please run it again.';
100 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
101 'This script bases itself on the references contained in the general reference index (sys_refindex). It is strongly advised to update it before running this wizard.',
102 'Updating the reference index',
103 \
TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
105 $description .= $message->render();
109 if (count($oldRecords) > 0) {
110 $description .=
'<br />There are currently <strong>' . count($oldRecords) .
'</strong> links to update.<br />';
129 if (!$this->storage) {
130 $customMessages =
'No file resource storage found';
136 foreach ($records as $singleRecord) {
141 if (count($this->errors) > 0) {
142 $customMessages .= implode(PHP_EOL, $this->errors);
143 if ($this->convertedLinkCounter == 0) {
149 if ($this->convertedLinkCounter > 0) {
150 $customMessages = $this->convertedLinkCounter .
' links converted.' . PHP_EOL . $customMessages;
152 $customMessages .=
'No file links found';
165 $record =
$GLOBALS[
'TYPO3_DB']->exec_SELECTgetSingleRow(
166 'uid, ' . $reference[
'field'],
167 $reference[
'tablename'],
168 'uid = ' . $reference[
'recuid']
170 if (is_array($record)) {
174 $this->errors[] =
'Original record not found for reference to element ' . $reference[
'recuid'] .
' of table ' . $reference[
'tablename'] .
' in field ' . $reference[
'field'] .
'. Not migrated.';
190 }
catch (\InvalidArgumentException $exception) {
192 $this->errors[] = $reference[
'ref_string'] .
' could not be replaced. File does not exist.';
194 if ($fileObject instanceof \
TYPO3\CMS\Core\Resource\AbstractFile) {
196 $content = $record[$reference[
'field']];
197 $regularExpression =
'$<((link|LINK) ' . str_replace(
'%2F',
'/', rawurlencode($reference[
'ref_string'])) .
').*>$';
199 $result = preg_match($regularExpression, $content, $matches);
202 $modifiedContent = str_replace(
204 'link file:' . $fileObject->getUid(),
205 $record[$reference[
'field']]
208 $this->
saveChanges($modifiedContent, $reference, $fileObject);
209 $this->convertedLinkCounter++;
211 $this->errors[] = $reference[
'ref_string'] .
' not found in referenced element (uid: ' . $reference[
'recuid'] .
' of table ' . $reference[
'tablename'] .
' in field ' . $reference[
'field'] .
'). Reference index was probably out of date.';
225 if (@file_exists(PATH_site .
'/' . $path)) {
227 $fileObject = $this->storage->getFile(
234 }
catch (\
TYPO3\CMS\Core\Resource\
Exception\FileDoesNotExistException $notFoundException) {
236 $this->errors[] = $path .
' not found (referenced in element ' . $reference[
'recuid'] .
' of table ' . $reference[
'tablename'] .
' in field ' . $reference[
'field'] .
')';
240 $recpid =
$GLOBALS[
'TYPO3_DB']->exec_SELECTgetRows(
242 $reference[
'tablename'],
243 'uid = ' . (
int)$reference[
'recuid']
245 $this->errors[] =
'File not found (page / uid / path / table / field):,' 246 . $recpid[0][
'pid'] .
',' 247 . $reference[
'recuid'] .
',' 249 . $reference[
'tablename'] .
',' 250 . $reference[
'field'];
263 protected function saveChanges($modifiedText, array $reference, $file) {
268 if (!$this->isDbalInstalled) {
269 $GLOBALS[
'TYPO3_DB']->sql_query(
'START TRANSACTION');
273 $GLOBALS[
'TYPO3_DB']->exec_UPDATEquery(
274 $reference[
'tablename'],
275 'uid = ' . $reference[
'recuid'],
277 $reference[
'field'] => $modifiedText
280 $this->queries[] = htmlspecialchars(str_replace(LF,
' ',
$GLOBALS[
'TYPO3_DB']->debug_lastBuiltQuery));
283 $GLOBALS[
'TYPO3_DB']->exec_UPDATEquery(
285 'hash = ' .
$GLOBALS[
'TYPO3_DB']->fullQuoteStr($reference[
'hash'],
'sys_refindex'),
287 'ref_table' =>
'sys_file',
288 'ref_uid' => $file->getUid(),
292 $this->queries[] = str_replace(LF,
' ',
$GLOBALS[
'TYPO3_DB']->debug_lastBuiltQuery);
295 if (!$this->isDbalInstalled) {
296 $GLOBALS[
'TYPO3_DB']->sql_query(
'COMMIT');
308 $records =
$GLOBALS[
'TYPO3_DB']->exec_SELECTgetRows(
309 'hash, tablename, recuid, field, ref_table, ref_uid, ref_string',
311 'softref_key = \'typolink_tag\' AND ref_table = \'_FILE\' ' convertFileLinks(array $reference, array $record)
fetchReferencedFile($path, array $reference)
saveChanges($modifiedText, array $reference, $file)
static makeInstance($className)
migrateRecord(array $reference)
checkForUpdate(&$description)
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.
static isLoaded($key, $exitOnError=FALSE)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
performUpdate(array &$dbQueries, &$customMessages)