Closed (fixed)
Project:
Drupal core
Version:
x.y.z
Component:
file system
Priority:
Critical
Category:
Bug report
Assigned:
Reporter:
Created:
16 Sep 2005 at 00:55 UTC
Updated:
14 Mar 2006 at 18:32 UTC
Jump to comment: Most recent file
I think that the files table has too much redundat data in it since we now have the new revisions system. I think another table to link revisions to files would be more appropriate.
| Comment | File | Size | Author |
|---|---|---|---|
| #56 | drupal-head.file-revisions25.junyor.patch | 14.26 KB | junyor |
| #53 | drupal-head.file-revisions24.junyor.patch | 14.29 KB | junyor |
| #50 | drupal-head.file-revisions23.junyor.patch | 14.05 KB | junyor |
| #48 | drupal-head.file-revisions22.junyor.patch | 13.74 KB | junyor |
| #43 | drupal-head.file-revisions21.junyor.patch | 13.74 KB | junyor |
Comments
Comment #1
junyor commentedI agree. NID and VID should be removed, making a new table containing FID, NID, and VID with all three as keys.
Comment #2
junyor commentedHere's a patch with the proposed changes. This is completely untested. I don't know SQL very well, so I'm sure I've done something wrong. I'll hopefully be able to do testing later today.
Comment #3
junyor commentedUpdated patch:
- cleaned up errors in database.*
- cleaned up errors in update.inc
I tested adding files, listing and unlisting files, deleting files, deleting revisions, deleting nodes, adding files only to certain revisions, etc. Deleting revisions does not delete the files, but as far as I can tell, that's because of http://drupal.org/node/31323.
Comment #4
junyor commentedUpdates after code review from Cvbge (thanks!):
- fixed typo in database.pgsql
- using a select statement in update_148()
- fixed logic in upload_delete()
Comment #5
junyor commentedKeeping up with HEAD.
Comment #6
junyor commentedUpdated again. Now, fuzz free!
Comment #7
Steve Dondley commentedThis seems more like a task than a bug.
Comment #8
junyor commentedThis patch also fixes several broken queries in upload.module.
Comment #9
junyor commentedKeeping up with head.
Comment #10
m3avrck commentedPatch is out of date. Agreed, this functionality would be very useful, the revisions patch was great, but there are lots of new, unforseen issues that need to be dealt with to really make the new revisions system shine.
Comment #11
moshe weitzman commentedAnyone willing to tackly this? Would be nice to clean this up before 4.7.
Comment #12
junyor commentedI'll update it within the next couple of days.
Comment #13
m3avrck commentedExcellent, I'm willing to help out debug/test etc I need this too!
Comment #14
junyor commentedUpdated to HEAD. This patch is untested, as there are some problems with uploads in core that need to be worked out. I'll try to get some testing done tomorrow.
Comment #15
m3avrck commentedOverall code looks good, but until this patch goes in: http://drupal.org/node/37605 gonna be a bit harder to test, as I would deem that one a bit higher priority ;-) But I do very much like this idea...
Comment #16
junyor commentedUpdated again to keep up with HEAD. This patch also includes the following changes from the previous patch:
- Tested and corrected the mysql upgrade path. I attempted to correct the upgrade path for pgsql, but it still needs testing.
- Added a 'delete revision' case to upload_nodeapi to fix the upload.module portion of http://drupal.org/node/31323
- Added upload_delete_revision() to handle revision deletion. I tested this a fair amount.
I tested adding new revisions, changing revisions, deleting revisions, and deleting nodes. I could not test adding new files, as that appears to be broken in HEAD. Everything else seemed to work fine.
Comment #17
junyor commentedActually, there seems to have been a problem when I deleted a node with attachments. I look into it soon.
Comment #18
junyor commentedUpdated to HEAD. Also, I fixed the problem with files not being deleted when nodes were deleted. I also improved the performance of upload_delete a bit.
I still can't get files to upload to nodes. I'll do a fresh checkout and see if it's a problem in my patch or something in CVS (like http://drupal.org/node/37605).
Comment #19
junyor commentedFile uploads don't work without my patch either, so it looks like that'll have to be fixed before I can go any further.
Comment #20
junyor commentedKeeping up with HEAD. Tested a bit more now that file uploads are working and everything seems to work well. I also fixed a bug in the previous patch where upload_delete() wasn't deleting files from old revisions if they weren't in the current revision. I also fixed a bug with removing files from nodes when revisioning was disabled (and removed an unnecessary query in the process).
Comment #21
junyor commentedKeeping up with HEAD.
Comment #22
Cvbge commentedCould you exaplain what this part about "get rid of duplicates in files table" in updates.inc is supposed to do? I'm a bit lost here.
Comment #23
junyor commentedCertainly. This patch removes one of the primary key values, VID, and moves some other data to the file_revisions table. To create the new primary key, FID, we have to get rid of duplicate rows.
Comment #24
Cvbge commentedI didn't understand how revisions work, started asking, and found following issues:
1. can count the same file many times?
2. node_revisions(nid) is used only in following queries, maybe it's not needed in the table?
Comment #25
Cvbge commentedChanges:
1. database.pgsql:
DEFAULT 0, notDEFAULT '0'2. update.inc: postgresql part
Is it possibile that (fid,vid) in old files table is not unique? It had no PK/UNIQUE...
I could not test the patch, as file uploads do not work currently...
Comment #26
m3avrck commentedFIle uploads *do* work with head, a patch went in a few days ago that fixed this. I've been using file uploads on CVS on a live site for a few days now, no problems.
Comment #27
junyor commentedI can change the
default '0's, but most of the rest of database.pgsql is filled with them. It's possible that fid/vid isn't unique, but it shouldn't happen.Comment #28
Cvbge commentedHere's a bit better patch for postgresql update. Also fixes a bug in postgresql update
Indeed, the file uploads work.
I've done some simple test, with the patch applied, and it seems to work.
The only problem is I can't edit not-active node revisions (that's probably has nothing to do with this issue...)
Comment #29
junyor commentedHere's another go at it. Changes from last patch (#11):
- Incorporated Cvbge's changes for pgsql (thanks!).
- Moved nid back to the files table on Cvbge's recommendation. It's not used in the key in file_revisions and doesn't change with revisions, so there was no point for it to be there.
- Corrected the default values in the file and file_revisions table for integers. They should be 0, not '0'. This change will also occur for existing installs.
- Fixed the query in upload_space_used().
- Reordered the logic in upload_save() somewhat. Now there's one foreach loop that handles everything instead of three separate loops.
I'll have to do another round of testing now.
I ran into a problem when changing upload_save(). The upload_nodeapi:validate call at the top of the function only returns new uploads when called from upload_save, not existing uploads. I'm not sure if that's by design or a bug. Note that upload_nodeapi:validate is called from upload_js, upload_nodeapi:update, upload_nodeapi:validate, and _upload_form_alter.
Comment #30
junyor commentedI finally got a chance to do that testing. Here's a new patch, updated to HEAD. This patch also fixes two issues I found:
1) The upgrade patch for mysql was broken
2) Nodes without files couldn't be created
In testing, I also found the following three issue:
1) The list attribute is always (except for #3 below) enabled for new uploads, no matter what the checkbox setting is
2) In JS mode, the list checkbox is checked by default for new uploads. In non-JS mode, it's unchecked by default
3) The list attribute is not set for new uploads if they weren't Attached before the node is Submitted
These issues exist *without* this patch as well, thus they should not stop this patch from hitting Core!
Comment #31
junyor commentedKeeping up with HEAD.
Comment #32
junyor commentedUpdated after some comments on IRC from killes. Fixed some style issues and removed a query change I did, as it removed a node access check.
Comment #33
junyor commentedKeeping up with HEAD.
This is the last patch standing in the way of continued work on http://drupal.org/node/25756.
Furthermore, this patch is the first step in allowing comments/users/etc. to have uploads. After this patch goes in, we can add a "type" column and change "nid" to "id" in the files table and the DB will be ready. In the type column, we put things like "node", "comment", or "user". In the "id" column, we put the nid, cid, or uid, respectively.
Comment #34
m3avrck commentedPatch applies cleanly and I can attach different files to different revisions and they each show up. However, when trying to download files on revisions, I get access denied (as uid=1).
Comment #35
m3avrck commentedThis is with downloads set to 'private'.
Comment #36
m3avrck commentedJust to follow up, if I change modes to 'public' files are correctly downloaded.
However, discovered another problem, if I create some revisions and attach files, then later make a new revision with no files, then later try and revert back an older revision with files attached, the new revision that is created (or copied) doesn't have it's files anymore.
Comment #37
junyor commentedThe last problem you mentioned also exists in HEAD, but I can fix it. m3avrck also mentioned the following issue on IRC: "when you create that new revision with one that has a file attached, the file is still there, however it no longer remembers its 'list' being checked"
Comment #38
junyor commentedHere's a new patch with the following changes for the last:
1) Addressed the problem m3avrck brought up about setting old revisions active
2) Changed some double quotes to single quotes
The problem with private downloads also happens in current HEAD and is unrelated to this patch. I could not reproduce the other problem m3avrck mentioned.
Comment #39
junyor commentedComment #40
m3avrck commentedEverything is working with the latest patch! Did not run into any problems at all. I think before I might have had a bad node with some data, fresh install this time, everything is working great. Tested all sorts of revisions, files, combinations, everything worked as expected!
I say +1 and this is RTC but I won't set it, I'd like to have another set of eyes glance over as well. Additionally, this update should go in before 4.7, as this complements the new revisions system quite well, and opens up a host of new possibilities for modules and patches.
Comment #41
junyor commentedKeeping up with HEAD. I also fixed an error when deleting a node.
Comment #42
dries commentedNeeds to be rerolled. updates.inc changed.
Comment #43
junyor commentedKeeping up with HEAD.
Comment #44
Souvent22 commentedWorked for me with latest HEAD/CVS. Ran through my test I used when patching upload.module, and worked as expected. RTC. +1.
Comment #45
dries commentedI'll commit it when Gerhards tells me so. He gets to be responsible for this issue. :)
Comment #46
killes@www.drop.org commentedI've applied the patch and ran the update. Worked fine.
When I looked at the tables afterwards I noticed that there is no index on nid in the files table. Maybe there should be one.
Also, then I tried to upload a file, it did work. The file is uploaded, the info is stored in the database, but when I edit the node again, no file is shown.
This might be dues to the general brokenness of uploads, but I don't think so.
Setting to "needs work".
Comment #47
junyor commentedm3avrck and I have been unable to reproduce the node edit problem. I did see an issue with the list checkbox[1], but that also exists in current CVS.
FWIW, I tested with and creating a new node revision with public downloads.
[1] The list checkbox never seems to stay checked when the node is submitted if a new upload is attached. It's checked when submitting, but then the file doesn't show. Editing the node, enabling list, and submitting fixes it.
Comment #48
junyor commentedHere's an updated patch that fixes a broken query that killes found. I'll have to do some more testing when I'm not logged in as UID 1, as I haven't done that at all.
Comment #49
junyor commentedI've found two problems in limited testing:
1) List is saved to the database as the FID instead of a BOOL.
2) Sometimes (I haven't figured out when), an row containing no fid, description, or list (i.e. just a vid) will be written to file_revisions
I'm low on time right now and would appreciate help in tracking down these issues so this patch can land ASAP.
Comment #50
junyor commentedUpdated again to HEAD. The list ID saving problem is also in HEAD and should be fixed in a separate patch. I cannot reproduce the blank database row issue. I'll be happy to try to track it down if someone can tell me how to reproduce it. Otherwise, I hope this patch can be committed.
Comment #51
moshe weitzman commentedI added files, created revisions, rolled back, deleted files and all worked well. nice.
I did see the blank row in file_revisions. i tried to reproduce it after seeing once but i was unable. here is what i did
started from scratch. applied patch and update.php
1. created a story with 1 attachment
2. edited same story and added an attachment. created new revision
3. rolled back a revision, so node only has 1 attachment
at this point, i noticed a fid=3 row with no other data in file_revisions table. that record might have been there since step, i don't know. i hope this helps. even if that row is not fixed, i think this is ready to commit.
thanks for sticking with this patch.
Comment #52
junyor commentedMoshe: OK, I was able to reproduce it. It's just some bogus data being added, not a missing file. Now to figure out what's causing it....
Comment #53
junyor commentedI've been able to reliably reproduce the problem, though I don't know how to fix it. Here's how to reproduce it:
1) Edit a node
2) Enable "Create new revision"
3) Enter a file to attach
4) Press Submit without attaching first
There will now be a new entry in file_revisions for the new vid with 0 for fid and list.
As far as I can tell, this is caused by an extra 'upload_N' in $_SESSION inserted by upload_nodeapi:validate. This problem is also present in HEAD, though not visible because of a check for
is_numeric()on line 414 in upload_save(). The problem seems to originate in the following code in upload_nodeapi:validate (starting on line 250 in HEAD):Or, it could be the nonsensical
file_check_upload('upload')on line 210 in HEAD.I'll add a check for is_numeric(), as in HEAD. Keep in mind that this is a work-around and doesn't fix the real problem. And I don't have the expertise to fix the real problem.
Attached is a new patch, updated to HEAD, which includes the is_numeric() change.
Comment #54
junyor commentedThe list problem mentioned in comment #49 is already filed as http://drupal.org/node/42358. The upload_nodeapi:validate problem described in comment #53 is filed as http://drupal.org/node/48092.
Comment #55
moshe weitzman commentedi tested again, and code reviewed.
Comment #56
junyor commentedKeeping up with HEAD.
Comment #57
moshe weitzman commentedComment #58
dries commentedCommitted to HEAD. Thanks.
Comment #59
killes@www.drop.org commentedIs there possibly an error in the update function? The update does not show up on update.php.
Comment #60
Tobias Maier commentedi tried it on four of my (test) drupal installs and it works perfectly...
Comment #61
junyor commentedKilles: What do you mean that it doesn't show up? You run the update script and it says you are up-to-date? That could happen if you've tested a patch that uses the same update number.
Comment #62
killes@www.drop.org commentedI've updated another database and it didn't have the problem. No idea what went wrong with the other db.
Comment #63
m3avrck commentedMaybe I'm misunderstanding the this, but isn't the following code a bit backwards?
It DELETES FROM {file_revisions} all fids that are $key.
However, right below, it then trys to get the count of fid that is $key.
If you already deleted them all, then this will always be 0 and then the file is always removed, when in fact, maybe it shouldn't.
Or am I misunderstanding something here?
Comment #64
m3avrck commentedAh just after posting I noticed the vid part. So that first one is deleting the file as part of that revision and if that file isn't used in any *other* (missing this keyword) then delete.
Ok makes sense.
Comment #65
m3avrck commentedAh just after posting I noticed the vid part. So that first one is deleting the file as part of that revision and if that file isn't used in any *other* (missing this keyword) then delete.
Ok makes sense.
Comment #66
(not verified) commented