Skip to content

Commit

Permalink
Refactor log result.
Browse files Browse the repository at this point in the history
  • Loading branch information
govindmaloo committed Jul 10, 2023
1 parent 9835fe6 commit 3cc9419
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 30 deletions.
22 changes: 9 additions & 13 deletions docroot/themes/contrib/civictheme/civictheme.post_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,11 @@ function (CivicthemeUpdateHelper $helper) use (&$sandbox, $old_field_configs, $f

if ($sandbox['#finished'] >= 1) {
$paragraph_types = array_keys($form_display_config);
$log = new TranslatableMarkup("Content from field 'field_c_p_column_count' was moved to 'field_c_p_list_column_count'.
Content from field 'field_c_p_fill_width' was moved to 'field_c_p_list_fill_width'.
The 'field_c_p_column_count' and 'field_c_p_fill_width' were removed from %paragraph_types paragraph types.
Please re-export your site configuration. \n", [
$log = new TranslatableMarkup("Content from field 'field_c_p_column_count' was moved to 'field_c_p_list_column_count'. Content from field 'field_c_p_fill_width' was moved to 'field_c_p_list_fill_width'.
The 'field_c_p_column_count' and 'field_c_p_fill_width' were removed from %paragraph_types paragraph types. Please re-export your site configuration. \n", [
'%paragraph_types' => implode(', ', $paragraph_types),
]);
\Drupal::logger('update')->notice($log);
\Drupal::logger('update')->info($log);

return $log;
}
Expand Down Expand Up @@ -316,12 +314,11 @@ function (CivicthemeUpdateHelper $helper) use (&$sandbox, $old_field_configs, $f

if ($sandbox['#finished']) {
$paragraph_types = array_keys($form_display_config);
$log = new TranslatableMarkup("Content from field 'field_c_p_summary' was moved to 'field_c_p_content'.
The 'field_c_p_summary' field was removed from %paragraph_types paragraph types.
Please re-export your site configuration. \n", [
$log = new TranslatableMarkup("Content from field 'field_c_p_summary' was moved to 'field_c_p_content'. The 'field_c_p_summary' field was removed from %paragraph_types paragraph types.
Please re-export your site configuration.\n", [
'%paragraph_types' => implode(', ', $paragraph_types),
]);
\Drupal::logger('update')->notice($log);
\Drupal::logger('update')->info($log);

return $log;
}
Expand Down Expand Up @@ -395,12 +392,11 @@ function (CivicthemeUpdateHelper $helper) use (&$sandbox, $old_field_configs, $f

if ($sandbox['#finished']) {
$entity_types = array_keys($form_display_config);
$log = new TranslatableMarkup("Content from field 'field_c_n_date' was moved to 'field_c_n_date_range'.
The 'field_c_n_date_range' field was removed from %entity_types node types.
Please re-export your site configuration. \n", [
$log = new TranslatableMarkup("Content from field 'field_c_n_date' was moved to 'field_c_n_date_range'. The 'field_c_n_date_range' field was removed from %entity_types node types.
Please re-export your site configuration.\n", [
'%entity_types' => implode(', ', $entity_types),
]);
\Drupal::logger('update')->notice($log);
\Drupal::logger('update')->info($log);

return $log;
}
Expand Down
28 changes: 11 additions & 17 deletions docroot/themes/contrib/civictheme/src/CivicthemeUpdateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function update(array &$sandbox, $entity_type, array $entity_bundles, cal
// Finiished callback.
$log = call_user_func($finished_callback, $this);

$log = new TranslatableMarkup("%finished\n Update results ran in %batches batch(es):\n Processed: %processed %processed_ids\n Updated: %updated %updated_ids\n Skipped: %skipped %skipped_ids\n", [
$log = new TranslatableMarkup("%finished\n<br> Update results ran in %batches batch(es):\n<br> Processed: %processed %processed_ids\n<br> Updated: %updated %updated_ids\n<br> Skipped: %skipped %skipped_ids\n<br>", [
'%finished' => $log,
'%batches' => $sandbox['batch'],
'%processed' => count($sandbox['results']['processed']),
Expand All @@ -133,7 +133,7 @@ public function update(array &$sandbox, $entity_type, array $entity_bundles, cal
'%skipped' => count($sandbox['results']['skipped']),
'%skipped_ids' => count($sandbox['results']['skipped']) ? '(' . implode(', ', $sandbox['results']['skipped']) . ')' : '',
]);
$this->logger->notice($log);
$this->logger->info($log);

return $log;
}
Expand All @@ -143,10 +143,6 @@ public function update(array &$sandbox, $entity_type, array $entity_bundles, cal
* Updated required field configs.
*/
public function createConfigs(&$sandbox, array $configs, $config_path) {
if (isset($sandbox['entities'])) {
return;
}

$source = new FileStorage($config_path);

// Check if field already exported in config/sync.
Expand All @@ -166,17 +162,15 @@ public function createConfigs(&$sandbox, array $configs, $config_path) {
* Delete field configs after content update.
*/
public function deleteConfig($sandbox, $configs) {
if (!isset($sandbox['#finished']) || $sandbox['#finished'] < 1) {
return;
}

// Check if field already exported to config/sync.
foreach ($configs as $config => $type) {
$storage = $this->entityTypeManager->getStorage($type);
$id = substr($config, strpos($config, '.', 6) + 1);
$config_read = $storage->load($id);
if ($config_read != NULL) {
$config_read->delete();
if ($sandbox['#finished'] >= 1) {
// Check if field already exported to config/sync.
foreach ($configs as $config => $type) {
$storage = $this->entityTypeManager->getStorage($type);
$id = substr($config, strpos($config, '.', 6) + 1);
$config_read = $storage->load($id);
if ($config_read != NULL) {
$config_read->delete();
}
}
}
}
Expand Down

0 comments on commit 3cc9419

Please sign in to comment.