eZ Community » Forums » eZ Publish 5 Platform » Contributing an ezimage field with...
expandshrink

Contributing an ezimage field with the content service

Contributing an ezimage field with the content service

Monday 08 February 2016 11:11:22 am - 4 replies

Hi,

I’m trying to create a content with an ezimage filed in php with ez publish community 2014.11.

Here is my code:

$imageValue = ImageValue::fromString($logoFilePath);
$contentUpdateStruct->setField('logo', $imageValue, $language);

It worked well until I activated the dfs cluster mode. Since then I get this exception:

eZ\Publish\Core\IO\Exception\InvalidBinaryFileIdException: Argument 'BinaryFile::id' is invalid: '/var/mysite/storage/images/3/0/2/0/203-2-fre-FR/logo.png' is wrong value in class 'BinaryFile'

The exception is thrown by eZ\Publish\Core\IO\UrlDecorator\Prefix::undecorate(), wich doesn’t find the prefix at the beginning of the file path: it is looking for 'var/mysite/storage', but file id begins with a slash /.

I think I can easily fix it in the code by looking for a / at the beginning of the file id, but it wouldn’t be clean and I wonder if it could simply be a matter of misconfiguration somewhere? should the fileid begin without a slash, or should the prefix begin with one?

in my ezpublish.yml, var_dir doesn’t begin with a slash, and the shared directory for the nfs adapter is absolute (/home/[...]//$var_dir/$storage_dir/

Modified on Monday 08 February 2016 12:00:22 pm by Ronan Leroy

Monday 08 February 2016 11:59:14 am

Here is the trace from the exception (starting with the call to ContentService->UpdateContent()):

Argument 'BinaryFile::id' is invalid: '/var/arc/storage/images/3/0/2/0/203-2-fre-FR/logo.png' is wrong value in class 'BinaryFile'
#0 /home/vagrant/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/IO/UrlRedecorator.php(37): eZ\Publish\Core\IO\UrlDecorator\Prefix->undecorate('/var/arc/storag...')
#1 /home/vagrant/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Persistence/Legacy/Content/FieldValue/Converter/Image.php(205): eZ\Publish\Core\IO\UrlRedecorator->redecorateFromTarget('/var/arc/storag...')
#2 /home/vagrant/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Persistence/Legacy/Content/FieldValue/Converter/Image.php(173): eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\Image->parseLegacyXml('<?xml version="...')
#3 /home/vagrant/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Persistence/Legacy/Content/Mapper.php(419): eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\Image->toFieldValue(Object(eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue), Object(eZ\Publish\SPI\Persistence\Content\FieldValue))
#4 /home/vagrant/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Persistence/Legacy/Content/Mapper.php(382): eZ\Publish\Core\Persistence\Legacy\Content\Mapper->extractFieldValueFromRow(Array, 'ezimage')
#5 /home/vagrant/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Persistence/Legacy/Content/Mapper.php(212): eZ\Publish\Core\Persistence\Legacy\Content\Mapper->extractFieldFromRow(Array)
#6 /home/vagrant/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Persistence/Legacy/Content/Handler.php(327): eZ\Publish\Core\Persistence\Legacy\Content\Mapper->extractContentFromRows(Array)
#7 /home/vagrant/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Persistence/Legacy/Content/Handler.php(497): eZ\Publish\Core\Persistence\Legacy\Content\Handler->load(60, 2)
#8 /home/vagrant/www/ezpublish/cache/dev/ezpublishDevDebugProjectContainer.php(34092): eZ\Publish\Core\Persistence\Legacy\Content\Handler->updateContent(60, 2, Object(eZ\Publish\SPI\Persistence\Content\UpdateStruct))
#9 /home/vagrant/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Persistence/Cache/ContentHandler.php(169): eZPublishCorePersistenceLegacyContentHandler_000000005cb31c7d0000000056f2760e->updateContent(60, 2, Object(eZ\Publish\SPI\Persistence\Content\UpdateStruct))
#10 /home/vagrant/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Repository/ContentService.php(1389): eZ\Publish\Core\Persistence\Cache\ContentHandler->updateContent(60, 2, Object(eZ\Publish\SPI\Persistence\Content\UpdateStruct))
#11 /home/vagrant/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/SignalSlot/ContentService.php(396): eZ\Publish\Core\Repository\ContentService->updateContent(Object(eZ\Publish\Core\Repository\Values\Content\VersionInfo), Object(eZ\Publish\Core\Repository\Values\Content\ContentUpdateStruct))
#12 /home/vagrant/www/ezpublish/cache/dev/ezpublishDevDebugProjectContainer.php(29142): eZ\Publish\Core\SignalSlot\ContentService->updateContent(Object(eZ\Publish\Core\Repository\Values\Content\VersionInfo), Object(eZ\Publish\Core\Repository\Values\Content\ContentUpdateStruct))

Monday 08 February 2016 1:58:34 pm

Hi there.

What exact kernel version is this happening on (composer show -i | grep ezpublish-kernel from the root) ? Could you also please include your DFS / vardir config ?

One thing to clarify first: you're not creating content, but updating an existing content item, aren't you ? You'd be using a ContentCreateStruct, and not a ContentUpdateStruct, otherwise.

That aside, I think that what is happening here is that it fails when reading the existing value, that might have been created before DFS was enabled.

Monday 08 February 2016 3:14:58 pm

The kernel version is v2014.11.8.

Here is the config:

# ezpublish.yml
 ez_io:
    metadata_handlers:
        cluster:
            legacy_dfs_cluster:
                connection: doctrine.dbal.ezdfs_connection
    binarydata_handlers:
        nfs:
            flysystem:
                adapter: nfs_adapter
ezpublish:
    system:
        mysite:
            repository: mysite_repository
            var_dir: var/mysite

#ezpublish_dev.yml 
oneup_flysystem:
    adapters:
        nfs_adapter:
            local:
                directory: "/home/vagrant/www/share/$var_dir$/$storage_dir$" 

It is in fact an update to an existing content. But the content is created in the same script that updates it, so it didn’t exist before dfs was enabled.

The problem appears when the updateContent method reloads the content it juste saved in order to return it, as seen lines #7-8 of the trace.

The updateContent method looks like this, line 497 is the return:

     public function updateContent( $contentId, $versionNo, UpdateStruct $updateStruct )
    {
        $content = $this->load( $contentId, $versionNo );
        $this->contentGateway->updateVersion( $contentId, $versionNo, $updateStruct );
        $contentType = $this->contentTypeHandler->load( $content->versionInfo->contentInfo->contentTypeId );
        $this->fieldHandler->updateFields( $content, $updateStruct, $contentType );
        foreach ( $updateStruct->name as $language => $name )
        {
            $this->contentGateway->setName(
                $contentId,
                $versionNo,
                $name,
                $language
            );
        }
        return $this->load( $contentId, $versionNo );
    }

Adding these two lines to eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterImage::parseLegacyXml does solve the problem (but it's ugly as hell)

        if (substr($legacyUrl, 0, 1) == '/')
            $legacyUrl = substr($legacyUrl, 1); 

Modified on Monday 08 February 2016 3:15:58 pm by Ronan Leroy

Tuesday 10 May 2016 1:24:06 pm

I have the same symptoms on a 5.4.5 setup:

- current env not set up in cluster mode

- content db might come from an env which was in cluster mode. it might also come from old versions, much upgraded

I am trying to create / update contents via API.

I am getting the error from UrlDecorator/Prefix.

The urls which do not get validated do start with a /

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from