$attachments = $this->db->fetchAll('
SELECT attachment.attachmentid AS attachment_id, attachment.userid AS user_id, ' . (self::$isVB4 ? 'contentid' : 'postid') . ' AS content_id, attachment.dateline AS attachment_date, ' . (self::$isVB4 ? 'filedata.filedata' : 'attachment.filedata') . ' AS file, ' . (self::$isVB4 ? 'filedata.thumbnail_filesize' : 'attachment.thumbnail_filesize') . ', attachment.filename, ' . (self::$isVB4 ? 'filedata.extension' : 'attachment.extension') . ' AS extension, ' . (self::$isVB4 ? 'filedata.filedataid' : 'attachment.attachmentid') . ' AS filesysid
FROM ' . $this->sourceDb . '.attachment
' . (self::$isVB4 ? 'LEFT JOIN ' . $this->sourceDb . '.filedata ON (filedata.filedataid = attachment.filedataid)' : '') . '
WHERE attachment.attachmentid BETWEEN ' . intval($start) . ' AND ' . intval($start + 999) . (self::$isVB4 ? ' AND attachment.contenttypeid = 1' : '') . '
' . (self::$isVB4 ? 'GROUP BY attachment.filedataid' : '') . '
ORDER BY attachment.attachmentid
')
)
{
echo "\r\n " . number_format(count($attachments)) . " new attachments\r\n";
foreach ($attachments as $attachment)
{
echo $attachment['attachment_id'] . ' ';
if (self::$attachFile AND file_exists(self::$attachFile . implode('/', preg_split('//', $attachment['user_id'], -1, PREG_SPLIT_NO_EMPTY)) . '/' . strval($attachment['filesysid']) . '.attach'))
{
$attachment['file'] = file_get_contents(self::$attachFile . implode('/', preg_split('//', $attachment['user_id'], -1, PREG_SPLIT_NO_EMPTY)) . '/' . strval($attachment['filesysid']) . '.attach');
}
else
{
$attachment['file'] = $attachment['file'];
}
if (!$attachment['file'])
{
echo '!!MISSING DATA!!';
continue;
}