CommandHelper.php in Config Partial Export 8
File
src/Utility/CommandHelper.php
View source
<?php
namespace Drupal\config_partial_export\Utility;
use Drupal\Core\Config\ConfigManagerInterface;
use Drupal\Core\Config\StorageComparer;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ModuleInstallerInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drush\Commands\DrushCommands;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class CommandHelper extends DrushCommands {
protected $configManager;
protected $configStorage;
protected $configStorageSync;
protected $eventDispatcher;
protected $lock;
protected $configTyped;
protected $moduleInstaller;
protected $themeHandler;
protected $stringTranslation;
protected $moduleHandler;
public function __construct(ConfigManagerInterface $configManager, StorageInterface $configStorage, StorageInterface $configStorageSync, ModuleHandlerInterface $moduleHandler, EventDispatcherInterface $eventDispatcher, LockBackendInterface $lock, TypedConfigManagerInterface $configTyped, ModuleInstallerInterface $moduleInstaller, ThemeHandlerInterface $themeHandler, TranslationInterface $stringTranslation) {
parent::__construct();
$this->configManager = $configManager;
$this->configStorage = $configStorage;
$this->configStorageSync = $configStorageSync;
$this->moduleHandler = $moduleHandler;
$this->eventDispatcher = $eventDispatcher;
$this->lock = $lock;
$this->configTyped = $configTyped;
$this->moduleInstaller = $moduleInstaller;
$this->themeHandler = $themeHandler;
$this->stringTranslation = $stringTranslation;
}
function _config_partial_export_write_config($key, StorageInterface $source_storage, StorageInterface $destination_storage, $destination_dir) {
$data = $source_storage
->read($key);
if (empty($data)) {
$data = $this->configManager
->getConfigFactory()
->get($key)
->getRawData();
}
$destination_storage
->write($key, $data);
$this
->logger()
->info(dt('Writing !name to !target.', [
'!name' => $key,
'!target' => $destination_dir,
]));
return $data;
}
function _config_partial_export_get_wildcard_keys($input, StorageInterface $storage) {
$split = explode('*', $input);
$matching_keys = [];
$possible_keys = $storage
->listAll($split[0]);
foreach ($possible_keys as $config_key) {
$match = TRUE;
$counter = strlen($split[0]);
for ($i = 1; $i < count($split); $i++) {
if (!empty($split[$i])) {
$pos = strpos($config_key, $split[$i], $counter);
if ($pos === FALSE) {
$match = FALSE;
}
$counter += $pos + strlen($split[$i]);
}
}
if ($match) {
$matching_keys[] = $config_key;
}
}
return $matching_keys;
}
function _config_partial_export_get_changes() {
$storage_comparer = new StorageComparer($this->configStorageSync, $this->configStorage, $this->configManager);
$source_list = $this->configStorageSync
->listAll();
$change_list = $storage_comparer
->createChangelist();
if (empty($source_list) || !$change_list
->hasChanges()) {
$this
->output()
->writeln(dt('There are no configuration changes.'));
return TRUE;
}
$diff = $change_list
->getChangelist();
if (!empty($diff)) {
foreach ($diff as $action => $config_names) {
if (empty($config_names)) {
unset($diff[$action]);
continue;
}
sort($diff[$action]);
}
}
return $diff;
}
}