diff --git a/modules/system/system.install b/modules/system/system.install index df0db71..a9c1503 100644 --- a/modules/system/system.install +++ b/modules/system/system.install @@ -2728,6 +2728,16 @@ function system_update_7061(&$sandbox) { return; } + // Delete stale rows from {upload} where the fid is not in the {files} table. + $connection = Database::getConnection(); + $upload_table_prefix = $connection->tablePrefix('upload'); + $delete_subquery = db_select('files', 'f'); + $delete_subquery->fields('f'); + $delete_subquery->where('f.fid = ' . $upload_table_prefix . 'upload.fid'); + $deleted_upload_files = db_delete('upload') + ->notExists($delete_subquery) + ->execute(); + if (!isset($sandbox['progress'])) { // Retrieve a list of node revisions that have uploaded files attached. // DISTINCT queries are expensive, especially when paged, so we store the