Skip to content
Snippets Groups Projects

Draft: WIP: #3511381 validate configuration in a batch process

3 files
+ 79
15
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -91,6 +91,62 @@ class ConfigInspectorController extends ControllerBase {
return $form;
}
public static function validateItem( $configs, &$context) {
/** @var \Drupal\config_inspector\ConfigInspectorManager $configInspectorManager */
$configInspectorManager = \Drupal::service('config_inspector.manager');
if (empty($context['sandbox'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['total'] = count($configs);
}
$items = array_slice($configs, $context['sandbox']['progress'], 50);
foreach ($items as $name) {
$item = [ 'name' => $name ];
if(!$configInspectorManager->hasSchema($name)) {
$item['schema'] = FALSE;
}
else{
$item['schema'] = TRUE;
$result = $configInspectorManager->checkValues($name);
$raw_violations = $configInspectorManager->validateValues($name);
$raw_validatability = $configInspectorManager->checkValidatabilityValues($name);
$item['schema_errors'] = $result;
$item['availability_percentage'] = $raw_validatability->computePercentage();
$item['raw_violations'] = $raw_violations;
}
$context['results'][$name] = $item;
}
$context['sandbox']['progress'] += 50;
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['total'];
}
/**
* Finishes the batch process.
*/
public static function batchValidationFinish($success, $results, $operations) {
$tempstore = \Drupal::service('tempstore.private')->get('config_inspector');
$tempstore->set('results', $results);
}
/**
* Sets up a batch process to validate the configuration.
*/
public function validateConfig() {
$batch = [
'title' => t('Validating configuration'),
'operations' => [
[ [ get_class($this), 'validateItem' ], [$this->configStorage->listAll()] ]
],
'finished' => [ get_class($this), 'batchValidationFinish' ],
];
batch_set($batch);
return batch_process('admin/reports/config-inspector');
}
/**
* Builds a page listing all configuration keys to inspect.
*
@@ -98,6 +154,10 @@ class ConfigInspectorController extends ControllerBase {
* A render array representing the list.
*/
public function overview() {
$tempstore = \Drupal::service('tempstore.private')->get('config_inspector');
$results = $tempstore->get('results');
$page['#attached']['library'][] = 'system/drupal.debounce';
$page['#attached']['library'][] = 'config_inspector/config_inspector';
@@ -151,10 +211,10 @@ class ConfigInspectorController extends ControllerBase {
],
];
foreach ($this->configStorage->listAll() as $name) {
foreach ($results as $name => $value) {
$label = '<span class="table-filter-text-source">' . $name . '</span>';
// Elements without a schema are displayed to help debugging.
if (!$this->configInspectorManager->hasSchema($name)) {
if (!$value['schema']) {
$page['table'][] = [
'name' => ['#markup' => $label],
'schema' => [
@@ -172,40 +232,37 @@ class ConfigInspectorController extends ControllerBase {
}
else {
$schema = $this->t('Correct');
$result = $this->configInspectorManager->checkValues($name);
$raw_violations = $this->configInspectorManager->validateValues($name);
$raw_validatability = $this->configInspectorManager->checkValidatabilityValues($name);
if (is_array($result)) {
if (is_array($value['schema_errors'])) {
// The no-schema case is covered above already, if we got errors, the
// schema is partial.
$schema = $this->translationManager->formatPlural(count($result), '@count error', '@count errors');
$schema = $this->translationManager->formatPlural(count($value['schema_errors']), '@count error', '@count errors');
}
$page['table'][] = [
'name' => ['#markup' => $label],
'schema' => [
'#markup' => $schema,
'#wrapper_attributes' => [
'data-has-errors' => is_array($result),
'data-has-errors' => is_array($value['schema_errors']),
],
],
'validatability' => [
'#markup' => $raw_validatability->isComplete()
'#markup' => $value['availability_percentage'] == 1
? $this->t('Validatable')
: $this->t('@validatability%', ['@validatability' => intval($raw_validatability->computePercentage() * 100)]),
: $this->t('@validatability%', ['@validatability' => intval($value['availability_percentage'] * 100)]),
],
'violations' => [
'#markup' => $raw_violations->count() === 0
? ($raw_validatability->isComplete()
'#markup' => $value['raw_violations']->count() === 0
? ($value['availability_percentage'] == 1
? $this->t('<abbr title="Correct primitive type, passed all validation constraints.">✅✅</abbr>')
: $this->t('<abbr title="Correct primitive type, detailed validation impossible.">✅❓</abbr>')
)
: $this->translationManager->formatPlural(
$raw_violations->count(),
count($value['raw_violations']),
'@count error',
'@count errors',
),
'#wrapper_attributes' => [
'data-has-errors' => $raw_violations->count() > 0,
'data-has-errors' => count($value['raw_violations']) > 0,
],
],
'list' => [
Loading