Skip to content
Snippets Groups Projects
Commit e1ea0dcf authored by Urvashi Vora's avatar Urvashi Vora Committed by Märt Rang
Browse files

Issue #3355098 by urvashi_vora: Fix the issues reported by PHPCS

parent e079dedf
No related branches found
No related tags found
No related merge requests found
### Why
Drupal makes it possible to update configuration in different ways. The ConfigFactory::getEditable allows editing any configuration type. It also allows to mess up and bad - for example, assuming that some entity configuration exists and partially updating creates an empty config file that can't be loaded because required values are missing.
It results in a broken admin side - either the toolbar link can't be loaded (like the view configuration), or some admin screen related to that config fails to load. When that happens, it is hard to find the config which is broken.
Drupal makes it possible to update configuration in different ways.
The ConfigFactory::getEditable allows editing any configuration type.
It also allows to mess up and bad -
for example, assuming that some entity configuration exists and partially
updating creates an empty config file that can't be loaded because required
values are missing.
It results in a broken admin side - either the toolbar link can't be loaded
(like the view configuration), or some admin screen related to that config
fails to load. When that happens, it is hard to find the config which is broken.
### What the module does
The module currently scans all config entity types and queries all entity IDs from the config table, which are loaded one by one. If the loading fails, we can assume it's broken and can be either deleted, re-imported, or manually fixed with Drush config commands.
The module currently scans all config entity types and queries all entity IDs
from the config table, which are loaded one by one. If the loading fails, we can
assume it's broken and can be either deleted, re-imported, or manually fixed
with Drush config commands.
Basically it is a simple helper module to quickly find possibly broken configurations.
Basically it is a simple helper module to quickly find possibly broken
configurations.
### How to use it
......@@ -13,7 +24,8 @@ Open administration url /admin/config/development/configuration/broken
Click on the Start scanning button
After batch job is finished, all problematic configs are shown.
If administration is not accessible (fatal error), then Drush command could help:
If administration is not accessible (fatal error), then Drush command
could help:
````bash
drush broken_config:scan
````
......
......@@ -2,8 +2,6 @@
namespace Drupal\broken_config;
use Drupal;
/**
* Batch processing helper class.
*/
......@@ -12,15 +10,15 @@ class BrokenConfigBatch {
/**
* Batch task which processes specific entity type.
*
* @param $entity_type
* @param string $entity_type
* Entity type to process.
* @param $context
* @param array $context
* Context.
*/
public static function scanConfigEntityType($entity_type, &$context): void {
public static function scanConfigEntityType($entity_type, array &$context): void {
$message = "Scanning configuration entity type $entity_type";
Drupal::service('broken_config.scanner')->scanEntityType($entity_type);
\Drupal::service('broken_config.scanner')->scanEntityType($entity_type);
$context['message'] = $message;
$context['results'][] = '';
......@@ -29,14 +27,14 @@ class BrokenConfigBatch {
/**
* Batch finished callback.
*
* @param $success
* @param string $success
* Batch job status.
* @param $results
* @param string $results
* Total entity types processed.
*/
public static function scanFinished($success, $results): void {
if ($success) {
$message = Drupal::translation()->formatPlural(
$message = \Drupal::translation()->formatPlural(
count($results),
'One config entity processed.', '@count config entities processed.'
);
......@@ -44,8 +42,8 @@ class BrokenConfigBatch {
else {
$message = t('Error scanning entities.');
}
Drupal::state()->set('broken_config.last_scan', Drupal::time()->getRequestTime());
Drupal::messenger()->addMessage($message);
\Drupal::state()->set('broken_config.last_scan', \Drupal::time()->getRequestTime());
\Drupal::messenger()->addMessage($message);
}
}
......@@ -56,7 +56,7 @@ class BrokenConfigScanner {
* Loads all configuration entities of specified entity type and tries to load
* them one by one to find the ones that can't be loaded.
*
* @param $entity_type
* @param string $entity_type
* Config entity type id to scan.
*/
public function scanEntityType($entity_type): void {
......@@ -119,7 +119,7 @@ class BrokenConfigScanner {
* Get broken config information from state.
*
* @return array
* Returns list of entity IDs from state, keyed by entity type.
* Returns list of entity IDs from state, keyed by entity type.
*/
public function getBrokenConfiguration(): array {
$entity_types = $this->getAllConfigEntityTypes();
......@@ -136,7 +136,7 @@ class BrokenConfigScanner {
foreach ($values as $entity_id) {
$prefix = $entity_type->getConfigPrefix();
$configs[$entity_type->id()][] = $prefix . '.' .$entity_id;
$configs[$entity_type->id()][] = $prefix . '.' . $entity_id;
}
}
......@@ -147,7 +147,7 @@ class BrokenConfigScanner {
* Get last scan information.
*
* @return null|string
* Returns last scan time or NULL if scan is not executed yet.
* Returns last scan time or NULL if scan is not executed yet.
*/
public function getLastScan(): ?string {
return $this->state->get('broken_config.last_scan');
......
......@@ -74,15 +74,18 @@ class ScanConfigForm extends FormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state): void {
$batch = [
'title' => t('Processing configuration'),
'title' => $this->t('Processing configuration'),
'operations' => [],
'finished' => '\Drupal\broken_config\BrokenConfigBatch::scanFinished',
];
$config_entities = $this->brokenConfigScanner->getAllConfigEntityTypes();
foreach($config_entities as $config_entity) {
$batch['operations'][] = ['\Drupal\broken_config\BrokenConfigBatch::scanConfigEntityType', [$config_entity->id()]];
foreach ($config_entities as $config_entity) {
$batch['operations'][] = [
'\Drupal\broken_config\BrokenConfigBatch::scanConfigEntityType',
[$config_entity->id()],
];
}
batch_set($batch);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment