Problem/Motivation

In Drupal 9 after applying the patch from #3042715: Drupal 9 Deprecated Code Report and running updates I got this error:

Error: Call to undefined method Drupal\Core\Entity\EntityDefinitionUpdateManager::applyUpdates() in votingapi_update_8301() (line 29 of /var/www/modules/contrib/votingapi/votingapi.install)
* @deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0. Use
*    \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface::getChangeList()
*    and execute each entity type and field storage update manually instead.

See Support for automatic entity updates has been removed.

Comments

Krzysztof Domański created an issue. See original summary.

tr’s picture

The D8 update hooks should probably be removed in D9, as they are only used when updating from 8.x-3.x to a newer version of 8.x-3.x.

pifagor’s picture

Status: Active » Needs work
tr’s picture

Status: Needs work » Needs review
StatusFileSize
new2.23 KB

Here is a patch for properly removing the old update hooks:

  • votingapi_update_8301() first included with Voting API 8.x-3.0-alpha5 on 2 March 2018
  • votingapi_update_8302() first included with Voting API 8.x-3.0-beta1 on 28 October 2018

The patch also adds a hook_update_last_removed() so that these removed hooks don't get skipped (if needed) during an update.

The argument for doing this can be found in the core queue: #3087644: Remove Drupal 8 updates up to and including 88**. I won't repeat that here. But let me make a few points about the Voting API module that I think are relevant:

First point to note is that anyone who has installed a fresh version of Voting API since 28 October 2018 doesn't need these update hooks - they will never be run.

Second, anyone who has upgraded to beta1 at any point in time (including the future) doesn't need these update hooks - they will have already been run.

Third, as of 24 March 2020 there are 11,283 sites using the Drupal 8 version of Voting API (see https://www.drupal.org/project/usage/votingapi)
But of these, a full 9,826 are using beta1. That's more than 87% of the total which have no need for these update functions. (The remaining 12% are sites that haven't been updated in close to two years now.)

Fourth, the proper way to upgrade is to first update all your modules to their most recent version THEN perform the major version upgrade of core. If you are trying to update your module from a very old version, you MAY have to do this in steps rather than jump all the way in one update. This is the documented process. This process will still work with the removed update hooks. This patch does not prevent sites that have Voting API < beta1 from updating, it just warns them that they skipped a step. If they update to beta1 first, then they can upgrade to Drupal 9 - assuming this patch is committed.

Finally, the whole purpose of hook_update_last_removed() is for exactly this situation - where we have update hooks that no longer run in the new major version because of API changes. This is why core Drupal removed all its old update hooks for D9.0 - most of those old hooks won't run anymore. Having a hook_update_last_removed() still allows an upgrade from the previous major version - the updates must be performed first, then the new major version of core installed. There is no danger than an important step will be skipped - that's what hook_update_last_removed() is there for.

tr’s picture

Marked #3150212: votingapi_update_8303() fails with MySql 8 as a duplicate.

EDIT: Actually, that's not a duplicate, as explained in #3150212-4: votingapi_update_8303() fails with MySql 8.

tr’s picture

StatusFileSize
new3.12 KB
new1.12 KB

Minor re-roll of #4 to correct coding standards.

  • TR committed 5d769c5 on 8.x-3.x
    Issue #3143266 by TR: Error: Call to undefined method Drupal\Core\Entity...
tr’s picture

Status: Needs review » Fixed

Committed #5.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.