MySQL server info:
-- MySQL Server version: 5.0.24
-- PHP Version: 4.4.7
relevant contents of table files:
INSERT INTO `files` (`fid`, `nid`, `filename`, `filepath`, `filemime`, `filesize`) VALUES
(13, 15, 'testing.txt', 'files/testing.txt', 'application/x-txt', 0);
relevant contents of table node_access:
INSERT INTO `node_access` (`nid`, `gid`, `realm`, `grant_view`, `grant_update`, `grant_delete`) VALUES
(15, 3, 'term_access', 1, 1, 1),
(15, 5, 'term_access', 1, 1, 1),
(15, 7, 'term_access', 1, 0, 0);
When I run function migrate_private() from page http://yourserver.com/admin/settings/private_upload, I receive errors:
* The selected file could not be copied, because no file by that name exists. Please check that you supplied the correct filename.
* The selected file could not be copied, because no file by that name exists. Please check that you supplied the correct filename.Making testing.txt private
Could not move files/testing.txt to private directory
Could not move files/testing.txt to private directory
Function private_upload::_private_upload_migrate_private() contains this query (line 524):
$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"', $private_path );
which returns multiple records when multiple roles in node_access reference the same nid. What seems to happen is the first record in the result set succeeds, but the remaining records fail as the file has been moved into $private_path.
I solved this issue by adding a GROUP BY clause to the query:
$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 );
which groups by fid and reduces the issue to one row per fid. I attached a patch that shows this.
Peace
| Comment | File | Size | Author |
|---|---|---|---|
| private_upload.patch | 705 bytes | iokevins |
Comments
Comment #1
iokevins commentedComment #2
starbow commentedGood explanation of the problem and good fix. I will include it in the next roll out.
Comment #3
starbow commentedcommitted to beta5
Comment #4
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.