Problem/Motivation

Once upon a time, update.fetch.inc included all the code that runs while fetching new available update data and related support methods. Over time, folks have OO-ified this into src/UpdateFetcher.php, src/UpdateProcessor.php and others. The once huge update.fetch.inc now contains a single, lonely function, _update_cron_notify().

Proposed resolution

Remaining tasks

  1. Implement the proposed resolution.
  2. Reviews.
  3. RTBC.
  4. Commit.

User interface changes

N/A

API changes

TBD. Nothing public, since _update_cron_notify() is prefixed with an underscore and therefore officially considered internal.

Data model changes

N/A

Release notes snippet

TBD, probably none.

Issue fork drupal-3125013

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dww created an issue. See original summary.

abhijeet.kumar2107’s picture

Assigned: Unassigned » abhijeet.kumar2107
abhijeet.kumar2107’s picture

Assigned: abhijeet.kumar2107 » Unassigned

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

znerol made their first commit to this issue’s fork.

znerol’s picture

Issue summary: View changes
Priority: Minor » Normal
Status: Active » Needs review
znerol’s picture

needs-review-queue-bot’s picture

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

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

znerol’s picture

Status: Needs work » Needs review

Fixed a misnamed variable. The approach in #3539178: Extract _user_mail_notify() into a user NotificationHandler changed a little bit (internal service, no interface). Let's see how that goes over there and adapt here if necessary.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs change record

Can we get a change record for the new interface?

anmolgoyal74’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record

I have added the change record. Probably It would need more updates. Please review.

smustgrave’s picture

Status: Needs review » Needs work

Looking at the MR vs the CR think we need to deprecate _update_cron_notify before we can remove it.

dww’s picture

I’m not so sure. It’s a function that starts with _ which means it’s explicitly not API. No one should be calling this manually. If they are, they’re “doing it wrong” and if their code breaks when we remove it, it’s on them for calling an internal, non-API function.

dww’s picture

That said, I think the CR isn’t documenting what anyone might care to know. It should be discussing the addition of core/modules/update/src/MailHandlerInterface.php not talking about “deprecation” since yeah, we’re not deprecating anything, we’re refactoring internal code.

znerol’s picture

Similar discussion over in #3539178: Extract _user_mail_notify() into a user NotificationHandler . I do not have much of an opinion, but we should do it consistently here and in the user module.

Also in the other issue we went without an interface.

smustgrave’s picture

Issue tags: +Needs title update

Just in case we don’t end up needing deprecation may want to update the title too

dww’s picture

Yeah, if we need no interface, happy to not need a CR here at all. Agree we should be consistent.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

berdir’s picture

We've made exceptions on the underscore-prefixed rule before, when it's not too much trouble and used in contrib. we did that with _field_multiple_value_form_sort_helper() and I think it makes sense for _user_mail_notify() because there are dozens of usages of that in contrib, with that one there's some disagreement on how far that BC logic should go though. That one probably should always have been an API, it is a pretty common thing that other modules need to do as proven by the usages.

That said, this one seems pretty much unused, all I could find is a bunch of copy-pasted and bogus @see references from copied hook_mail() implementations: https://git.drupalcode.org/search?group_id=2&scope=blobs&search=_update_...

IMHO we don't need to be consistent but can decide on a case-by-case basis for these functions.

If it were doing anything else but sending mails, I'd suggest to just inline it into the hooks class, that's what we did in other cases too. We can keep the old code as-is and deprecate it without attempting to call the new code. However, the semi-secret reason that znerol is doing that MailHandler service here is that this helps with the completely separate effort to replace hook_mail with the new symfony mailer API, the idea there is that the experimental module would, if enabled, replace/subclass all those services to use the new API until it's no longer experimental. But that won't work in all cases anyway, so I'm undecided myself and can live with either the service or inlined in the hooks class. Either way, +1 on no interface.

znerol’s picture

Title: Deprecate _update_cron_notify() and remove update.fetch.inc » Refactor update.fetch.inc into a MailHandler
Status: Needs work » Needs review
Issue tags: -Needs title update

Applied the same approach as in #3539178-22: Extract _user_mail_notify() into a user NotificationHandler to get rid of the interface and still permit a subclass with a completely different kind of mail manager.

It is possible to mark methods for setter injection with the #[Required] attribute. That way, a subclass doesn't need to receive and pass on a MailManager via its constructor. It only needs to declare the services which it really needs.

znerol’s picture

Updated the CR.

znerol’s picture

Should we mark Drupal\update\MailHandler as @internal.

nod_’s picture

Updated search link for #25: _update_cron_notify seems like it's not used anywhere

znerol’s picture

