Convert update_calculate_project_update_status() into a class

Created on 10 December 2019, about 5 years ago
Updated 13 May 2024, 7 months ago

Problem/Motivation

core/modules/update/update.compare.inc contains 1 method, update_process_project_info() that is called from outside of the file.

update_calculate_project_update_status() is almost 300 lines long and its docblock is over 60 lines. It very hard to follow what this function is doing.

Now that we did #3094304: Create tests that cover contrib non-full releases and contrib patch versions β†’ we have much better test coverage for this functionality

In #3100115: The update module should recommend updates based on supported_branches rather than major versions majors β†’ we will be changing much of the logic of update_calculate_project_update_status(). If this isn't in a class then we either have to add to the existing method or add more global functions. If we move to the class within #3100115 then reviewing the changes becomes much hard because the diff of the refactor for the new logic around support branches would not be clear.

Automatic Updates will also additional information from the Update XML that would easier to get if this function was already refactored. See #3252187: [Meta] Deal with core Update module recommending the latest release in the major version not the latest in the Minor version β†’ and #3254207: Only allow 1 patch release update increment in Cron β†’

Proposed resolution

Instead of just creating 1 new class that encapsulates all update_calculate_project_update_status() we should take all the logic possible out of this method that doesn't deal directly with assigning values to the specific elements of the $project_data array and move this new ProjectStatusCalculator class.

ProjectStatusCalculator would have these public methods

  1. getLatestDev() currently set as <code>$project_data['latest_dev'] if this is either the latest development release of the target major or the latest release, which ever is more recent
  2. getRecommendReleaseForTargetMajor currently set as $project_data['recommended'] the recommended version for the target major. This may be the current version is there is not recommended update
  3. getLatestReleaseForTargetMajor() currently set as $project_data['latest_version']
  4. getReleasesInMajorsGreaterThanTarget(better name?) currently set as $project_data['also'] now. This is the latest version for each target major greater than the current target major
  5. getSecurityReleases() set as currently set as $project_data['security updates']
  6. getStatus(). This does not directly correlate to what is stored in
    $project_data<code>....  
    
    Because for instance 
    <code>$project_data['status'] = UpdateManagerInterface::NOT_SUPPORTED

    appears multiple times. Once it is stores project_status from the XML, another time it is because the installed version is not in a supported branch and another time it is because installed version is marked unsupported.

    for more details see #33

    So this will return the status based on what the currently has installed. Not on the status of the Update XML.

  7. getInstallType() a wrapper around $project_data['install_type']

All of these public methods will not return any versions that should never be installed as defined by being, insecure, unpublished, revoked, unsupported or or an unsupported branch. They all rely on private method getInstallableReleases() to ensure that they don't consider uninstallable versions. In the future we could make this public so that we could #3252190: Store all installable releases in update_calculate_project_update_status() β†’ which allow Automatic Updates to select recommendations use different criteria while not having to worry figuring out which versions should never be recommended.

Nothing in ProjectStatusCalculator should be considered an API except the public methods therefore it should be final and all non-pubic internals should be private.

Remaining tasks

Review

User interface changes

None

API changes

Introduces ProjectStatusCalculator class we should consider if this should be @internal or now.

Data model changes

None

Release notes snippet

Note needed

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
UpdateΒ  β†’

Last updated 2 days ago

  • Maintained by
  • πŸ‡ΊπŸ‡ΈUnited States @tedbow
  • πŸ‡ΊπŸ‡ΈUnited States @dww
Created by

πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

Live updates comments and jobs are added and updated live.
  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024