Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[config:import:single] Writing to DB before using the ConfigImporter. #4236

Closed
melvinversluijs opened this issue Mar 17, 2020 · 0 comments · Fixed by #4237
Closed

[config:import:single] Writing to DB before using the ConfigImporter. #4236

melvinversluijs opened this issue Mar 17, 2020 · 0 comments · Fixed by #4237

Comments

@melvinversluijs
Copy link
Contributor

[config:import:single] Writing to DB without using the ConfigImporter.

Problem/Motivation

We noticed this issue when trying to install modules using the config:import:single command on a core.extension.yml file. While trying to install a module with this command the install hook is skipped which will result in missing DB tables.

This issue is caused by line 106 of the src/Command/Config/ImportSingleCommand.php file $source_storage->write($name, $value);

This write is hitting the write function of the underlaying DatabaseStorage object, which means it is already written to the DB before the ConfigImporter class is able to make it's comparison. When the ConfigImporter is initialised the Source and Target storages are exactly the same (Since they are both reading from the same DB).

I used xdebug while running this command and found that both the totalExtensionsToProcess and totalConfigurationToProcess properties of the ConfigImporter are always 0, which means the ConfigImporter is never writing to the DB.

To verify my theory I removed the entire $this->importConfig() block which gave me the exact same end result.

How to reproduce

Import a core.extension.yml file which includes a new module with it's own DB table. Afterwards the DB table will be missing.

Details to include:

System Info

Property Value
Drupal 8.8.1
Access to update.php Protected
Configuration files protected
Cron maintenance tasks Last run 4 minutes 2 seconds ago
Database system MySQL, MariaDB, Percona Server, or equivalent
Database system version 5.6.43
Database updates Up to date
Drupal core update status No update data available
Entity/field definitions Up to date
File system Writable (public download method)
JSON:API allowed operations Read-only
JSON:API revision support Limited
Node Access Permissions Disabled
PHP 7.3.11 (more information)
PHP extensions Enabled
PHP OPcode caching Enabled
Random number generation Successful
Search index progress 100% (0 remaining)
Serialized data types Not enabled
Trusted Host Settings Not enabled
Unicode library PHP Mbstring Extension
Update notifications Enabled
Upload progress Not enabled
Drupal Console 1.9.4

Solution

The solution is quite simple, we can replace line 105 and 106:

$source_storage->delete($name);
$source_storage->write($name, $value);

with:

$source_storage->replaceData($name, $value);

Looking at the file history it seems that the initial implementation was using this function, so not sure why it was changed. The commit which changes this has as far as I can see no reason to change this line.

I am currently creating a Patch file for our own project so will create a PR later today. (Assuming this is a bug and not intended behaviour).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant