drupalwxt / wxt

Drupal 10 variant of the Web Experience Toolkit (WxT).
https://drupalwxt.github.io
GNU General Public License v2.0
26 stars 27 forks source link

Error with wxt-8.x-3.0.17: scheduled_transition_date field and scheduled_transition_state field need to be uninstalled. #234

Closed PCH-TanB closed 3 years ago

PCH-TanB commented 3 years ago

Hello, could you please help us with this error:

Entity/field definitions Mismatched entity and/or field definitions The following changes were detected in the entity type and field definitions. Custom block

The scheduled_transition_date field needs to be uninstalled.
The scheduled_transition_state field needs to be uninstalled.

Crop

The scheduled_transition_date field needs to be uninstalled.
The scheduled_transition_state field needs to be uninstalled.

Media

The scheduled_transition_date field needs to be uninstalled.
The scheduled_transition_state field needs to be uninstalled.

image

PCH-TanB commented 3 years ago

I tried to add following code before $response->send(); in index.php file, but it doesn't work. try { \Drupal::entityDefinitionUpdateManager()->applyUpdates(); } catch (EntityStorageException $e) { print_r($e); }

PCH-TanB commented 3 years ago

I found a solution from Clay Freeman (clayfreeman) on https://www.drupal.org/project/lightning_workflow/issues/3126343 The attached script can be ran to perform the necessary updates to the field storage definitions in the interim until a fix is released: /**

use Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface;

// Retrieve a list of pending updates to entity types and their field storage. $change_list = \Drupal::entityDefinitionUpdateManager()->getChangeList(); // We're only interested in field storage updates; discard everything else. $change_list = array_filter(array_map(function ($changed) { // Check whether there are any field storage updates to this entity type. if (array_key_exists('field_storage_definitions', $changed)) { // Filter the list of field storage updates to contain updates to // 'lightning_scheduler' fields only. return array_filter($changed['field_storage_definitions'], function ($key) { // Check if this is field is provided by 'lightning_scheduler'. return in_array($key, [ 'scheduled_transition_date', 'scheduled_transition_state', ], TRUE); }, ARRAY_FILTER_USE_KEY); } }, $change_list));

// Iterate over each updated entity type for processing. foreach ($change_list as $entity_type_id => $fields) { // Fetch the currently-installed field storage definitions for this type. $current = \Drupal::service('entity.last_installed_schema.repository') ->getLastInstalledFieldStorageDefinitions($entity_type_id); // Fetch the new field storage definitions as defined. $new = \Drupal::service('entity_field.manager') ->getFieldStorageDefinitions($entity_type_id);

// Iterate over each field that requires an update for this entity type. foreach ($fields as $field_name => $op) { // Fetch the current and new field storage definitions for this field. $current_field = array_key_exists($field_name, $current) ? $current[$field_name] : NULL; $new_field = array_key_exists($field_name, $new) ? $new[$field_name] : NULL;

// Perform the required update for this field storage definition.
switch ($op) {
  case EntityDefinitionUpdateManagerInterface::DEFINITION_CREATED:
    \Drupal::service('field_storage_definition.listener')
      ->onFieldStorageDefinitionCreate($new_field);
    break;

  case EntityDefinitionUpdateManagerInterface::DEFINITION_UPDATED:
    \Drupal::service('field_storage_definition.listener')
      ->onFieldStorageDefinitionUpdate($new_field, $current_field);
    break;

  case EntityDefinitionUpdateManagerInterface::DEFINITION_DELETED:
    \Drupal::service('field_storage_definition.listener')
      ->onFieldStorageDefinitionDelete($current_field);
    break;
}

} } After I run the above code, the errors are gone. But Clay Freeman said: “ This should probably only be used if absolutely necessary, however, since the final fix for the original issue may not be compatible with any changes made here.” I don’t know if there exist a final fix. Thank you so much!

sylus commented 3 years ago

We send an email mentioning you have to run the drush update scripts and resolved this in email :D