You are here

class ConfigExportIgnoreConfigSplitService in Config Export Ignore 8

Overrides exports service and removes specified configuration form export.

@package Drupal\config_export_ignore

Hierarchy

Expanded class hierarchy of ConfigExportIgnoreConfigSplitService

File

src/ConfigExportIgnoreConfigSplitService.php, line 24

Namespace

Drupal\config_export_ignore
View source
class ConfigExportIgnoreConfigSplitService extends ConfigSplitCliService {
  const FORCE_EXCLUSION_PREFIX = '~';

  /**
   * ConfigExportIgnoreConfigSplitService constructor.
   */
  public function __construct(ConfigFilterManagerInterface $config_filter_manager, ConfigFilterStorageFactory $storageFactory, ConfigManagerInterface $config_manager, StorageInterface $active_storage, StorageInterface $sync_storage, EventDispatcherInterface $event_dispatcher, LockBackendInterface $lock, TypedConfigManagerInterface $config_typed, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler, TranslationInterface $string_translation, ModuleExtensionList $moduleExtensionList) {
    parent::__construct($config_filter_manager, $storageFactory, $config_manager, $active_storage, $sync_storage, $event_dispatcher, $lock, $config_typed, $module_handler, $module_installer, $theme_handler, $string_translation, $moduleExtensionList);
  }

  /**
   * Export the configuration.
   *
   * This is the quintessential config export.
   *
   * @param \Drupal\Core\Config\StorageInterface $storage
   *   The config storage to export to.
   *
   * @param \Drupal\Core\Config\StorageInterface|null $active
   *   The config storage to export from (optional).
   */
  public function export(StorageInterface $storage, StorageInterface $active = NULL) {

    // Delete all, the filters are responsible for keeping some configuration.
    $storage
      ->deleteAll();

    // Get the default active storage to copy it to the sync storage.
    if ($this->activeStorage
      ->getCollectionName() != StorageInterface::DEFAULT_COLLECTION) {

      // This is probably not necessary, but we do it as a precaution.
      $this->activeStorage = $this->activeStorage
        ->createCollection(StorageInterface::DEFAULT_COLLECTION);
    }

    // Copy everything.
    foreach ($this->activeStorage
      ->listAll() as $name) {
      if (!self::matchConfigName($name)) {
        $storage
          ->write($name, $this->activeStorage
          ->read($name));
      }
    }

    // Get all override data from the remaining collections.
    foreach ($this->activeStorage
      ->getAllCollectionNames() as $collection) {
      $source_collection = $this->activeStorage
        ->createCollection($collection);
      $destination_collection = $storage
        ->createCollection($collection);

      // Delete everything in the collection sub-directory.
      try {
        $destination_collection
          ->deleteAll();
      } catch (\UnexpectedValueException $exception) {

        // Deleting a non-existing folder for collections might fail.
      }
      foreach ($source_collection
        ->listAll() as $name) {
        if (!self::matchConfigName($name)) {
          $destination_collection
            ->write($name, $source_collection
            ->read($name));
        }
      }
    }
  }

  /**
   * Match a config entity name against the list of ignored config entities.
   *
   * @param string $config_name
   *   The name of the config entity to match against all ignored entities.
   *
   * @return bool
   *   True, if the config entity is to be ignored, false otherwise.
   */
  public static function matchConfigName($config_name) {
    $config_ignore_settings = \Drupal::config('config_export_ignore.settings')
      ->get('configuration_names');
    if ($config_ignore_settings) {

      // If the string is an excluded config, don't ignore it.
      foreach ($config_ignore_settings as $config_ignore_setting) {
        if (substr($config_ignore_setting, 0, 1) === static::FORCE_EXCLUSION_PREFIX && fnmatch(substr($config_ignore_setting, 1), $config_name)) {
          return FALSE;
        }
      }
      foreach ($config_ignore_settings as $config_ignore_setting) {

        // Test if the config_name is in the ignore list using a shell like
        // validation function to test the config_ignore_setting pattern.
        if (fnmatch($config_ignore_setting, $config_name)) {
          return TRUE;
        }
      }
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigExportIgnoreConfigSplitService::export public function Export the configuration. Overrides ConfigSplitCliService::export
ConfigExportIgnoreConfigSplitService::FORCE_EXCLUSION_PREFIX constant
ConfigExportIgnoreConfigSplitService::matchConfigName public static function Match a config entity name against the list of ignored config entities.
ConfigExportIgnoreConfigSplitService::__construct public function ConfigExportIgnoreConfigSplitService constructor. Overrides ConfigSplitCliService::__construct
ConfigSplitCliService::$activeStorage protected property Active Config Storage.
ConfigSplitCliService::$configFilterManager protected property The filter manager.
ConfigSplitCliService::$configManager protected property Drupal\Core\Config\ConfigManager definition.
ConfigSplitCliService::$configTyped protected property Drupal\Core\Config\TypedConfigManager definition.
ConfigSplitCliService::$errors protected property List of messages.
ConfigSplitCliService::$eventDispatcher protected property Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher definition.
ConfigSplitCliService::$lock protected property Drupal\Core\ProxyClass\Lock\DatabaseLockBackend definition.
ConfigSplitCliService::$moduleExtensionList protected property The ModuleExtensionList to be passed to the config importer.
ConfigSplitCliService::$moduleHandler protected property Drupal\Core\Extension\ModuleHandler definition.
ConfigSplitCliService::$moduleInstaller protected property Drupal\Core\ProxyClass\Extension\ModuleInstaller definition.
ConfigSplitCliService::$storageFactory protected property The config filter storage factory.
ConfigSplitCliService::$stringTranslation protected property Drupal\Core\StringTranslation\TranslationManager definition.
ConfigSplitCliService::$syncStorage protected property Sync Config Storage.
ConfigSplitCliService::$themeHandler protected property Drupal\Core\Extension\ThemeHandler definition.
ConfigSplitCliService::ALREADY_IMPORTING constant The return value indicating that the import is already in progress.
ConfigSplitCliService::COMPLETE constant The return value indicating that the process is complete.
ConfigSplitCliService::getDestination protected function Returns the directory path to export or "database".
ConfigSplitCliService::getErrors public function Returns error messages created while running the import.
ConfigSplitCliService::getPluginIdFromConfigName protected function Get the plugin id of a split filter from a config name.
ConfigSplitCliService::getSplitName protected function Get the configuration name from the short name.
ConfigSplitCliService::import public function Import the configuration.
ConfigSplitCliService::ioExport public function Handle the export interaction.
ConfigSplitCliService::ioImport public function Handle the import interaction.
ConfigSplitCliService::NO_CHANGES constant The return value indicating no changes were imported.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.