Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
We need a way to add steps to configuration synchronisation. We have two use cases:
- Add a step to delete fields before uninstalling modules #2198429: Make deleted fields work with config synch
- Add a step to synchronise language overrides #2224887: Language configuration overrides should have their own storage
Proposed resolution
- Move the operations code from BatchConfigImporter to ConfigImporter
- Use operation list in ConfigImporter
- Add ability to alter the operation list
Remaining tasks
- Agree approach
- Write patch
User interface changes
None
API changes
Maybe none
Comment | File | Size | Author |
---|---|---|---|
#16 | 2238069.16.patch | 23.89 KB | alexpott |
#16 | 11-16-interdiff.txt | 5.42 KB | alexpott |
#12 | 2238069.11.patch | 25.5 KB | alexpott |
#12 | 5-11-interdiff.txt | 5.89 KB | alexpott |
#5 | 2238069.5.patch | 23.27 KB | alexpott |
Comments
Comment #1
Gábor HojtsyLooking at this one now.
Comment #2
Gábor HojtsyIn fact alexpott is working on this.
Comment #3
alexpottThe patch attached completely removes the BatchConfigImporter since once we start adding steps to the synchronisation process having a batch and non batch version.
All steps have to use the batch context array but ConfigImporter::import() still allows for a non batch implementation.
Comment #4
Gábor HojtsyOnly relatively minor things, so leaving as needs review.
So in my local version of this, I made it a callable all the time for simplicity. So config importer would just return callables also in its operations generator.
operations? there may be multiple
It may or may not be a batch :) It is a semi-batch... Would not be correct to say it is a batch AFAIS.
*Operations* not step.
Comment #5
alexpottChanged the use of
operations
/operation
tosync_steps
/sync_step
. This is because$op
is used in theConfigImporter
to mean the operation that is currently being performed eg createfield.field.some_id
.Comment #6
alexpottI looked a making the method calls on the ConfigImporter use the callable syntax as well... ie.
$sync_steps[] = array($this, 'processConfigurations');
this didn't work because theConfigImporter $this
gets out of sync.Comment #7
Gábor HojtsyIs that $this lost due to batching? How is that not the same problem for anybody altering the steps then? Not the same problem there?
Comment #8
alexpott@Gabor anybody adding new steps and using an object would have to use a public static method.
Comment #9
Gábor HojtsyDo we expect/advise people to use global functions then? Which sounds like the only remaining use case for callables then no? Looks like we should remove support for that then to direct people to the right thing and avoid them doing callables with instances of objects.
Comment #10
tim.plunketttypehint
The exception message shouldn't end in punctuation. Also, this assumes that $sync_step is a string, when it could be a malformed callable (or anything, really)
Here (and elsewhere), full class name please
These hooks need *.api.php entries.
Also, I checked install_tasks (which this is similar to), and it includes an alter. I think allowing an alter of the merged list would be a good idea.
I think we've tried to avoid/remove these, and return empty arrays. Accidentally foreach-ing over FALSE is never fun
These renames are fine, but seem rather superfluous.
Addressing #9,
array('Classname', 'static_method')
andsome_global_function
would both be fine. We could try protecting against instance methods...if (is_array($step) && is_object($step[0])) { throw new \Exception(); }
or something...
Comment #11
Gábor Hojtsy@timplunkett: re 4, the idea was not to allow removal of the crucial built-in steps which is why the pre/post steps hooks were added. Otherwise the full alter hook could be the only one and we would be done :)
Comment #12
alexpottThanks @timplunkett
Comment #13
Gábor HojtsyAll right, changes look good to me. Not entirely happy with now having 3 new hooks for this (we could just have one alter that would do the same thing?). But I don't feel strong about it. I do see the usecase of having the pre/post hooks which are safe and the alter hook which can then alter everything and knows all the *added* items are in, so we have different hooks for adding and then for possibly doing dangerous things. I don't feel strong either way.
Comment #14
Gábor HojtsyResolved issues raised by @timplunkett. I think we can refine this in the future as needed, but is a great first step.
Comment #15
Gábor HojtsyAdded a draft change notice at https://drupal.org/node/2239929
Comment #16
alexpottI think only the alter is necessary. If people break their site through improper API usage so be it.
Comment #17
Gábor HojtsyUpdates look good and reflect my preference from #13. I rewrote the change notice based on the changes :)
Comment #18
sunHm. We're performing all of the entity CRUD operations for all config of a single "step" ("operation"?) in one go...?
What if the import involves to install 50 modules? (plus configuration?)
s/s/z/ - American English
Comment #19
alexpottComment #21
webchickCool beans.
The only thing I found a bit weird was that the example code referenced procedural functions vs. more "Drupal Eight-y" OO code. But Alex explained that the whole Batch API atm is highly procedural-focused and we've never gotten around to modernizing the code. There's some issue for this but I can't find it right now.
Otherwise, the code is nice and easy to read and well-tested. Committed and pushed to 8.x. Thanks!