If I've created a node and attached a few files, when I goto edit the node and attach another file, the file list disappears. However, after the file is added, all files are still present. I'm guessing the hidden iframe is being overwritten or similar? Problem tested and confirmed in FF.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Souvent22’s picture

Assigned: Unassigned » Souvent22
Status: Active » Needs review
FileSize
1.07 KB

List problem fixed. Please review.

m3avrck’s picture

Status: Needs review » Needs work

Patch does indeed fix this problem.

However, patch needs a bit of work, phantom 0 byte files appear when new revisions are created, and then editing older revisions and attaching files. Almost there, certainly a great fix!

decafdennis’s picture

Title: JS-uploads, file list disappears » File list disappears, changes not remembered on preview
Component: base system » upload.module
Assigned: Souvent22 » decafdennis
Status: Needs work » Needs review
FileSize
1.93 KB

Because it has been a while since the last follow up, I take the liberty of improving Souvent22's patch.

The problem with Souvent22's patch was that the query that selects files by nid returns all files from all revisions. I rewrote this query to only return files from the last revision using an inner join. This seems to fix the phantom 0 byte files problem, as well as the problem of reviving files that were removed in previous revisions.

Another problem that I fixed is that the delete, list and description form fields were not remembered when previewing a node. I don't believe an issue has been posted for this problem yet, so I fitted it into this issue.

decafdennis’s picture

FileSize
2.15 KB

Updated patch, fixed a bug which caused the list checkbox not to be enabled by default.

m3avrck’s picture

Still getting a phantom 0 byte file here.

To reproduce: create a node and attach some files. Save. Then edit this node and attach some more files, creating a revision. Save. Go back and edit this new revision, then you'll see the 0 byte phantom file.

decafdennis’s picture

FileSize
3.47 KB

Yes, you're right. The problem was that new files were attempted to be copied from the previous revision to the new revision in upload_save, so I added a check for that.

I've also changed upload_nodeapi($op = 'view') a bit, so that when one or more delete checkboxes are enabled and you click preview, they don't show up in the node preview anymore.

m3avrck’s picture

Status: Needs review » Reviewed & tested by the community

Patch works! Code does look good to me and I tested thoroughly. Weird phantom files are gone! Should definetly clean up this area. I would say this is ready to commit!

decafdennis’s picture

Nice, thank you! I've also tested it, its even used on a production site, and I have not came across any problems (yet).

killes@www.drop.org’s picture

Version: x.y.z » 4.6.3
Status: Reviewed & tested by the community » Needs review

The new code in upload_load does not make sense to me.

+ // not a revision. You view and/or revert to a revision.
+ if ($node->vid || $node->nid) {

A node either has vid and nid or none of them.

+ if ($node->vid) {
+ $result = db_query("SELECT * FROM {files} WHERE vid = %d", $node->vid);
+ }
+ else {
+ $result = db_query("SELECT f.* FROM {files} f INNER JOIN {node} n ON f.nid = n.nid WHERE f.nid = %d AND f.vid = n.vid", $node->nid);
+ }

Why do you treat those cases differently?

decafdennis’s picture

A node either has vid and nid or none of them.

That is not the case when the node is being edited. Then only the nid is set, and I am certain this is true, because if it weren't true, the second query in the else part would never happen, and it does. Exactly as Souvent22 says in his comment:

When you are editing, you are editing the node not a revision. You view and/or revert to a revision.

decafdennis’s picture

Forgot to add this... what the second query actually does is load the downloads from the last revision.

killes@www.drop.org’s picture

If your statement where true we'd have a more serious bug.

If you create a new node, it will have both vid and nid after you save it. regardless of the revisions setting.
If you then later edit it again, then your loaded node object shoudl have both vid and nid. teh difference between "revisions on" and "revisions off" is that in the first case you will get a _new_ vid for the next revision which will be the current version ID for all further node_loads.

decafdennis’s picture

Title: File list disappears, changes not remembered on preview » File changes not remembered on postback
FileSize
2.78 KB

You are very right, this is a serious bug in node.module indeed! Only the nid is remembered at postback through a hidden form field, but vid is not. I've submitted an issue (http://drupal.org/node/33209).

But the other fixes to the upload module still stand, like the improved behavior when previewing a node. Updated patch attached.

m3avrck’s picture

Status: Needs review » Reviewed & tested by the community

Sounds good to me! This patch and the other patch are definetly needed, this is one the most annoying problems I've encountered with HEAD thus far. Let's get this in code still is good to me.

m3avrck’s picture

Version: 4.6.3 » x.y.z

This is a problem with HEAD not 4.6.3.

decafdennis’s picture

Assigned: decafdennis » Unassigned
Status: Reviewed & tested by the community » Needs work

There have been some significant changes in the upload module's code, mostly because of the new forms api. The patch should therefore be remade. Unfortunately, I am not using the newest CVS yet because of the forms api changes, so I am not really into the new forms api and someone else should adapt my patch. Thank you.

Dries’s picture

This might be fixed in CVS HEAD thanks to a patch being committed 2 minutes ago. Please verify and update this issue accordingly. Thanks. Looks like a 100% different patch though.

m3avrck’s picture

Yes, patch is still needed. Once you create a node and attach a few files, if you go back and edit the node and try to attach more, the previous files are overwritten until you hit submit, in which case the new files and old files show up.

m3avrck’s picture

Status: Needs work » Closed (duplicate)

Marking this a duplicate of this new patch, updated to latest CVS: http://drupal.org/node/39358

m3avrck’s picture

FileSize
4.93 KB

Here's a better patch that removes some uncessary security logic (called twice in a row).

m3avrck’s picture

Crap, wrong thread!