In preparation for #2161591: Change default active config from file storage to DB storage I have coded an XML encoding that will yield well to querying with XPath and to type safe decoding within a very few lines of code. An example of the XML produced (in database only, this not user-facing):
<array>
<string key="id">stark_admin</string>
<string key="uuid">ab7f7ccd-242b-4898-8901-1c4ba3bb65fb</string>
<integer key="weight">1</integer>
<boolean key="status">1</boolean>
<string key="langcode">en</string>
<string key="theme">stark</string>
<string key="region">sidebar_first</string>
<string key="plugin">system_menu_block:admin</string>
<array key="settings">
<string key="label">Administration</string>
<string key="module">system</string>
<string key="label_display">visible</string>
<integer key="cache">-1</integer>
</array>
<array key="visibility">
<array key="path">
<integer key="visibility">0</integer>
<string key="pages"/>
</array>
<array key="role">
<array key="roles"/>
</array>
<array key="node_type">
<array key="types"/>
</array>
<string key="visibility__active_tab">edit-visibility-path</string>
</array>
</array>
Querying for not-visible blocks:
MariaDB [d8]> select name from config_snapshot where extractvalue(data, 'count(//*[@key="visibility" and text()=0])') >0;
+-------------------------+
| name |
+-------------------------+
| block.block.stark_admin |
| block.block.stark_login |
| block.block.stark_tools |
+-------------------------+
3 rows in set (0.02 sec)
Comments
Comment #1
chx commentedComment #3
chx commentedComment #4
chx commentedComment #5
chx commentedThis is a little less WTF-y.
Comment #6
chx commentedComment #7
chx commentedComment #10
chx commentedComment #12
chx commentedComment #15
chx commentedThe test passes for me.
Comment #18
chx commentedtwistor suggested using text() instead of @value ; I changed the code accordingly and I also simplified the decoder. The code http://privatepaste.com/e808e14583 is here for now until I find time (likely tomorrow) to fix the snapshot test.
Comment #19
sunI wonder whether we perhaps want to (1) split the configuration storage serialization formats into own classes and (2) inject the desired one into the ConfigStorage service?
We have a few Serializers by now already:
1. serialize()
2. YAML
3. JSON
4. XML
→ Drupal\Core\Config\Serializer\SerializerInterface
That would allow people to use an existing storage, without having a hard-coded serialization format baked-in.
That way, you can use FileStorage with YAML or JSON, and DatabaseStorage with serialize or XML, whatever makes sense to you.
Regarding the XML schema/format here: Would it make sense to use the data type as element name?
(leaving the key name as attribute)
Comment #20
chx commentedSuch a split is IMO beyond the scope of this issue but it is a very good idea nonetheless. I was thinking on making this little array2xml project available separately.
Using the type as the element name is a good idea, thanks! I thought of using the key but of course that didn't work...
I will get the snapshot test pass and post the code.
Comment #21
chx commentedComment #23
chx commentedI can't reproduce this locally but nonetheless I have discovered the need for HTML escape which is suspciously close to these exceptions.
Comment #24
chx commentedComment #25
twistor commentedSimpleXMLElement::addChild() doesn't encode ampersands (&). It does encode < and >, however.
Setting the value directly using should work.
Comment #26
chx commentedYes, until you realize it doesn't encode the ampersand in
<so when decoding back those are lost. Diff #21 and #23 please.Comment #27
eclipsegc commentedI've not read or played with this patch, but I really like the example xml output I'm seeing. I'll give this some of my time tomorrow.
Eclipse
Comment #30
crazysix commentedchx, when you refer to an array2xml project, are you talking about a drupal array, or one created by the developer? I have a simple module that takes a properly formatted array and outputs xml. I'd be interested to see if you got anywhere with that and if I could help.
Comment #31
chx commentedI meant the decode-encode pair in this patch. And this issue needs at least a reroll and in general needs someone to carry it home.
Comment #32
andypostSuppose postgres affected which could use "jsonb-ng" for serialization much faster
PS: overall issue could help one more leakage in libxml
Comment #33
chx commentedSo we talked about making default_backend the db driver but I do not think this happened. It should. Then this can become MySQL only and PgSQL can provide jsonb etc. I dumped this code to https://github.com/chx/array2xml btw.
Comment #40
andypostIt still makes sense in context of refactoring of serialization #839444: Make serializer customizable for Cache\DatabaseBackend
Comment #44
andypostGuess it could be closed for JSON format proposed for D10
Comment #45
ghost of drupal past