Migrate function fails with poor error info due to incorrect query - patch attached, also adds watchdog support

agiliter - September 19, 2008 - 14:10
Project:Private Upload
Version:6.x-1.0-rc2
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:patch (to be ported)
Description

function _private_upload_migrate_private()

reports following problem...

user warning: Unknown column 'f.nid' in 'where clause' query: SELECT f.* FROM files f, node_access na WHERE f.nid = na.nid AND na.gid != 0 AND f.filepath NOT REGEXP "^uploads/private" GROUP BY f.fid in /users/home/progfrog/domains/photoremake.com/web/public/sites/all/modules/private_upload/private_upload.module on line 586.

... on the admin/user page.

The private upload configuration page at admin/settings/private_upload
reported: "There are 3 public files attached to private nodes. Click here to make them all private."

I clicked on the link, but the migration never went through. Instead the above error turned up.

I am not familiar with the code, but apparently there is no nid field in the file table; nid field that is used in the where clause.

#1

jvieille - October 26, 2008 - 09:16

Probably the same problem for me, though somewhat different behaviour

I went to enabling Private Upload after installing this module for the first time while upgrading to D6.6
The process went successfully

I was happy seing several green notices and reading the following:
"There are 98 public files attached to private nodes. Click here to make them all private."

I clicked but only got a white page (no warning at this time). Nothing changed on the server, the files/private directory contains only 2 iles ".htaccess" and "privacy_test.txt"
Going back to the admin/settings/private_upload page, I got this warning:

"user warning: Unknown column 'f.nid' in 'where clause' query: SELECT f.* FROM files f, node_access na WHERE f.nid = na.nid AND na.gid != 0 AND f.filepath NOT REGEXP "^sites/default/files/private" GROUP BY f.fid in /home/psynapse/public_html/controlchaingroup/sites/all/modules/private_upload-6.x-1.0-rc2/private_upload/private_upload.module on line 586."

Refreshing the page makes the warning wanished

Hope this helps

#2

rimu - October 14, 2009 - 00:34

around line 585, change this

  $result = db_query('SELECT f.* FROM {files} f, {node_access} na '.
                     ' WHERE f.nid = na.nid AND na.gid != 0 AND f.filepath NOT REGEXP "^%s" '.
                     ' GROUP BY f.fid', $private_path  );

to this
  $result = db_query('SELECT f.* FROM {files} f inner join {upload} u on f.fid = u.fid INNER JOIN {node_access} na ON u.nid = na.nid '.
                     ' WHERE na.gid != 0 AND f.filepath NOT REGEXP "^%s" '.
                     ' GROUP BY f.fid', $private_path  );

#3

alexharries - October 22, 2009 - 16:50
Title:Private upload migrate problem.» Migrate function fails with poor error info due to incorrect query - patch attached, also adds watchdog support
Status:active» patch (to be ported)

** EEP: don't apply this patch - I haven't tested it fully - see my next post instead please! **

Attached is a patch which should hopefully fix this issue (see http://drupal.org/patch/apply to find out how to apply this patch to an existing install, if you want to try it, but I wouldn't recommend using this on a live system! ;o).

/al

AttachmentSize
private_upload_migrate_patch.patch 4.36 KB
 
 

Drupal is a registered trademark of Dries Buytaert.