Add a "Centarro Toolbox" menu item beneath "Configuration" in the Commerce menu with a single child item called "Orphaned entities". We have multiple entity types (product variations, order items, etc.) that are meant to be tightly coupled to a parent but through site error can become orphaned.
An "orphaned" entity is one that identifies a parent entity (i.e. $product_variation->product_id) that does not reference the child entity in return. The "Orphaned entities" page should be a form with a fieldset for each entity type, "Product variations", "Order items", etc. The description of the fieldset should be a count of how many such orphaned entities exist in the site:
"Your site has 0 orphaned product variations."
"Your site has 12 orphaned order items."
Each fieldset should then include a submit button that reads,
"Delete orphaned product variations"
"Delete orphaned order items"
It should be disabled if there are 0 orphaned entities. When submitted, those entities should be deleted and a status message shown:
"12 orphaned order items deleted."
That same message should be logged to the watchdog.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | interdiff_2_4.patch | 1.09 KB | khiminrm |
| #4 | centarro_toolbox-orphaned-entities-form-3197747-4.patch | 12.7 KB | khiminrm |
| #2 | centarro_toolbox-orphaned-entities-form-3197747-2.patch | 12.33 KB | khiminrm |
Issue fork centarro_toolbox-3197747
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
Comment #2
khiminrm commentedComment #3
khiminrm commentedComment #4
khiminrm commentedAdded support of commerce_shipment entities. Working on adding conditions to check if modules providing entity types are enabled - maybe will add it in
CommerceOrphanedEntitiesServiceand will return array of available entity types for the form.Comment #5
jsacksick commentedLet's skip the additional service for now and add a helper method in the form class itself.
Additionally, there's probably a way to build the query automatically with variables that works for all our entity types.
See
SqlContentEntityStorage::buildQuery().For example, you can get the base table from the storage by doing:
Also, as a side note, it'd be interesting to see if we can load entities by group of 50 at once (for better performance), instead of loading them one by one.