Commit f24938d8 authored by James Scott's avatar James Scott Committed by James Scott
Browse files

Issue #3223043 by Lugir, jlscott: Error on initialise

parent f1a5aebe
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -177,7 +177,8 @@ class UserHistoryInitialiseForm extends FormBase {
  public function submitForm(array &$form, FormStateInterface $form_state) {

    $batch_size = $form_state->getValue('batch_size');
    $tracked_fields = array_filter($form_state->getValue('tracked_fields'));
    $tracked_fields = $form_state->getValue('tracked_fields');
    $tracked_fields = is_array($tracked_fields) ? array_filter($tracked_fields) : [];

    $module_path = $this->moduleHandler->getModule('user_history')->getPath();

@@ -201,8 +202,7 @@ class UserHistoryInitialiseForm extends FormBase {
      ];
    }

    // Batch operation to update the user history records with changed field
    // data.
    // Batch operation to initialise the user history records with user data.
    $batch['operations'][] = [
      'user_history_create_initial_history', [
        $batch_size,
+32 −32
Original line number Diff line number Diff line
@@ -194,7 +194,7 @@ function user_history_create_initial_history($batch_size, array &$context) {
      $user_history->setLabel($account->id() . ': Install - ' . $context['sandbox']['date']);

      // Set the modified time to the last changed time of the account.
      $user_history->setCreatedTime($account->getChangedTime());
      $user_history->setCreatedTime($account->getChangedTime() ?? 0);
      // Set the modified_by uid value to current user.
      $user_history->setModifiedByUid($current_user->id());
      // Record that this record was generated during module install.
@@ -202,21 +202,21 @@ function user_history_create_initial_history($batch_size, array &$context) {
      // Record that this user entity exists in the database.
      $user_history->setUserDeleted(FALSE);

      $user_history->setUserId($account->id());
      $user_history->setUsername($account->getAccountname());
      $user_history->setUserPass($account->getPassword());
      $user_history->setUserMail($account->getEmail());
      $user_history->setUserTimezone($account->getTimeZone());
      $user_history->setUserStatus($account->isActive());
      $user_history->setUserRoles(implode('; ', $account->getRoles(TRUE)));
      $user_history->setUserCreated($account->getCreatedTime());
      $user_history->setUserChanged($account->getChangedTime());
      $user_history->setUserAccess($account->getLastAccessedTime());
      $user_history->setUserLogin($account->getLastLoginTime());
      $user_history->setUserInit($account->getInitialEmail());
      $user_history->setUserLangcode($account->language()->getId());
      $user_history->setUserPreferredLangcode($account->getPreferredLangcode());
      $user_history->setUserPreferredAdminLangcode($account->getPreferredAdminLangcode());
      $user_history->setUserId($account->id() ?? 0);
      $user_history->setUsername($account->getAccountname() ?? '');
      $user_history->setUserPass($account->getPassword() ?? '');
      $user_history->setUserMail($account->getEmail() ?? '');
      $user_history->setUserTimezone($account->getTimeZone() ?? '');
      $user_history->setUserStatus($account->isActive() ?? FALSE);
      $user_history->setUserRoles(implode('; ', $account->getRoles(TRUE) ?? []));
      $user_history->setUserCreated($account->getCreatedTime() ?? 0);
      $user_history->setUserChanged($account->getChangedTime() ?? 0);
      $user_history->setUserAccess($account->getLastAccessedTime() ?? 0);
      $user_history->setUserLogin($account->getLastLoginTime() ?? 0);
      $user_history->setUserInit($account->getInitialEmail() ?? '');
      $user_history->setUserLangcode($account->language()->getId() ?? '');
      $user_history->setUserPreferredLangcode($account->getPreferredLangcode() ?? '');
      $user_history->setUserPreferredAdminLangcode($account->getPreferredAdminLangcode() ?? '');

      // Get a list of fields attached to the user_history entity.
      $field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('user_history', 'user_history');
@@ -448,7 +448,7 @@ function user_history_update_tracked_history($batch_size, array $add_fields, arr
        $user_history->setLabel($account->id() . ': Modify - ' . $context['sandbox']['date']);

        // Set the modified time to the last changed time of the account.
        $user_history->setCreatedTime($account->getChangedTime());
        $user_history->setCreatedTime($account->getChangedTime() ?? 0);
        // Set the modified_by uid value to current user.
        $user_history->setModifiedByUid($current_user->id());
        // Record that this record was generated during tracked field update.
@@ -456,21 +456,21 @@ function user_history_update_tracked_history($batch_size, array $add_fields, arr
        // Record that this user entity exists in the database.
        $user_history->setUserDeleted(FALSE);

        $user_history->setUserId($account->id());
        $user_history->setUsername($account->getAccountname());
        $user_history->setUserPass($account->getPassword());
        $user_history->setUserMail($account->getEmail());
        $user_history->setUserTimezone($account->getTimeZone());
        $user_history->setUserStatus($account->isActive());
        $user_history->setUserRoles(implode('; ', $account->getRoles(TRUE)));
        $user_history->setUserCreated($account->getCreatedTime());
        $user_history->setUserChanged($account->getChangedTime());
        $user_history->setUserAccess($account->getLastAccessedTime());
        $user_history->setUserLogin($account->getLastLoginTime());
        $user_history->setUserInit($account->getInitialEmail());
        $user_history->setUserLangcode($account->language()->getId());
        $user_history->setUserPreferredLangcode($account->getPreferredLangcode());
        $user_history->setUserPreferredAdminLangcode($account->getPreferredAdminLangcode());
        $user_history->setUserId($account->id() ?? 0);
        $user_history->setUsername($account->getAccountname() ?? '');
        $user_history->setUserPass($account->getPassword() ?? '');
        $user_history->setUserMail($account->getEmail() ?? '');
        $user_history->setUserTimezone($account->getTimeZone() ?? '');
        $user_history->setUserStatus($account->isActive() ?? FALSE);
        $user_history->setUserRoles(implode('; ', $account->getRoles(TRUE) ?? []));
        $user_history->setUserCreated($account->getCreatedTime() ?? 0);
        $user_history->setUserChanged($account->getChangedTime() ?? 0);
        $user_history->setUserAccess($account->getLastAccessedTime() ?? 0);
        $user_history->setUserLogin($account->getLastLoginTime() ?? 0);
        $user_history->setUserInit($account->getInitialEmail() ?? '');
        $user_history->setUserLangcode($account->language()->getId() ?? '');
        $user_history->setUserPreferredLangcode($account->getPreferredLangcode() ?? '');
        $user_history->setUserPreferredAdminLangcode($account->getPreferredAdminLangcode() ?? '');

        // Record the reason for adding this user_history record.
        $user_history->setDifference(implode('. ', $difference));
+1 −1
Original line number Diff line number Diff line
@@ -173,7 +173,7 @@ function user_history_create_user_history(UserInterface $account, array $values
  $user_history->setUserPass($account->getPassword() ?? '');
  $user_history->setUserMail($account->getEmail() ?? '');
  $user_history->setUserTimezone($account->getTimeZone() ?? '');
  $user_history->setUserStatus($account->isActive() ?? TRUE);
  $user_history->setUserStatus($account->isActive() ?? FALSE);
  $user_history->setUserRoles(implode('; ', $account->getRoles(TRUE) ?? []));
  $user_history->setUserCreated($account->getCreatedTime() ?? 0);
  $user_history->setUserChanged($account->getChangedTime() ?? 0);
+21 −21
Original line number Diff line number Diff line
@@ -158,27 +158,27 @@ function user_history_restore_records($archive_file, array $uids, $batch_size, a
      $user_history = new UserHistory([], 'user_history');

      // Set the values in the user history record.
      $user_history->setLabel($values['label'][0]['value']);
      $user_history->setCreatedTime($values['created'][0]['value']);
      $user_history->setAction($values['action'][0]['value']);
      $user_history->setModifiedByUid($values['modified_by'][0]['target_id']);
      $user_history->setUserDeleted($values['user_deleted'][0]['value']);
      $user_history->setUserId($values['user_id'][0]['target_id']);
      $user_history->setUsername($values['user_name'][0]['value']);
      $user_history->setUserPass($values['user_pass'][0]['value']);
      $user_history->setUserMail($values['user_mail'][0]['value']);
      $user_history->setUserTimezone($values['user_timezone'][0]['value']);
      $user_history->setUserStatus($values['user_status'][0]['value']);
      $user_history->setUserRoles($values['user_roles'][0]['value']);
      $user_history->setUserCreated($values['user_created'][0]['value']);
      $user_history->setUserChanged($values['user_changed'][0]['value']);
      $user_history->setUserAccess($values['user_access'][0]['value']);
      $user_history->setUserLogin($values['user_login'][0]['value']);
      $user_history->setUserInit($values['user_init'][0]['value']);
      $user_history->setUserLangcode($values['user_langcode'][0]['value']);
      $user_history->setUserPreferredLangcode($values['user_preferred_langcode'][0]['value']);
      $user_history->setUserPreferredAdminLangcode($values['user_preferred_admin_langcode'][0]['value']);
      $user_history->setDifference($values['difference'][0]['value']);
      $user_history->setLabel($values['label'][0]['value'] ?? '');
      $user_history->setCreatedTime($values['created'][0]['value'] ?? 0);
      $user_history->setAction($values['action'][0]['value'] ?? '');
      $user_history->setModifiedByUid($values['modified_by'][0]['target_id'] ?? 0);
      $user_history->setUserDeleted($values['user_deleted'][0]['value'] ?? FALSE);
      $user_history->setUserId($values['user_id'][0]['target_id'] ?? 0);
      $user_history->setUsername($values['user_name'][0]['value'] ?? '');
      $user_history->setUserPass($values['user_pass'][0]['value'] ?? '');
      $user_history->setUserMail($values['user_mail'][0]['value'] ?? '');
      $user_history->setUserTimezone($values['user_timezone'][0]['value'] ?? '');
      $user_history->setUserStatus($values['user_status'][0]['value'] ?? FALSE);
      $user_history->setUserRoles($values['user_roles'][0]['value'] ?? '');
      $user_history->setUserCreated($values['user_created'][0]['value'] ?? 0);
      $user_history->setUserChanged($values['user_changed'][0]['value'] ?? 0);
      $user_history->setUserAccess($values['user_access'][0]['value'] ?? 0);
      $user_history->setUserLogin($values['user_login'][0]['value'] ?? 0);
      $user_history->setUserInit($values['user_init'][0]['value'] ?? '');
      $user_history->setUserLangcode($values['user_langcode'][0]['value'] ?? '');
      $user_history->setUserPreferredLangcode($values['user_preferred_langcode'][0]['value'] ?? '');
      $user_history->setUserPreferredAdminLangcode($values['user_preferred_admin_langcode'][0]['value'] ?? '');
      $user_history->setDifference($values['difference'][0]['value'] ?? '');

      // Get a list of fields attached to the user_history entity.
      // $field_definitions is not currently used.