Problem/Motivation
We should not have functions that query the subscription table, as this is considered an implementation detail of the storage.
Proposed resolution
Add a custom SubscriptionStorage + Interface, that subsclasses \Drupal\Core\Entity\Sql\SqlContentEntityStorage, specify that as storage handler in Subscriber.
Move the function to a method there, and call it like this \Drupal::entityManager()->getStorage('simplenews_subscriber')->deleteSubscriptions().
See UserStorage::deleteRoleReferences() and #2390467: User role permission assignments are not deleted when a role is deleted as reference.
A quick grep shows that simplenews_count_subscriptions() is similar, but we can probably do that using an entity aggregate query in a storage agnostic way, which is even better.
Remaining tasks
@todo complete problem description and solution.
Comments
Comment #1
berdirDone.
Comment #2
berdirComment #3
johnchqueI have created the SubscriptionStorage file and its Interface to for deleting subscriptions, seems it works. I attach the patch.
Comment #4
johnchqueComment #5
berdirThanks, review below.
entityManager() is deprecated, use entityTypeManager() instead.
looks like an accidental paste.
Check other files for the correct dochblok here, @files and then Contains \...
Also add a class docblock and an @inheritdoc (again,see others) to the method.
I think we can remove the @todo here then.
Use the injected database service, $this->database->delete()
You are the storage. so just $this->resetCache()
space between interface line and docblock.
DeleteS
I think the ; delete part isn't necessary.
Comment #6
johnchqueChanges made, extra code deleted.
Comment #7
johnchqueComment #8
berdirYou didn't properly rebase/merge and are reverting a change that I just committed.
Comment #10
berdiryou're missing the tablename now.
Comment #11
johnchqueMerged properly and added tablename. Attached new patch.
Comment #12
berdirNote: When addressing a review from someone, always provide an interdiff: https://www.drupal.org/documentation/git/interdiff
Then I don't have to re-read the whole patch, just the lines that changed.
Too many newlines.
Indentation here and in the interface is off. Two spaces, not for. Make sure that PHPStorm is configured correctly.
Instead of hardcoding the table name, we should use the API. $this->getTableMapping()->getTableName('subscriptions') should give you that.
Missing . at the end.
Still missing an empty line here, and should be Deletes, with S. method descriptions are always third-person.
Comment #13
johnchqueNew patch added fixing indentation. Interdiff added.
Comment #15
johnchqueSorry, wrong method used.
Comment #17
johnchqueAdded new patch based on the comment #12, still hardcoding the table name to simplify the code. Added interdiff based on comment #12.
Comment #19
berdirThank you, committed.