Overscan
Active member
So, I bit the bullet at last, paid the money and am test migrating my 12 year old forum from SMF to Xenforo. Its done a pretty good job in general, but I am missing the oldest attachments.
SMF 1.0 named attachment files differently from later versions and also did not store a file_hash value in the database. This caused me identical issues with missing old attachments with a previous import of my forum to Elkarte (an SMF fork) where the importer could not find the attachments due the their different filename format.
I've looked at the Xenforo import code and there is obviously code to deal with attachments missing a file_hash:
However it is mostly wrong.
The actual filenames for my old attachments are like this:
790_Rockwell-1_gif1930c2099b9fe0e6077e09dcf4c68d25
But of course the hash value isn't stored in the database.
This is relevant code for handling legacy attachments these from SMF:
I've never written any PHP code, but all my missing attachments match the $enc_name format so presumably I can do something like this;
and reimport my data?
This would seem to be a good candidate to add to the importer codebase to improve SMF forum to Xenforo migration experience.
SMF 1.0 named attachment files differently from later versions and also did not store a file_hash value in the database. This caused me identical issues with missing old attachments with a previous import of my forum to Elkarte (an SMF fork) where the importer could not find the attachments due the their different filename format.
I've looked at the Xenforo import code and there is obviously code to deal with attachments missing a file_hash:
Code:
if ($attachment['file_hash'] === '')
{
$filePath = "$attachmentPath/$attachment[filename]";
}
else
{
$filePath = "$attachmentPath/$attachment[id_attach]_$attachment[file_hash]";
}
However it is mostly wrong.
The actual filenames for my old attachments are like this:
790_Rockwell-1_gif1930c2099b9fe0e6077e09dcf4c68d25
But of course the hash value isn't stored in the database.
This is relevant code for handling legacy attachments these from SMF:
Code:
function getLegacyAttachmentFilename($filename, $attachment_id, $dir = null, $new = false)
{
global $modSettings;
$clean_name = $filename;
// Remove international characters (windows-1252)
// These lines should never be needed again. Still, behave.
// Sorry, no spaces, dots, or anything else but letters allowed.
$clean_name = preg_replace(array('/\s/', '/[^\w_\.\-]/'), array('_', ''), $clean_name);
$enc_name = $attachment_id . '_' . strtr($clean_name, '.', '_') . md5($clean_name);
$clean_name = preg_replace('~\.[\.]+~', '.', $clean_name);
if ($attachment_id == false || ($new && empty($modSettings['attachmentEncryptFilenames'])))
return $clean_name;
elseif ($new)
return $enc_name;
// Are we using multiple directories?
if (!empty($modSettings['currentAttachmentUploadDir']))
{
if (!is_array($modSettings['attachmentUploadDir']))
$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
$path = $modSettings['attachmentUploadDir'][$dir];
}
else
$path = $modSettings['attachmentUploadDir'];
if (file_exists($path . '/' . $enc_name))
$filename = $path . '/' . $enc_name;
else
$filename = $path . '/' . $clean_name;
return $filename;
}
I've never written any PHP code, but all my missing attachments match the $enc_name format so presumably I can do something like this;
Code:
if ($attachment['file_hash'] === '')
{
$clean_name = $attachment[filename]
$clean_name = preg_replace(array('/\s/', '/[^\w_\.\-]/'), array('_', ''), $clean_name);
$enc_name = $attachment[id_attach] . '_' . strtr($clean_name, '.', '_') . md5($clean_name);
$filePath = "$attachmentPath/$enc_name
}
else
{
$filePath = "$attachmentPath/$attachment[id_attach]_$attachment[file_hash]";
}
and reimport my data?
This would seem to be a good candidate to add to the importer codebase to improve SMF forum to Xenforo migration experience.