/** * Switch to another user to run an update if necessary. * * @param \Drupal\scheduled_updates\ScheduledUpdateInterface $update * @param \Drupal\Core\Entity\ContentEntityInterface $entity_to_update */ protected function switchUser(ScheduledUpdateInterface $update, ContentEntityInterface $entity_to_update) { $update_user = $this->configuration['update_user']; $switch_to_user = NULL; switch ($update_user) { case $this::USER_UPDATE_RUNNER: // Running the update as the update runner means there is no need to switch return; case $this::USER_OWNER: $switch_to_user = $this->getEntityOwner($entity_to_update); break; case $this::USER_REVISION_OWNER: $switch_to_user = $this->getRevisionOwner($entity_to_update); break; case $this::USER_UPDATE_OWNER: $switch_to_user = $update->getOwner(); break; } if ($switch_to_user) { // @todo Throw an error because we should have a user. $this->accountSwitcher->switchTo($switch_to_user); $this->isUserSwitched = TRUE; } }