nicxvan’s picture

nicxvan’s picture

There are a couple of contrib modules including the file though which is weird because they don't use the function.

https://git.drupalcode.org/project/dash/-/blob/6fc17292c04d903f1285db629...

That whole method is... interesting to say the least.

I think this means we should deprecate the file, although in one of the locale issue alexpott said we should explicitly not deprecate the file and just delete the file when ready, the immediate white screen is a better signal.

So in not sure we change anything now that I think further.

znerol’s picture

include() doesn't fatal when a file is missing. require() does.

nicxvan’s picture

That's right, so nothing to change, I'll review it again when I have a moment.

dww’s picture

nicxvan’s picture

Status: Needs review » Reviewed & tested by the community

I took a careful look at this. All of the code that was moved has been faithfully moved.

The actual send code has been moved with the reasons stated in 25.

This may get kicked back for consistency and require deprecation. But as noted, it is not used anywhere, and there is only the one function in that file so I think we can make the exception and clean up the whole include.

I reviewed the IS and the CR.

The CR is a bit sparse, but I question if we need it since we're not even deprecating it.

dww’s picture

Status: Reviewed & tested by the community » Needs work

Resolved 1 thread. Opened a few others. Mostly nits, and possible scope creep that should be follow-ups.

But NW since there's an {@inheritdoc} on a method with no parent docs to inherit. At least that one should be fixed before RTBC. The others I'm open to moving to follow-ups (or fixing here).

Thanks!
-Derek

znerol’s picture

Status: Needs work » Needs review
dww’s picture

Indeed, that was my concern. But I'm prepared to let it go for now. The method is in fact protected. So if we made it public in the future, we can revisit.

Thanks for the fixes! Almost there. 😅 2 more minor suggestions, then this is RTBC to my eyes.

Thanks again!
-Derek

dww’s picture

Status: Needs review » Reviewed & tested by the community

I think I've squeezed every improvement out of this I can ethically request. 😂 This seems great. We can definitely handle any other potential improvements in follow-ups.

Title and summary are still accurate.

I'm not sure we need/want the CR, but the draft is there.

First pass at saving credit: @znerol for the code, myself and @nicxvan for reviews. The other contributions here don't seem significant enough for credit. But happy to be wrong if the committer feels otherwise.

Thanks!
-Derek

godotislate’s picture

Status: Reviewed & tested by the community » Needs work

Performance test needs tweaking.

Asset Aggregation Across Pages (Drupal\Tests\demo_umami\FunctionalJavascript\AssetAggregationAcrossPages)
     ✘ Assets across multiple pages
       ┐
       ├ Failed asserting that two arrays are identical.
       ┊ ---·Expected
       ┊ +++·Actual
       ┊ @@ @@
       ┊  Array &0 [
       ┊      'ScriptCount' => 15,
       ┊ -····'StylesheetCount'·=>·8,
       ┊ +····'StylesheetCount'·=>·7,
       ┊  ]
       │
       │ /builds/core/tests/Drupal/Tests/PerformanceTestTrait.php:692
       │ /builds/core/profiles/demo_umami/tests/src/FunctionalJavascript/AssetAggregationAcrossPagesTest.php:116
       │ /builds/core/profiles/demo_umami/tests/src/FunctionalJavascript/AssetAggregationAcrossPagesTest.php:30
       ┴
    
    FAILURES!
    Tests: 1, Assertions: 43, Failures: 1.

Also a question on the MR.

berdir’s picture

I don't see why this would affect asset aggregation, maybe a random fail? Agree on the lazy services, most cron executions won't need them.

godotislate’s picture

I don't see why this would affect asset aggregation, maybe a random fail?

Re-running again now, but I think it's failed at least twice.

berdir’s picture

It did fail again yes, but this was a few commits behind and I think it just managed to hit the HEAD fail introduced by #3502993: Convert Navigation messages component to SDC, there was a follow-up commit to that that fixed that test. I rebased it through the UI to confirm.

znerol’s picture

Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Reviewed & tested by the community

Feedback has been addressed.

  • godotislate committed 4081563a on main
    refactor: #3125013 Refactor update.fetch.inc into a MailHandler
    
    By: dww...

  • godotislate committed df228407 on 11.x
    refactor: #3125013 Refactor update.fetch.inc into a MailHandler
    
    By: dww...
godotislate’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Consulted with @quietone and @catch about the how the service closure properties were documented, such as

    /**
     * @var \Closure(): \Drupal\update\MailHandler
     */

Decision was that this is fine, though we may open a coding standards issue if there's a way we want to standardize going forward.

Committed and pushed to 4081563 main and df22840 to 11.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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