Problem/Motivation
In Drupal 8.4.x a refined version of Media Entity was added to core. Due to some modifications at the API level, an upgrade path is needed.
Proposed resolution
- Write the upgrade path
- Test exhaustively
- Document steps for upgrading
- Commit
Test case scenarios
https://docs.google.com/spreadsheets/d/1q1BM2KbLwQvEDerSN9oxBz82mIYfSBmG...
Draft for the upgrade instructions
If you are looking for the upgrade instructions, please check #2917099: Document upgrade path to Media in core in the meantime.
| Comment | File | Size | Author |
|---|---|---|---|
| #42 | interdiff-2880334-40-42.txt | 1.42 KB | phenaproxima |
| #42 | 2880334-42.patch | 16.7 KB | phenaproxima |
| #40 | 2880334-40.patch | 15.9 KB | phenaproxima |
| #33 | interdiff-30-33.txt | 355 bytes | marcoscano |
| #33 | 2880334-30.patch | 236.86 KB | marcoscano |
Comments
Comment #2
alisonHi! I can't figure out how to get the 2.x branch via composer :-/ Do I just have to do tarball or git clone for now, or?
Also, is media_entity 8.x-2.x compatible with entity 8.x-1.x?
Thank you!
Comment #3
marcoscanoAs of today, the upgrade path / 2.x branch of Media Entity is not fully implemented or ready for testing. There will probably be a patch on this issue when there is something ready to be tested, using the standard drupal patch workflow.
For now, if you want to build something with Media Entity, it is safe to use the 1.x branch. In Drupal 8.3.x there is no confusion, and if you want to test it with Drupal 8.4.x, you can do it too, but in this case you shouldn't enable the core "Media" module at the same time. Once the upgrade path is ready, you will be able to upgrade Media Entity to the 2.x branch, run the updates, then disable the module and start using the core Media solution.
Keep an eye on this issue, as well as on #2860796: Plan for contributed modules with Media Entity API in core and https://www.drupal.org/node/2825215#followup-roadmap , to have a better picture of the current roadmap.
Comment #4
alisonHi, thanks for the quick reply, @marcoscano! That's really helpful information, thank you for explaining. The only other thing I'd add is, I think the info on the project page gives the wrong idea:
I think even if you copied over what you said in your comment to me here, or change to some variety of "future tense" in the project page info, so it doesn't sound like y'all intend for users to be upgrading to Media 2.x rn, if that makes sense. Something like......
(and then carry on with the "Note that in order to start..." and "If you need to upgrade Drupal core to 8.4.x..." paragraphs.)
Just a suggestion. Thanks again for your quick and informative reply!
Comment #5
marcoscanoYeah, sorry about the confusion... Wording is always hard :)
Media in core in 8.4.x is really not meant to be "end-user-ready". In the roadmap the upgrade path (this issue) is listed as a must-have before shown on the UI, and this milestone is currently targeted for 8.5.x. In other words, there will be an upgrade path before the Media module is shown on the UI in core 8.5.x. So if the project page info gives the impression that "hey users you need to install core 8.4.x + media_entity 2.x right now!" the text is not doing a good job at all... :)
I've tweaked it a little bit to try to make this idea more evident. I hope it is somehow clearer now.
Comment #6
alisonOy vey, so hard! :) Thanks for tweaking, looks good!
Comment #7
marcoscanoI was wanting to start working on this a bit. Can we all agree on the approach and make sure we are not leaving any detail behind?
Scenario:
Site with core 8.3.x and Media Entity 1.x + a bunch of plugins. The steps to upgrade will then be:
media_entitymedia_entitybymediamedia_entity.settingsintomedia.settingsand delete the originalmedia_entity.bundle.*bymedia.type.*(using "file" instead of "document" if it exists)media_entity.bundle.*bymedia.type.*administer media bundles" -> "administer media types")Step 4 is basically what the initial approach is doing, and I think this is where we would benefit mostly from additional eyes.
Questions:
- Would provider plugins possibly need additional update hooks on their own, for some reason?
- Should we try to disable Media Entity (step 5) at the end of the update hook to prevent people missing this step, or will the 2.x branch be an empty module only with the update hook? If it's the latter, wouldn't things break if trying to use the site before performing the updates? (or if the update hook aborts early)
Comment #8
slashrsm commentedGenerally looks OK.
Yes, if they need them they should implement them I guess. We'll have to consider requirements (i.e. in which order hooks execute), but I'd discuss for every specific case separately.
I think that the 2.x will be only update hooks so we could leave it enabled. Maybe display a message in status report that the udpates were run and the module can be disabled?
Comment #9
marcoscanoHere is a first approach to the upgrade patch, based on @chrfritsch's and @phenaproxima's work.
This has not been exhaustively tested. I plan to do more testing in the coming days. However, it would be nice if we could start getting reviews, to spot all possible edge-case scenarios we need to deal with.
The steps to upgrade would then currently be:
media_entitymedia_entitybymediamedia_entity.settingsintomedia.settingsand delete the originalmedia_entity.bundle.*bymedia.type.*(using "file" instead of "document" if it exists)media_entity.bundle.*bymedia.type.*typeandtype_configurationwithsourceandsource_configurationin all of them.administer media bundles" by "administer media types" and revoke instances of the deleted "access media overview"media_entity_imageandmedia_entity_document, if present.Some questions appeared:
1) About the simple config
media.settingsupdate:The previous code was doing:
but I think we can't really do that because the new key for
icon_baseisicon_base_uri. Is it OK if we just update that key value?2)
system_get_info('module', $module_name)appears to return an empty version for -dev modules. Is there a workaround?Comment #11
marcoscanoComment #13
marcoscanoComment #14
marcoscanoThis is the same patch as #9, but here I diff'ed only the
media_entity.installfile, in order to make a patch of a reasonable size.Comment #15
berdirI'm not sure if we really want to go after the version, won't help with custom providers/modules anyway that don't follow the pattern.
Instead, my proposal would be to simply load the media bundle configs and make sure it exists as a plugin using the new media.module plugin manager. If not, then we display an error and abort. Maybe this will result in error messages that are not quite as clear (plugin X is missing instead of module X is not updated) but we're much more flexible.
The current logic would require that even new modules or modules that have no stable version yet have to start with/switch to 8.x-2.x, but there really isn't a reason to do that. A non-stable version can just do a >= 8.4 dependency on media module and do a new release.
and unless I'm missing something, it would also require us to do completely empty document/image module branches, just to have them exist. Although not 100% sure if having the 8.x-1.x ones still around could result in some errors.
we need to open a core issue about this because removing this permission was simply wrong :)
views.view.media.yml in core still uses that permission, no idea why it was removed and why our tests are still working (unless we only test with admin-users, it should not be possible to access that page).
Comment #16
marcoscanoThanks @Berdir for the feedback!
#15.1:
True, comparing versions is definitely not the most robust approach. What if we kept
MediaTypeManageronly for the sake of loading all definitions, and aborting if there is any module implementing a@MediaTypeplugin? We risk being too aggressive and aborting even if the module is enabled but no bundle is effectively created, but in the end, I believe this scenario would still be preferable.#15.2:
Wow, I tried to search in patchzilla (#2831274: Bring Media entity module to core as Media module) where this happened to understand why, but I was unable to figure out when it got removed. Opened #2905213: Bring back "access media overview" permission to discuss that.
Comment #17
marcoscanoSome additional tweaks, still a WIP patch.
It's kind of hard to test and troubleshoot this. Maybe it would be worth preparing a boilerplate packed scenario (code + DB, docker image, or something like this) so people working on this could quickly test and provide feedback?
Anyway, some more things I found:
- We should disregard
media_entity_imageandmedia_entity_documentin the list of incompatible modules, if we don't want to create empty 2.x versions of them, just to bypass validation- It's important to clear caches after the code was updated but before running the DB updates, otherwise our @MediaType plugin validation will incorrectly fail. I assume this could be a problem in automated upgrade scripts or when upgrading with drush?
While testing, I could proceed to the update hook, but while running the batch process it failed with an AJAX error where the validation message was present:
This means that at some point during the update batch the requirements are evaluated again, which is a problem for the current approach. .. we may want to re-think how we enforce the requirements in this case.
And just for the record, here again an updated and simplified list of steps the user would need to perform to follow this upgrade path:
Unfortunately, I won't be able to keep working on this in the near future, so if anyone else wants to pick it up from here, please feel free to do so.
Comment #18
marcoscanoWe may have a bigger problem to solve here: is it true that
drush updbbypasseshook_requirements()?I can't find any call to the requirements enforcing in https://github.com/drush-ops/drush/blob/4ceda41bedfac4936410c9ddd0f9c508..., the same way Drupal core does when running the updates through update.php on the UI.
If that's the case, it will be a problem for people using drush / automated scripts to update their sites. I believe the
hook_requirementsis the most important part of this patch, because there we try to ensure that people won't start the DB changes unless they have an environment that meets all conditions to complete the updates. If we can't find a way to enforce that, we risk updates leaving sites half-broken due to some missing requirements (such as some provider modules not available, etc).Comment #19
Narretz commentedI know this issue is for the "Media Entity" upgrade steps, but I think it can't hurt to point out the relationship to the "Media" module in the upgrade notes (as shown here https://www.drupal.org/node/2880334#comment-12238747)
As far as I know, the "Media" module will be in core, and the contrib module "Media" must be disabled before upgrading to 8.4.
If this is correct, I think this should be in the upgrade notes, or the notes should include a link to the upgrade notes for "Media"
Comment #20
marcoscanoHere is the PR to enforce
hook_requirements()when running updates with drush:https://github.com/drush-ops/drush/pull/2708
Comment #21
marcoscanoNothing like brainstorming in the same room! :)
We found out a way of working around the drush limitation in
drush updb(thanks @phenaproxima!), and this patch accounts for that.We also provide here an additional command to dry-run the requirements and check if your site is OK to upgrade or not.
Comment #22
seanbFixed the following:
Me and marcoscano talked about moving the generic media source to a separate module. This will allow people that use this to also delete the media entity module after the update (if you don't use it that is not necessary of course). We think deleting the module is not only important to write a consistent manual, but it is also an important last step. To create a feel-good moment.
The best way to do this might be to already create the module and force people to update in the 1.x branch. The 2.x branch could then check if the 1.x branch was on the right version before proceeding.
Comment #23
seanbComment #24
marcoscano@seanB++
This is looking good.
I believe now is the moment to start some exhaustive testing, so I have started to define some test cases:
https://docs.google.com/spreadsheets/d/1q1BM2KbLwQvEDerSN9oxBz82mIYfSBmG...
to help us make sure we don't leave any important one behind.
Also updated the IS that needed some love.
Comment #25
marcoscanoAdded a draft for upgrade instructions to the IS.
Comment #26
seanbWe have discussed moving the generic media source to a separate module. This way the upgrade path becomes a little more consistent. Everybody can delete media_entity contrib after the upgrade.
TODO: We should create a separate module and make sure the requirement hooks check this when someone is using the generic source.
Marking needs work for this.
Comment #27
phenaproximaHere's a version of the patch without the Generic source, and a separate module containing it.
Still needs work to adjust hook_requirements() accordingly; not sure exactly how to approach that, though.
Comment #28
phenaproximaAdded the hook_requirements() check.
Comment #29
seanbLooking good, think there are a couple of things that still need work:
- Create the media_entity_generic module
- I think we should also make sure the update hook installs the media_entity_generic module if needed
- Update the drush command media-entity-check-upgrade to also check if media_entity_generic is needed/available
The check should be in a separate function so we don't have to duplicate the code for requirement/drush/update.
Comment #30
phenaproximaOkay, made the requested changes
except for creating the media_entity_generic module. :)Comment #31
seanbThis might need to be done earlier in the update process to make sure the config can be updated, but I will do some manual testing to check this out.
Comment #32
seanbComment #33
marcoscanoI briefly tested the latest patch this morning, here what I did:
- Site with Media Entity 1.x + Generic, Image and Twitter. One media type of each created.
- Applied the patch, downloaded
media_entity_genericand twitter 2.x- Ran
drush mecuto check the requirements.* Result: ERROR: site cannot be upgraded
- Ran
drush cr, and thendrush mecuagain* Result: OK: site can be upgraded
- Ran
drush updb* Results:
I can't troubleshoot right now, but wanted to post the result anyways. If I can find more time this weekend I'll resume testing.
Note: I'm uploading a small change on the patch because apparently drush includes .module files of enabled modules, so deleting it completely produces some unwanted warnings. Keeping an empty file solves the problem.
Comment #34
chr.fritschTalked with phenaproxima and we concluded that we need some kind of automated tests for this.
We decided to implement and UpdatePath test and provide a dump containing:
If this is done, we can provide other dumps, to test more sophisticated use-cases.
@phenaproxima will start to work on this.
Comment #35
phenaproximaI have a basic test of the update path working perfectly in my local environment.
However, I would like this patchzilla to land in the 8.x-2.x branch before proceeding, since we know from personal experience that patchzillas are a Very Bad Time.
Comment #37
phenaproximaIn discussion with @chr.fritsch, we agreed to commit the patchzilla in #33 in the name of cleanup (and sanity), and continue working on the update path here.
Comment #38
phenaproximaBlocking on #2915251: Create database fixture for testing the update path, which is necessary for us to write automated update path tests.
Comment #39
phenaproxima#2915251: Create database fixture for testing the update path is in, so this is no longer blocked.
Comment #40
phenaproximaHere we go: a passing, basic update path test!
Let's add more!
Comment #42
phenaproximaAdded asserts of media linked from the front page view.
This will fail too, since it only applies against the 8.x-2.x branch, which is hidden for the time being.
Comment #44
phenaproximaAfter discussion in IRC, we agreed to commit this basic update path test, and add more tests and scenarios in follow-up issues.
Great start!
Comment #45
marcoscanoCreated follow-up: #2915738: Increase reliability of upgrade path to Media in core
Comment #46
marcoscanoRemoved the obsolete upgrade instructions from the IS, pointing interested people to #2917099: Document upgrade path to Media in core instead.