Problem/Motivation

#3016388: Manual cleanup process for obsolete composite entities provides a way to remove obsolete composite entities in a batch process through the user interface. It would be nice to have an option to trigger such operation via Drush.

Proposed resolution

Implement a Drush command to remove obsolete composite entities in a batch process.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

mbovan created an issue. See original summary.

mbovan’s picture

Status: Active » Postponed
berdir’s picture

Status: Postponed » Active
moshe weitzman’s picture

Assigned: Unassigned » moshe weitzman
Status: Active » Needs review
StatusFileSize
new6.44 KB

Quite easy now that the service is there. Thanks for that.

richardbporter’s picture

The patch in #4 worked well for us.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/composer.json
    @@ -0,0 +1,12 @@
    +{
    +    "name": "drupal/entity_reference_revisions",
    +    "description": "Adds a Entity Reference field type with revision support.",
    +    "type": "drupal-module",
    +    "extra": {
    +        "drush": {
    +            "services": {
    +                "drush.services.yml": "^9 || ^10"
    +            }
    +        }
    +    }
    

    I suppose the addition of the composer.json file somehow breaks dev dependencies, even though they seem to be still added?

    Lets add diff as a require-dev dependency and remove the test_dependencies key in .info.yml to see if that helps.

  2. +++ b/src/EntityReferenceRevisionsOrphanPurger.php
    @@ -138,10 +138,10 @@ class EntityReferenceRevisionsOrphanPurger {
        *   The entity type id, for example 'paragraph'.
    -   * @param array $context
    +   * @param $context
        *   The context array.
        */
    -  public function deleteOrphansBatchOperation($entity_type_id, array &$context) {
    +  public function deleteOrphansBatchOperation($entity_type_id, &$context) {
         $composite_type = $this->entityTypeManager->getDefinition($entity_type_id);
    

    why this change? Seems to be causing coding standard errors.

moshe weitzman’s picture

You can omit the composer.json and doxygen change if you want. You do have to
Remove the array type hint since drush passes an iterable object and not an array during batch processing.

berdir’s picture

Hm, that seems a bit unfortunate change in drush if it's not compatible then with core batch handling :)

anyway, we can remove the type hint, but we need to have a type or multiple types in the @param docs, otherwise phpcs complains.

moshe weitzman’s picture

Drush has passed an Iterable for years. It didn't matter back then since nobody used type hints! A module can type hint on Iterable if it only supports PHP 7.1+. See https://steemit.com/php/@crell/php-never-type-hint-on-arrays. And yes, the whole situation is slightly unfortunate.

As for the Doxygen, it would be valid to use Iterable|array or just Iterable

chr.fritsch’s picture

Status: Needs work » Needs review
StatusFileSize
new5.85 KB

Removed the composer.json changes and changed the doc comment.

manu manu’s picture

Works well for me, thanks !
RTBC +1

  • Berdir committed bcc55ad on 8.x-1.x authored by chr.fritsch
    Issue #3081700 by moshe weitzman, chr.fritsch: Implement a Drush command...
berdir’s picture

Status: Needs review » Fixed

Thanks, committed.

Status: Fixed » Closed (fixed)

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