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
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | simplenews-spool-refactor-2410257-8-interdiff.txt | 18.37 KB | berdir |
| #8 | simplenews-spool-refactor-2410257-8.patch | 135.29 KB | berdir |
| #7 | simplenews-spool-refactor-2410257-7-interdiff.txt | 85.76 KB | berdir |
| #7 | simplenews-spool-refactor-2410257-7.patch | 134.17 KB | berdir |
| #6 | simplenews-spool-refactor-2410257-6-interdiff.txt | 2.47 KB | berdir |
Comments
Comment #1
miro_dietikerMajor and release target since key API.
Comment #2
berdirAdding some more explanations, changing to a meta.
Comment #3
berdirNeeded 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
Comment #4
berdirActually 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 ;)
Comment #6
berdirA rename went wrong there.
Comment #7
berdirThis introduces the Mailer and MailBuilder services and removes the remaining functions in mail.inc there. It is gone :)
Comment #8
berdirVarious documentation improvements.
Comment #10
berdirCommitted :)
two major follow-up refactorings planned: subscription management (confirmation stuff) and refactoring source classes: renaming, plugins, services, ...