You are here

class EntityReferenceRevisionsCommands in Entity Reference Revisions 8

A Drush commandfile.

Hierarchy

Expanded class hierarchy of EntityReferenceRevisionsCommands

1 string reference to 'EntityReferenceRevisionsCommands'
drush.services.yml in ./drush.services.yml
drush.services.yml
1 service uses EntityReferenceRevisionsCommands
entity_reference_revisions.commands in ./drush.services.yml
\Drupal\entity_reference_revisions\Commands\EntityReferenceRevisionsCommands

File

src/Commands/EntityReferenceRevisionsCommands.php, line 13

Namespace

Drupal\entity_reference_revisions\Commands
View source
class EntityReferenceRevisionsCommands extends DrushCommands {

  /**
   * The purger service.
   *
   * @var \Drupal\entity_reference_revisions\EntityReferenceRevisionsOrphanPurger
   */
  protected $purger;

  /**
   * Constructs a ERRCommands object.
   *
   * @param \Drupal\entity_reference_revisions\EntityReferenceRevisionsOrphanPurger $purger
   */
  public function __construct(EntityReferenceRevisionsOrphanPurger $purger) {
    $this->purger = $purger;
  }

  /**
   * Orphan composite revision deletion.
   *
   * @param $types
   *   A comma delimited list of entity types to check for orphans. Omit to
   *   choose from a list.
   * @usage drush err:purge paragraph
   *   Purge orphaned paragraphs.
   *
   * @command err:purge
   * @aliases errp
   */
  public function purge($types) {
    $this->purger
      ->setBatch(StringUtils::csvToArray($types));
    drush_backend_batch_process();
  }

  /**
   * @hook interact err:purge
   */
  public function interact($input, $output) {
    if (empty($input
      ->getArgument('types'))) {
      $choices = [];
      foreach ($this->purger
        ->getCompositeEntityTypes() as $entity_type) {
        $choices[(string) $entity_type
          ->id()] = (string) $entity_type
          ->getLabel();
      }
      $selected = $this
        ->io()
        ->choice(dt("Choose the entity type to clear"), $choices);
      $input
        ->setArgument('types', $selected);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityReferenceRevisionsCommands::$purger protected property The purger service.
EntityReferenceRevisionsCommands::interact public function @hook interact err:purge
EntityReferenceRevisionsCommands::purge public function Orphan composite revision deletion.
EntityReferenceRevisionsCommands::__construct public function Constructs a ERRCommands object.