You are here

class CliService in CMS Content Sync 2.0.x

Same name in this branch
  1. 2.0.x src/Cli/CliService.php \Drupal\cms_content_sync\Cli\CliService
  2. 2.0.x modules/cms_content_sync_developer/src/Cli/CliService.php \Drupal\cms_content_sync_developer\Cli\CliService
Same name and namespace in other branches
  1. 8 modules/cms_content_sync_developer/src/Cli/CliService.php \Drupal\cms_content_sync_developer\Cli\CliService
  2. 2.1.x modules/cms_content_sync_developer/src/Cli/CliService.php \Drupal\cms_content_sync_developer\Cli\CliService

Hierarchy

  • class \Drupal\cms_content_sync_developer\Cli\CliService

Expanded class hierarchy of CliService

2 files declare their use of CliService
CMSContentSyncDeveloperCommands.php in modules/cms_content_sync_developer/src/Commands/CMSContentSyncDeveloperCommands.php
cms_content_sync.module in ./cms_content_sync.module
Module file for cms_content_sync.

File

modules/cms_content_sync_developer/src/Cli/CliService.php, line 11

Namespace

Drupal\cms_content_sync_developer\Cli
View source
class CliService {

  /**
   * Export the configuration to the Sync Core.
   *
   * @param $io
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function configuration_export($io) {
    $flows = Flow::getAll(FALSE);
    foreach ($flows as $flow) {

      // Get all entity type configurations.
      $entity_type_bundle_configs = $flow
        ->getEntityTypeConfig(NULL, NULL, TRUE);

      // Update versions.
      foreach ($entity_type_bundle_configs as $config) {
        $flow
          ->updateEntityTypeBundleVersion($config['entity_type_name'], $config['bundle_name']);
        $flow
          ->resetVersionWarning();
      }
    }
    $io
      ->text('Flows updated');
  }
  public static $forceEntityDeletion = FALSE;

  /**
   * Force the deletion of an entities and skip the syndication.
   *
   * @param $io
   * @param $entity_type
   * @param $options
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   * @throws \Drupal\Core\Entity\EntityStorageException
   * @throws \Drush\Exceptions\UserAbortException
   */
  public function force_entity_deletion($io, $entity_type, $options) {
    self::$forceEntityDeletion = TRUE;
    $bundle = $options['bundle'];
    $entity_uuid = $options['entity_uuid'];
    if (isset($bundle) && isset($entity_uuid) || !isset($bundle) && !isset($entity_uuid)) {
      $io
        ->error('Either the bundle OR the entity_uuid option must be set.');
      return;
    }
    if (isset($entity_uuid)) {
      $entity = \Drupal::service('entity.repository')
        ->loadEntityByUuid($entity_type, $entity_uuid);
      if (!$entity) {
        $io
          ->error('An entity of type ' . $entity_type . ' having the uuid ' . $entity_uuid . ' does not exist.');
        return;
      }
      if (!$io
        ->confirm(dt('Do you really want to delete the entity of type ' . $entity_type . ' having the uuid: ' . $entity_uuid . ' '))) {
        throw new UserAbortException();
      }
      $entity
        ->delete();
      $io
        ->success('The ' . $entity_type . ' having the uuid ' . $entity_uuid . ' has been deleted.');
      return;
    }
    if (isset($bundle)) {
      if (!$io
        ->confirm(dt('Do you really want to delete all entities of the type: ' . $entity_type . ' having the bundle: ' . $bundle . ' ?'))) {
        throw new UserAbortException();
      }
      $bundle_key = \Drupal::entityTypeManager()
        ->getStorage($entity_type)
        ->getEntityType()
        ->getKey('bundle');
      if ($entity_type == 'menu_link_content') {
        $bundle_key = 'menu_name';
      }
      if ($entity_type == 'crop') {
        $bundle_key = 'type';
      }
      $entities = \Drupal::entityTypeManager()
        ->getStorage($entity_type)
        ->loadByProperties([
        $bundle_key => $bundle,
      ]);
      foreach ($entities as $entity) {
        $entity
          ->delete();
      }
      $io
        ->success('All entities of type: ' . $entity_type . ' and bundle: ' . $bundle . ' have been deleted.');
      return;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CliService::$forceEntityDeletion public static property
CliService::configuration_export public function Export the configuration to the Sync Core.
CliService::force_entity_deletion public function Force the deletion of an entities and skip the syndication.