BlackbitDigitalCommerce / pimcore-data-director

Import Bundle for Pimcore
16 stars 3 forks source link

NFR: Can you please provide official document with the documentation on scripting language used to configure raw fields in export dataport? #51

Closed kaurov closed 1 year ago

kaurov commented 1 year ago

I mean there is UnitTest: $this->assertEquals('abc', $this->dataQuerySelectorResolver->resolve('scalar', $object)); $this->assertEquals('abc', $this->dataQuerySelectorResolver->resolve('getScalar', $object)); $this->assertEquals('123', $this->dataQuerySelectorResolver->resolve('object:scalar', $object)); $this->assertEquals('123,00', $this->dataQuerySelectorResolver->resolve('object:scalar:number_format#2,\,,', $object)); $this->assertEquals('ABC', $this->dataQuerySelectorResolver->resolve('scalar:strtoupper', $object)); $this->assertFalse($this->dataQuerySelectorResolver->resolve('scalar:empty', $object)); $this->assertEquals('BC', $this->dataQuerySelectorResolver->resolve('scalar:strtoupper:substr#%s,1,2', $object)); $this->assertEquals('ab', $this->dataQuerySelectorResolver->resolve('scalar:str_replace#c,,%s', $object)); $this->assertEquals('04.01.20 12:00:00', $this->dataQuerySelectorResolver->resolve('date:"format#d.m.y H:i:s"', $object)); $this->assertEquals('05.02.20 14:00:00', $this->dataQuerySelectorResolver->resolve('object:date:"format#d.m.y H:i:s"', $object)); $this->assertEquals(['scalar' => 'abc', 'object:scalar' => '123'], $this->dataQuerySelectorResolver->resolve('(scalar;object:scalar)', $object)); $this->assertEquals(['foo', 'bar'], $this->dataQuerySelectorResolver->resolve('array:all:(arrayItemValue)', $object)); $this->assertEquals(['de' => 'value-de', 'en' => 'value-en'], $this->dataQuerySelectorResolver->resolve('assocArray:each:(arrayItemValue)', $object)); $this->assertEquals([['test' => 'foo'], ['test' => 'bar']], $this->dataQuerySelectorResolver->resolve('array:all:(arrayItemValue as test)', $object)); $this->assertEquals([['arrayItemValue' => 'foo', 'id' => 1], ['arrayItemValue' => 'bar', 'id' => 2]], $this->dataQuerySelectorResolver->resolve('array:all:(arrayItemValue;id)', $object)); $this->assertEquals([['test' => 'foo', 'identifier' => 1], ['test' => 'bar', 'identifier' => 2]], $this->dataQuerySelectorResolver->resolve('array:all:(arrayItemValue as test;id as identifier)', $object)); $this->assertEquals('abc 123', $this->dataQuerySelectorResolver->resolve('(scalar;object:scalar):implode# ,%s', $object)); $this->assertEquals('foo bar', $this->dataQuerySelectorResolver->resolve('array:all:(arrayItemValue):implode# ,%s', $object)); $this->assertEquals('foo bar', $this->dataQuerySelectorResolver->resolve('array:(arrayItemValue):implode# ,%s', $object)); // optional, not documented $this->assertEquals('x y', $this->dataQuerySelectorResolver->resolve('array:all:(object:scalar):implode# ,%s', $object)); $this->assertEquals([[13], [13,12]], $this->dataQuerySelectorResolver->resolve('array:all:(object:array:all(id))', $object)); $this->assertEquals(['scalar' => 'abc', 'array:all:' => [1,2]], $this->dataQuerySelectorResolver->resolve('(scalar;array:all:(id))', $object)); $this->assertEquals([['id' => 1, 'subIds' => [13]], ['id' => 2, 'subIds' => [13,12]]], $this->dataQuerySelectorResolver->resolve('array:all:(id;object:array:all as subIds:(id))', $object)); $this->assertEquals([['subIds' => [13], 'arrayItemValue' => 'foo'], ['subIds' => [13, 12], 'arrayItemValue' => 'bar']], $this->dataQuerySelectorResolver->resolve('array:all:(object:array:all as subIds:(id);arrayItemValue)', $object)); $this->assertEquals([['data' => ['scalar' => 'x', 'anotherScalar' => 'y'], 'id' => 1], ['data' => ['scalar' => 'y', 'anotherScalar' => 'z'], 'id' => 2]], $this->dataQuerySelectorResolver->resolve('array:all:(object as data:(scalar;anotherScalar);id)', $object)); $this->assertEquals(['array:all:' => [1,2], 'scalar' => 'abc'], $this->dataQuerySelectorResolver->resolve('(array:all:(id);scalar)', $object)); $this->assertEquals([['id' => 1, 'data' => ['scalar' => 'x', 'anotherScalar' => 'y']], ['id' => 2, 'data' => ['scalar' => 'y', 'anotherScalar' => 'z']]], $this->dataQuerySelectorResolver->resolve('array:all:(id;object as data:(scalar;anotherScalar))', $object)); $this->assertEquals([], $this->dataQuerySelectorResolver->resolve('array:all:(id;object as data:(scalar;anotherScalar))', new stdClass()));

Where can I find: 1) the full documentation which queries can I use? 2) what is what in those queries, e.g. array:all:(id;object as data:(scalar;anotherScalar))

BlackbitDevs commented 1 year ago

I hope that all cases are covered in https://pimcore.blackbit.de/Blackbit/1.pimcore/Handb%C3%BCcher/Ultima-Import-Bundle.pdf - but just write your concrete use-case / question, then I will support you and probably add it to the docs.

Please also see https://www.youtube.com/watch?v=mAu_5Eg3q_o&list=PL4-QRNfdsdKIfzQIP-c9hRruXf0r48fjt&index=9 where I explain common use-cases for data query selectors.

Concerning

what is what in those queries, e.g. array:all:(id;object as data:(scalar;anotherScalar))

In the same DataQuerySelectorResolverTest file you can see the "data model" in the method testResolve(). This returns objects of an anonymous class (data query selectors do not only work with Pimcore classes but with any PHP objects - but of course they support some convenience things when used with Pimcore classes).

kaurov commented 1 year ago

Thanks