Problem/Motivation

simplenews.mail.inc contains a large list of functions related to building newsletters, managing the spool, and so on. We have a dozen or so includes to then be able to call those functions.

This is not the D8 way.

Proposed resolution

Group those functions into meaningful topics/groups, and convert them to services or utulity classes.

Example based on spool:
- Identify all functions that are doing something related to spool (count_spool, get_spool, ...)
- Move them into a new class, Drupal\simplenews\MailSpool
- Rename them to methods, this is probably the hardest part. They all have very inconsistent documentation and terminology. First we need to define what we call the things inside the mail spool. If you look at the documentation, we use data, records, elements, items, .. We need to discuss this. Then, simplenews_count_spool() would for example become countItems().
- Define this as a service in services.yml, inject things like the database connection and lock, name for the service: simplenews.spool?
- Update calls to the old functions with \Drupal::service('simplenews.spool')->countItems() etc.
- Extract an interface, move documentation of methods there, clean up naming and formatting

This is a big task, but I'd love to get started here.

@todo: Identify more groups/services.

Remaining tasks

@todo complete problem description and solution.

User interface changes

API changes

Comments

miro_dietiker’s picture

Priority: Normal » Major
Issue tags: +8.x release target

Major and release target since key API.

berdir’s picture

Title: todo.txt: simplenews.mail.inc: convert to services » [meta] simplenews.mail.inc: convert to services
Issue summary: View changes
Parent issue: #2410255: todo.txt: simplenews_get_source_caches: convert to plugin »

Adding some more explanations, changing to a meta.

berdir’s picture

Status: Active » Needs review
StatusFileSize
new57.02 KB

Needed to do some stuff.

Lots of things to clean up, primary change is converting the spool methods to a service, but there are also lots of related services as I'm trying to figure out what to do and move where.. Not yet sure about the remaining pieces, thinking about a Mailer component, that does the mail building and so on, but the source already does a lot of that.. and has a weird name for that.

Also not sure what to name the things inside the spool. Currently used messages, but maybe Mails would be better. Then we could rename Source to Mail, and it would start to match together..

Also not sure yet how to make the source/mail stuff pluggable exactly... still lots of weird things.

Not ending up with a 200kb patch here is going to be hard :p

berdir’s picture

Actually had the Mail idea while writing the comment, I think I like that. Also renamed Spool to SpoolList (or MailList?) and returning that from getMails(), moved the constants..

So much to rename ;)

Status: Needs review » Needs work

The last submitted patch, 4: simplenews-spool-refactor-2410257-4.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new65.79 KB
new2.47 KB

A rename went wrong there.

berdir’s picture

This introduces the Mailer and MailBuilder services and removes the remaining functions in mail.inc there. It is gone :)

berdir’s picture

Various documentation improvements.

  • Berdir committed b80b1d4 on 8.x-1.x
    Issue #2410257 by Berdir: Replaced simplenews.mail.inc with spool...
berdir’s picture

Title: [meta] simplenews.mail.inc: convert to services » Replace simplenews.mail.inc with spool storage and mailer services
Status: Needs review » Fixed

36 files changed, 1585 insertions(+), 1292 deletions(-)

Committed :)

two major follow-up refactorings planned: subscription management (confirmation stuff) and refactoring source classes: renaming, plugins, services, ...

Status: Fixed » Closed (fixed)

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