You are here

function maestro_user_update in Maestro 8.2

Same name and namespace in other branches
  1. 3.x maestro.module \maestro_user_update()

Implements hook_user_update().

File

./maestro.module, line 60
Provides glue logic, hook implementation and core set process variable functions.

Code

function maestro_user_update($account) {
  $old_account = $account->original;
  $old_name = $old_account
    ->getAccountName();
  if ($old_account
    ->getAccountName() != $account
    ->getAccountName()) {

    // We have to update our production assignments.
    $query = \Drupal::entityQuery('maestro_production_assignments')
      ->condition('assign_id', $old_name);
    $assignmentIDs = $query
      ->execute();
    foreach ($assignmentIDs as $assignmentID) {
      $assignRecord = \Drupal::entityTypeManager()
        ->getStorage('maestro_production_assignments')
        ->load($assignmentID);
      $assignRecord
        ->set('assign_id', $account
        ->getAccountName());
      $assignRecord
        ->save();
    }
  }
}