Fixed Watermark Problem

Snog

Well-known member
Affected version
2.0.2
XFMG\Attachment\Media.php->Function onAssociation contains this...
Code:
if ($container->canAddWatermark(false) && !$container->canAddMediaWithoutWatermark())
{
    $mediaRepo = \XF::repository('XFMG:Media');
    $watermarkPath = $mediaRepo->getAbstractedWatermarkPath($options->xfmgWatermarking['watermark_hash']);
    if (\XF::app()->fs()->has($watermarkPath))
    {
        $tempWatermark = \XF\Util\File::copyAbstractedPathToTempFile($watermarkPath);

        /** @var \XFMG\Service\Media\Watermarker $watermarker */
        $watermarker = \XF::service('XFMG:Media\Watermarker', $container, $tempWatermark);
        $watermarker->watermark();
    }
}

Which is all fine and dandy, but XFMG\Service\Watermarker.php->function watermark contains this...
Code:
if (!$this->canWatermark())
{
    return false;
}

Which overrides the $container->canAddWatermark(false) and checks permissions before watermarking a new upload which can lead to an upload not being watermarked in some cases.

This may or may not be associated with the permission problem I reported here...
https://xenforo.com/community/threads/permission-problem.143236/

EDIT: I would suggest that any permission checks be done in the functions calling the service. Not in the service itself.
 
Last edited:
I've made some changes here to make the code a bit clearer and moved the permission checks out of the service.

I'm not seeing the correlation between this bug and the permission one, but if you have further details on that, please post in that bug thread.
 
Top Bottom