You are here

protected function AcsfDuplicationScrubUserHandler::reassignFiles in Acquia Cloud Site Factory Connector 8.2

Same name and namespace in other branches
  1. 8 src/Event/AcsfDuplicationScrubUserHandler.php \Drupal\acsf\Event\AcsfDuplicationScrubUserHandler::reassignFiles()

Reassigns files owned by the given user ID to the anonymous user.

Prior to deleting the user, re-assign {file_managed}.uid to anonymous. Re-assign files only: allow nodes and comments to be deleted. It would be more proper to call File::load_multiple(), iterate each loaded file entity, set its uid property, and call save() (see comment_user_cancel() for a similar example for comments). It would be even more proper if file.module implemented hook_user_cancel(), so we could just call that hook. But for performance, we just update the {file_managed} table directly.

Parameters

int $uid: The user ID for which to reassign files.

1 call to AcsfDuplicationScrubUserHandler::reassignFiles()
AcsfDuplicationScrubUserHandler::deleteEntities in src/Event/AcsfDuplicationScrubUserHandler.php
Deletes entities.

File

src/Event/AcsfDuplicationScrubUserHandler.php, line 77

Class

AcsfDuplicationScrubUserHandler
Handles the scrubbing of Drupal users.

Namespace

Drupal\acsf\Event

Code

protected function reassignFiles($uid) {
  \Drupal::database()
    ->update('file_managed')
    ->fields([
    'uid' => 0,
  ])
    ->condition('uid', $uid)
    ->execute();
}