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

CommentFileSizeAuthor
private_upload.patch705 bytesiokevins

Comments

iokevins’s picture

Status: Active » Needs review
starbow’s picture

Status: Needs review » Reviewed & tested by the community

Good explanation of the problem and good fix. I will include it in the next roll out.

starbow’s picture

Status: Reviewed & tested by the community » Fixed

committed to beta5

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.