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

chx’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, config_db_xml.patch, failed testing.

chx’s picture

Status: Needs work » Needs review
StatusFileSize
new2.72 KB
chx’s picture

Title: Change DatabaseStorage to use XML instead of serialize » Change DatabaseStorage to use XML instead of serialize (e!)
Issue summary: View changes
chx’s picture

StatusFileSize
new2.81 KB
new1.15 KB

This is a little less WTF-y.

chx’s picture

Issue summary: View changes
StatusFileSize
new2.64 KB
chx’s picture

Issue summary: View changes
StatusFileSize
new2.63 KB

The last submitted patch, 3: 2162161_2.patch, failed testing.

The last submitted patch, 5: 2162161_3.patch, failed testing.

chx’s picture

StatusFileSize
new2.6 KB

The last submitted patch, 6: 2162161_4.patch, failed testing.

chx’s picture

Issue summary: View changes
StatusFileSize
new2.38 KB

The last submitted patch, 7: 2162161_5.patch, failed testing.

The last submitted patch, 10: 2162161_8.patch, failed testing.

chx’s picture

StatusFileSize
new3.13 KB

The test passes for me.

Status: Needs review » Needs work

The last submitted patch, 15: 2162161_10.patch, failed testing.

The last submitted patch, 12: 2162161_9.patch, failed testing.

chx’s picture

twistor 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.

sun’s picture

I 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

public function encode()
public function decode()

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)

- <e type="integer" key="foo">bar</e>
+ <integer key="foo">bar</integer>
chx’s picture

Such 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.

chx’s picture

Title: Change DatabaseStorage to use XML instead of serialize (e!) » Change DatabaseStorage to use XML instead of serialize
Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new2.96 KB

Status: Needs review » Needs work

The last submitted patch, 21: 2162161_21.patch, failed testing.

chx’s picture

StatusFileSize
new2.97 KB

I can't reproduce this locally but nonetheless I have discovered the need for HTML escape which is suspciously close to these exceptions.

chx’s picture

Status: Needs work » Needs review
twistor’s picture

SimpleXMLElement::addChild() doesn't encode ampersands (&). It does encode < and >, however.

Setting the value directly using should work.

$simplexml->{gettype($value)} = is_array($value) ? '' : (string) $value;
chx’s picture

Yes, until you realize it doesn't encode the ampersand in &lt; so when decoding back those are lost. Diff #21 and #23 please.

eclipsegc’s picture

I'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

anavarre queued 23: 2162161_23.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 23: 2162161_23.patch, failed testing.

crazysix’s picture

chx, 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.

chx’s picture

I 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.

andypost’s picture

Issue tags: +PostgreSQL

Suppose postgres affected which could use "jsonb-ng" for serialization much faster

PS: overall issue could help one more leakage in libxml

chx’s picture

So 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.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Version: 8.6.x-dev » 8.8.x-dev
Related issues: +#839444: Make serializer customizable for Cache\DatabaseBackend

It still makes sense in context of refactoring of serialization #839444: Make serializer customizable for Cache\DatabaseBackend

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

andypost’s picture

Guess it could be closed for JSON format proposed for D10

ghost of drupal past’s picture

Status: Needs work » Closed (won't fix)