diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-08-08 03:12:11 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-08-08 03:12:11 +0000 |
commit | b537c30be5dfdda58d39666e7f8aaa658ac8cb58 (patch) | |
tree | 0da30ecbaae545c7b0f84f05741e2613394a9ca5 | |
parent | be614da01feed2201ba13e1e3341daf38c4553be (diff) | |
download | brdo-b537c30be5dfdda58d39666e7f8aaa658ac8cb58.tar.gz brdo-b537c30be5dfdda58d39666e7f8aaa658ac8cb58.tar.bz2 |
- Patch #870594 by marcingy, moshe weitzman: user_update_7004 fail during upgrade from Drupal 6 to 7.
-rw-r--r-- | modules/user/user.install | 147 |
1 files changed, 77 insertions, 70 deletions
diff --git a/modules/user/user.install b/modules/user/user.install index 0a26ebf94..792901677 100644 --- a/modules/user/user.install +++ b/modules/user/user.install @@ -501,77 +501,10 @@ function user_update_7003() { } /** - * Add the user's pictures to the {file_managed} table and make them managed - * files. + * Moved to user_update_7012(). */ -function user_update_7004(&$sandbox) { - - $picture_field = array( - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'description' => "Foreign key: {file_managed}.fid of user's picture.", - ); - - if (!isset($sandbox['progress'])) { - // Check that the field hasn't been updated in an aborted run of this - // update. - if (!db_field_exists('users', 'picture_fid')) { - // Add a new field for the fid. - db_add_field('users', 'picture_fid', $picture_field); - } - - // Initialize batch update information. - $sandbox['progress'] = 0; - $sandbox['last_user_processed'] = -1; - $sandbox['max'] = db_query("SELECT COUNT(*) FROM {users} WHERE picture <> ''")->fetchField(); - } - - // As a batch operation move the photos into the {file_managed} table and - // update the {users} records. - $limit = 500; - $result = db_query_range("SELECT uid, picture FROM {users} WHERE picture <> '' AND uid > :uid ORDER BY uid", 0, $limit, array(':uid' => $sandbox['last_user_processed'])); - foreach ($result as $user) { - // Don't bother adding files that don't exist. - if (file_exists($user->picture)) { - - // Check if the file already exists. - $files = file_load_multiple(array(), array('uri' => $user->picture)); - if (count($files)) { - $file = reset($files); - } - else { - // Create a file object. - $file = new stdClass(); - $file->uri = $user->picture; - $file->filename = basename($file->uri); - $file->filemime = file_get_mimetype($file->uri); - $file->uid = $user->uid; - $file->status = FILE_STATUS_PERMANENT; - $file = file_save($file); - } - - db_update('users') - ->fields(array('picture_fid' => $file->fid)) - ->condition('uid', $user->uid) - ->execute(); - } - - // Update our progress information for the batch update. - $sandbox['progress']++; - $sandbox['last_user_processed'] = $user->uid; - } - - // Indicate our current progress to the batch update system. If there's no - // max value then there's nothing to update and we're finished. - $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); - - // When we're finished, drop the old picture field and rename the new one to - // replace it. - if (isset($sandbox['#finished']) && $sandbox['#finished'] == 1) { - db_drop_field('users', 'picture'); - db_change_field('users', 'picture_fid', 'picture', $picture_field); - } +function user_update_7004() { + // This doesn't affect any subsequent user updates. } /** @@ -715,6 +648,80 @@ function user_update_7011() { } /** + * Add the user's pictures to the {file_managed} table and make them managed + * files. + */ +function user_update_7012(&$sandbox) { + + $picture_field = array( + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + 'description' => "Foreign key: {file_managed}.fid of user's picture.", + ); + + if (!isset($sandbox['progress'])) { + // Check that the field hasn't been updated in an aborted run of this + // update. + if (!db_field_exists('users', 'picture_fid')) { + // Add a new field for the fid. + db_add_field('users', 'picture_fid', $picture_field); + } + + // Initialize batch update information. + $sandbox['progress'] = 0; + $sandbox['last_user_processed'] = -1; + $sandbox['max'] = db_query("SELECT COUNT(*) FROM {users} WHERE picture <> ''")->fetchField(); + } + + // As a batch operation move the photos into the {file_managed} table and + // update the {users} records. + $limit = 500; + $result = db_query_range("SELECT uid, picture FROM {users} WHERE picture <> '' AND uid > :uid ORDER BY uid", 0, $limit, array(':uid' => $sandbox['last_user_processed'])); + foreach ($result as $user) { + // Don't bother adding files that don't exist. + if (file_exists($user->picture)) { + + // Check if the file already exists. + $files = file_load_multiple(array(), array('uri' => $user->picture)); + if (count($files)) { + $file = reset($files); + } + else { + // Create a file object. + $file = new stdClass(); + $file->uri = $user->picture; + $file->filename = basename($file->uri); + $file->filemime = file_get_mimetype($file->uri); + $file->uid = $user->uid; + $file->status = FILE_STATUS_PERMANENT; + $file = file_save($file); + } + + db_update('users') + ->fields(array('picture_fid' => $file->fid)) + ->condition('uid', $user->uid) + ->execute(); + } + + // Update our progress information for the batch update. + $sandbox['progress']++; + $sandbox['last_user_processed'] = $user->uid; + } + + // Indicate our current progress to the batch update system. If there's no + // max value then there's nothing to update and we're finished. + $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); + + // When we're finished, drop the old picture field and rename the new one to + // replace it. + if (isset($sandbox['#finished']) && $sandbox['#finished'] == 1) { + db_drop_field('users', 'picture'); + db_change_field('users', 'picture_fid', 'picture', $picture_field); + } +} + +/** * @} End of "defgroup user-updates-6.x-to-7.x" * The next series of updates should start at 8000. */ |