I am working on an enhancement to the filedepot module for a multifile
uploader - drag & drop files to a hotspot on the browser. It was all
working nicely but now consistently getting duplicate entry errors in both the
node_access and the CCK table
The filedepot_folder is a node and the files are attachments - using
the filefield CCK widget.
Duplicate entry '16-0-all'
for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view,
grant_update, grant_delete) VALUES (16, 'all';, 0, 1, 0, 0)
Duplicate entry '16-1' for
key 1 query: INSERT INTO content_field_filedepot_file (vid, nid, delta,
field_filedepot_file_fid, field_filedepot_file_list, field_filedepot_file_data)
VALUES (16, 16, 1, 234, NULL, NULL)
I've stripped the module code down to only the following and modules
HOOK_nodeapi is just doing a return so no other code in filedepot should be
involved.
$node = node_load($file->nid, NULL,
TRUE);
$field =
content_fields('field_filedepot_file', 'filedepot_folder');
$validators =
filefield_widget_upload_validators($field);
$nodefile =
field_file_save_file($file->tmp_name, $validators, $this->tmp_storage_path);
// Need to populate the CCK fields for the
filefield field - so node_save will update the CCK field
$node->field_filedepot_file[] =
$nodefile;
node_save($node);
// Clear CCK data cache so the new value
will be loaded for display purposes
cache_clear_all('content:' . $node->nid
. ':' . $node->vid, 'cache_content');
I was suspecting a race condition as the
files I'm uploading are small test files and thought the node_save was not
completed before another update was attempted but attempts to remove this
potential race condition still cause the same issue.
Often the first 2 or 3 files get attached
just fine to the folder node and then the next file triggers the SQL error then
a few more may save ok and then SQL error but the pattern is not consistent.
I initially thought it was a CCK cache
issue but adding the cache_clear has not removed the issue.
Any ideas or suggestions as to the source
of this issue and how to solve it.
Thanks!