Resource icon

MetaMirror 1.6.1

No permission to download
Mick, now the rehosting has completed on my site, I've got the option set on for "instant rehosting"

Does the cron still need to be running with this enabled?

The instant re-hosting is working perfectly by the way

Code:
2013-09-10 12:41:36 Rehosted: http://farm6.staticflickr.com/5344/9007433258_906732d0d9_b.jpg For post # 1213313
2013-09-10 12:41:36 Modified post # 1213313 Changed: http://farm6.staticflickr.com/5344/9007433258_906732d0d9_b.jpg => [attach=full]38543[/attach]
 
  • Like
Reactions: rdn
You can disable the cron job once it's finished if you are using instant re-hosting.

All the cron job does is scan existing posts for external IMG links. It flags posts so it won't scan them twice, but there's still some minor overhead to scanning flagged posts, so it's better disabled.
 
That looks similar to the issue MattW was having, if the thumbnail generation fails, then the XF attachment system assumes it is not an image. The only thing I can think of there is to re-run rebuilding thumbnails. :(

I don't THINK it's a MetaMirror issue, just showing up here because of the very large number of thumbnails being generate perhaps stresses the system. And if if that attachment worked before, them MM will not touch the attachment again, so it's something else (failing during rebuild)
Just coming back to this, I've checked the images, and the thumbnails didn't get created correctly, as they are 0 size
Rich (BB code):
z22se@z22se.co.uk [~/public_html/data/attachment-files/2010/07]# ls -al | grep 40346
-rw-r--r--  1 z22se z22se  129649 Sep  9 06:57 40346_awww.mediajustice.co.uk_images_astrawip_17072010604.jpg
z22se@z22se.co.uk [~/public_html/data/attachment-files/2010/07]# cd thumb/
z22se@z22se.co.uk [~/public_html/data/attachment-files/2010/07/thumb]# ls -al | grep 40346
-rw-r--r-- 1 z22se z22se    0 Sep  9 06:57 40346_awww.mediajustice.co.uk_images_astrawip_17072010604.jpg
 
I'm mirroring the live site to my ubuntu server at home, and I'll try re-building the thumbnails on there to see if it can be fixed.
 
I'm mirroring the live site to my ubuntu server at home, and I'll try re-building the thumbnails on there to see if it can be fixed.

In library/xenforo/deferred/AttachmentThumb.php there's the code to rebuild the attachment thumbnails, starting
PHP:
class XenForo_Deferred_AttachmentThumb extends XenForo_Deferred_Abstract
{
    public function execute(array $deferred, array $data, $targetRunTime, &$status)
    {
        $data = array_merge(array(
            'batch' => 100,
            'position' => 0
        ), $data);

        /* @var $attachmentModel XenForo_Model_Attachment */
        $attachmentModel = XenForo_Model::create('XenForo_Model_Attachment');

        $s = microtime(true);

        $dataIds = $attachmentModel->getAttachmentDataIdsInRange($data['position'], $data['batch']);
        if (sizeof($dataIds) == 0)
        {
            return false;
        }

        foreach ($dataIds AS $dataId)
        {
            $data['position'] = $dataId;

            $dw = XenForo_DataWriter::create('XenForo_DataWriter_AttachmentData', XenForo_DataWriter::ERROR_SILENT);
            if ($dw->setExistingData($dataId)
                && $dw->get('width')
                && XenForo_Image_Abstract::canResize($dw->get('width'), $dw->get('height'))
            )
            {

As you can see by the two checks:
PHP:
                && $dw->get('width')
                && XenForo_Image_Abstract::canResize($dw->get('width'), $dw->get('height'))
where
PHP:
    public static function canResize($width, $height)
    {
        return (($width * $height) < XenForo_Application::getConfig()->maxImageResizePixelCount);
    }

It will skip attachments that have a width of zero, the second check will return true.

So if you temporarily comment out one line, like
PHP:
//                && $dw->get('width')

Then it should re-parse ALL attachments, attempting to create thumbnails for them. Non-images will be skipped by subsequent code checks, and it should fix things.

I just ran it with that line commented out, and it seemed fine. Since most attachments are images, it won't take much longer.
 
Okay I think you also need to change the line just below that:

PHP:
                if ($imageInfo)
to
PHP:
                if ($imageInfo && ($imageInfo[2] == IMAGETYPE_GIF ||  $imageInfo[2] == IMAGETYPE_JPEG || $imageInfo[2] == IMAGETYPE_PNG))

Although I'm not entirely sure now this is your problem, as you say you get thumbnails generated, but they are of zero size. Hmm
 
I'll give it a whirl, and see what happens. From looking at that code, it's getting the 'width' value from the table, which is there, because the actual images have been generated. It's just the thumbnails which are 0 size, because the current thumbnail image is 0 bytes.

This looks to be the bit of code actually generating the thumbnails:

PHP:
{
                                $attach = $dw->getMergedData();
                                $attachFile = $attachmentModel->getAttachmentDataFilePath($attach);
                                $imageInfo = @getimagesize($attachFile);
                                if ($imageInfo)
                                {
                                        $image = XenForo_Image_Abstract::createFromFile($attachFile, $imageInfo[2]);
                                        if ($image)
                                        {
                                                if ($image->thumbnail(XenForo_Application::get('options')->attachmentThumbnailDimensions))
                                                {
                                                        ob_start();
                                                        $image->output($imageInfo[2]);
                                                        $thumbData = ob_get_contents();
                                                        ob_end_clean();
                                                }
                                                else
                                                {
                                                        // no resize necessary, use the original
                                                        $thumbData = file_get_contents($attachFile);
                                                }

                                                $dw->set('thumbnail_width', $image->getWidth());
                                                $dw->set('thumbnail_height', $image->getHeight());
                                                $dw->setExtraData(XenForo_DataWriter_AttachmentData::DATA_THUMB_DATA, $thumbData);
                                                try
                                                {
                                                        $dw->save();
                                                }
                                                catch (Exception $e)
                                                {
                                                        XenForo_Error::logException($e, false, "Thumb rebuild for #$dataId: ");
                                                }

                                                unset($image);
                                        }
                                }
                        }

Where it's comparing the thumbnail dimensions from the options, to the actual values of the thumbnail file. Maybe @Mike or @Kier could comment?
 
Just finished testing this locally, and the images now have dimensions and are working correctly in the posts
fixed.webp
 
I've seen mods for other forums that would take any images not hosted on your site, and upload them as an attachment to prevent hotlinking.
Is there a mod for xenforo that does this?

For example if a user uploaded an image to photobucket, I'd like a cron to run that would grab that image, upload it to my forum via attachments and replace the image in the post with the one hosted on my forum.

Thanks
I have written an add-on that automatically rehosts external images and re-writes the links to post to the local files.

http://xenforo.com/community/resources/metamirror.2117/
How is hotlink protection enabled in MetaMirror?
 
It wouldn't have anything to do with hotlink protection, that would be on your server itself.

Correct. All MetaMirror is doing is taking external files, and making them either be attachments, or local files in the /MetaMirrorCache folder.

If you've already got hotlink protection, then nothing will change.
 
I want to force SSL through htaccess. Is there anything special I need to do to MetaMirror options after forcing SSL in htaccess?
 
I want to force SSL through htaccess. Is there anything special I need to do to MetaMirror options after forcing SSL in htaccess?

No. The actual protocol (HTTP/HTTPS) is irrelevant to attachments or locally linked files.
 
  • Like
Reactions: DRE
Just finished on the live site, and now all images are working correctly (y)
and just for clarification, I didn't need to change anything. I just ran the "Rebuild Attachment Thumbnails", so if @DRE still has some not working, it's worth giving it a go to see if it fixes your issue as well.
 
Top Bottom