Commit 28f8a79e authored by sreenivas paruchuri's avatar sreenivas paruchuri Committed by Joshua Bolduc
Browse files

Issue #3317357 by sreenivasparuchuri: Executed Date Time field not dispalyed in views

parent 2ccef8a1
Loading
Loading
Loading
Loading

action_queue.install

0 → 100644
+108 −0
Original line number Diff line number Diff line
<?php

use Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;

/**
 * Change executed column data type from datetime to timestamp.
 */
function action_queue_update_9001(&$sandbox) {
  $database = \Drupal::database();
  $transaction = $database->startTransaction();

  // Store the existing values.
  $executed_values = $database->select('action_queue_data')
    ->fields('action_queue_data', ['id', 'executed'])
    ->execute()
    ->fetchAllKeyed();
  // Clear out the values.
  $database->update('action_queue_data')
    ->fields(['executed' => NULL])
    ->execute();

  // apply entity updates.
  _action_queue_apply_entity_updates('action_queue_item');

  // Update old field values to new field.
  foreach ($executed_values as $id => $value) {
    $database->update('action_queue_data')
      ->fields(['executed' => $value])
      ->condition('id', $id)
      ->execute();
  }

  // Commit transaction.
  unset($transaction);
}

/**
 * Apply entity definition updates.
 *
 * @param $entity_type_id
 *   The entity type.
 */
function _action_queue_apply_entity_updates($entity_type_id) {
  // This is based on code in EntityDefinitionTestTrait which is nearly
  // identical to code that was in the deprecated method applyUpdates().
  // @see \Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait
  $complete_change_list = \Drupal::entityDefinitionUpdateManager()->getChangeList();
  if ($complete_change_list) {
    // In case there are changes, explicitly invalidate caches.
    \Drupal::entityTypeManager()->clearCachedDefinitions();
    \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
  }

  $complete_change_list = array_intersect_key($complete_change_list, [$entity_type_id => TRUE]);

  foreach ($complete_change_list as $entity_type_id => $change_list) {
    try {
      $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
    }
    catch (PluginNotFoundException $e) {

    }
    $field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type_id);

    if (!empty($change_list['entity_type'])) {
      switch ($change_list['entity_type']) {
        case EntityDefinitionUpdateManagerInterface::DEFINITION_CREATED:
          \Drupal::entityDefinitionUpdateManager()->installEntityType($entity_type);
          break;

        case EntityDefinitionUpdateManagerInterface::DEFINITION_UPDATED:
          \Drupal::entityDefinitionUpdateManager()->updateFieldableEntityType($entity_type, $field_storage_definitions);
          break;
      }
    }

    // Process field storage definition changes.
    if (!empty($change_list['field_storage_definitions'])) {
      $storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type_id);
      $original_storage_definitions = \Drupal::service('entity.last_installed_schema.repository')->getLastInstalledFieldStorageDefinitions($entity_type_id);

      foreach ($change_list['field_storage_definitions'] as $field_name => $change) {
        $storage_definition = isset($storage_definitions[$field_name]) ? $storage_definitions[$field_name] : NULL;
        $original_storage_definition = isset($original_storage_definitions[$field_name]) ? $original_storage_definitions[$field_name] : NULL;
        switch ($change) {
          case EntityDefinitionUpdateManagerInterface::DEFINITION_CREATED:
            \Drupal::entityDefinitionUpdateManager()
              ->installFieldStorageDefinition($field_name, $entity_type_id, $entity_type_id, $storage_definition);
            break;

          case EntityDefinitionUpdateManagerInterface::DEFINITION_UPDATED:
            \Drupal::entityDefinitionUpdateManager()
              ->updateFieldStorageDefinition($storage_definition);
            break;

          case EntityDefinitionUpdateManagerInterface::DEFINITION_DELETED:
            \Drupal::entityDefinitionUpdateManager()->uninstallFieldStorageDefinition($original_storage_definition);
            break;
        }
      }
    }
  }
}



+1 −1
Original line number Diff line number Diff line
@@ -219,7 +219,7 @@ class ActionQueueItem extends ContentEntityBase implements ActionQueueItemInterf
      ->setLabel(t('Created'))
      ->setDescription(t('The time that the entity was created.'));

    $fields['executed'] = BaseFieldDefinition::create('datetime')
    $fields['executed'] = BaseFieldDefinition::create('timestamp')
      ->setLabel(t('Executed'))
      ->setDescription(t('The time that the action was executed.'));