function user_update_7013 in Drupal 7
Add user module file usage entries.
Related topics
File
- modules/
user/ user.install, line 787 - Install, update and uninstall functions for the user module.
Code
function user_update_7013(&$sandbox) {
if (!isset($sandbox['progress'])) {
// Initialize batch update information.
$sandbox['progress'] = 0;
$sandbox['last_uid_processed'] = -1;
$sandbox['max'] = db_query("SELECT COUNT(*) FROM {users} u WHERE u.picture <> 0")
->fetchField();
}
// Add usage entries for the user picture files.
$limit = 500;
$result = db_query_range('SELECT f.*, u.uid as user_uid FROM {users} u INNER JOIN {file_managed} f ON u.picture = f.fid WHERE u.picture <> 0 AND u.uid > :uid ORDER BY u.uid', 0, $limit, array(
':uid' => $sandbox['last_uid_processed'],
))
->fetchAllAssoc('fid', PDO::FETCH_ASSOC);
foreach ($result as $row) {
$uid = $row['user_uid'];
$file = (object) $row;
file_usage_add($file, 'user', 'user', $uid);
// Update our progress information for the batch update.
$sandbox['progress']++;
$sandbox['last_uid_processed'] = $uid;
}
// Indicate our current progress to the batch update system.
$sandbox['#finished'] = empty($sandbox['max']) || $sandbox['progress'] / $sandbox['max'];
}