symfony-cmf / media-bundle

UNMAINTAINED - Minimalistic interfaces to handle media in the context of the CMF
http://cmf.symfony.com/
30 stars 40 forks source link

Array to string conversion when setting an array metadata #123

Closed gonzalovilaseca closed 8 years ago

gonzalovilaseca commented 9 years ago

When I set metadata like this: (file is a Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\Image object)

$file->setMetadataValue('filters', array('foo' => 'bar');

I get a Notice: Array to string conversion error when performing a flush.

I've tried to debug it but can't really find the issue. In the property values that are checked in Jackalope\NodeType\NodeType, metadataKeys has a multiple property value of false.

If I look into phpcr_type_props, multiple is set to false both for metadata and metadataKeys.

Changing the definition of metadata in AbstractMedia.phpcr.xml doesn't seem to make any difference.

Any ideas?

dbu commented 9 years ago

the problem is that phpcr-odm multivalue fields can not be nested, only flat arrays. @dantleech was working on options to support nested arrays in fields.

gonzalovilaseca commented 9 years ago

Ok, so I've tried:

$file->setMetadata(array('a'));
$file->setMetadata(array('a'=>'b'));
$file->setMetadataValue('a','b');

And none of them work, they all throw Notice: Array to string conversion. Any idea as how can I set the metadata?

dbu commented 9 years ago

this is unexpected. the metadata field is mapped as an associative field of type string. are you sure you don't have some event listener that causes the problem? do you see on which line this notice is triggered? can you try to checkout just this bundle, composer install and then add some metadata to Tests/WebTest/TestApp so that we can reproduce the problem? if you manage to do that, please do a PR with the failing test, that will help a lot to fix the issue.

gonzalovilaseca commented 9 years ago

Its in

in vendor/jackalope/jackalope/src/Jackalope/NodeType/NodeType.php at line 206 
      throw new ConstraintViolationException("The property definition is multivalued, but the value '$value' is not.");
                    }
                    if (is_array($value)) {
                        throw new ConstraintViolationException("The value $value is multivalued, but the property definition is not.");
                    }
                }
                if (PropertyType::UNDEFINED == $prop->getRequiredType()

The stack trace is:

at NodeType ->canSetProperty ('metadataKeys', array('a'), true)
in vendor/jackalope/jackalope/src/Jackalope/Node.php at line 526
at Node ->setProperty ('metadataKeys', array('a'), '1')
in vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/UnitOfWork.php at line 3852
at UnitOfWork ->processAssoc (object(Node), array('type' => 'string', 'assoc' => 'metadataKeys', 'nullable' => true, 'fieldName' => 'metadata', 'multivalue' => true, 'property' => 'metadata', 'assocNulls' => 'metadataNulls', 'declared' => 'Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\File'), array('a' => 'b'))
in vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/UnitOfWork.php at line 2362
at UnitOfWork ->executeInserts (array('000000006fa5fb8400007f4ef758d38c' => object(Resource), '000000006fa5fb1000007f4ef758d38c' => object(Image)))
in vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/UnitOfWork.php at line 2193

I'm going to do what you suggested, thanks, will keep you updated.

gonzalovilaseca commented 9 years ago

I've spent the whole morning trying to run the tests without success, I'm getting this error:

PHPCR\RepositoryException: Unexpected error talking to the backend: An exception occurred while executing 'SELECT 1 FROM phpcr_workspaces WHERE name = ?' with params ["default"]:

Is as if the tests db is not configured correctly, but I can't seem to find where or why.

dbu commented 9 years ago

this is what travis is doing to run the tests: https://github.com/symfony-cmf/MediaBundle/blob/master/.travis.yml

maybe check if you can run vendor/symfony-cmf/testing/bin/travis/phpcr_odm_doctrine_dbal.sh - this should be present if you ran composer update.

gonzalovilaseca commented 9 years ago

Don't know exactly how but I made it work...PR #124 as requested.