31 protected $title =
'Migrate all RTE magic images from uploads/RTEmagicC_* to fileadmin/_migrated/RTE/';
58 public function __construct() {
62 $this->logger = $logManager->getLogger(__CLASS__);
65 if (!empty(
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'RTE_imageStorageDir'])) {
66 $this->oldPrefix =
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'RTE_imageStorageDir'] .
'RTEmagicC_';
75 public function init() {
78 $storages = $storageRepository->findAll();
79 $this->storage = $storages[0];
89 $description =
'This update wizard goes through all magic images, located in "' . htmlspecialchars($this->oldPrefix) .
'", and moves the files to fileadmin/_migrated/RTE/.';
90 $description .=
'<br />It also moves the files from uploads/ to the fileadmin/_migrated/ path.';
94 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
95 '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.',
96 'Updating the reference index',
97 \
TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
99 $description .= $message->render();
102 if ($this->oldPrefix) {
104 if (count($oldRecords) > 0) {
105 $description .=
'<br />There are currently <strong>' . count($oldRecords) .
'</strong> magic images in the old directory.<br />';
125 throw new \Exception(
'PATH_site was undefined.');
128 $fileadminDirectory = rtrim(
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'fileadminDir'],
'/');
129 $targetDirectory =
'/_migrated/RTE/';
130 $fullTargetDirectory = PATH_site . $fileadminDirectory . $targetDirectory;
133 if (!is_dir($fullTargetDirectory)) {
139 foreach ($oldRecords as $refRecord) {
142 $sourceFileName = $refRecord[
'ref_string'];
144 $fullSourceFileName = PATH_site . $refRecord[
'ref_string'];
150 if (!file_exists($fullTargetFileName)) {
153 if (!file_exists(PATH_site . $sourceFileName)) {
154 $this->logger->notice(
'File ' . $sourceFileName .
' does not exist. Reference was not migrated.', array());
156 $format =
'File \'%s\' does not exist. Referencing field: %s.%d.%s. The reference was not migrated.';
157 $message = sprintf($format, $sourceFileName, $refRecord[
'tablename'], $refRecord[
'recuid'], $refRecord[
'field']);
158 $customMessages .= PHP_EOL . $message;
163 rename($fullSourceFileName, $fullTargetFileName);
167 $file = $this->storage->getFile($targetFileName);
168 if ($file instanceof \
TYPO3\CMS\Core\Resource\
File) {
170 $targetFieldName = $refRecord[
'field'];
171 $targetRecord = $this->db->exec_SELECTgetSingleRow(
172 'uid, ' . $targetFieldName,
173 $refRecord[
'tablename'],
174 'uid=' . (
int)$refRecord[
'recuid']
178 $searchString =
'src="' . $sourceFileName .
'"';
179 $replacementString =
'src="' . $fileadminDirectory . $targetFileName .
'"';
180 $replacementString .=
' data-htmlarea-file-uid="' . $file->getUid() .
'"';
181 $replacementString .=
' data-htmlarea-file-table="sys_file"';
182 $targetRecord[$targetFieldName] = str_replace(
185 $targetRecord[$targetFieldName]
188 $this->db->exec_UPDATEquery(
189 $refRecord[
'tablename'],
190 'uid=' . (
int)$refRecord[
'recuid'],
191 array($targetFieldName => $targetRecord[$targetFieldName])
193 $queries[] = str_replace(LF,
' ', $this->db->debug_lastBuiltQuery);
196 $this->db->exec_UPDATEquery(
198 'hash=' . $this->db->fullQuoteStr($refRecord[
'hash'],
'sys_refindex'),
200 'ref_table' =>
'sys_file',
201 'softref_key' =>
'rtehtmlarea_images',
202 'ref_uid' => $file->getUid(),
203 'ref_string' => $fileadminDirectory . $targetFileName
206 $queries[] = str_replace(LF,
' ', $this->db->debug_lastBuiltQuery);
222 $records = $this->db->exec_SELECTgetRows(
223 'hash, tablename, recuid, field, ref_table, ref_uid, ref_string',
225 'ref_string LIKE ' . $this->db->fullQuoteStr($this->db->escapeStrForLike($this->oldPrefix,
'sys_refindex') .
'%',
'sys_refindex'),
findMagicImagesInOldLocation()
static mkdir_deep($directory, $deepDirectory='')
static makeInstance($className)
checkForUpdate(&$description)
performUpdate(array &$dbQueries, &$customMessages)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]