<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
 name="City"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
 name="place"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 77.95pt 1.0in 77.95pt;}
div.Section1
        {page:Section1;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>I am working on an enhancement to the filedepot module for a multifile
uploader - drag &amp; 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 <o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>The filedepot_folder is a node and the files are attachments - using
the filefield CCK widget.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><em><i><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>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)</span></font></i></em><o:p></o:p></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><em><i><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>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)</span></font></i></em> <o:p></o:p></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'>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.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 face="Courier New"><span style='font-size:
10.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'>$node = node_load($file-&gt;nid, NULL,
TRUE);<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'>$field =
content_fields('field_filedepot_file', 'filedepot_folder');<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'>$validators =
filefield_widget_upload_validators($field);<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'>$nodefile =
field_file_save_file($file-&gt;tmp_name, $validators, $this-&gt;tmp_storage_path);<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'>// Need to populate the CCK fields for the
filefield field - so node_save will update the CCK field<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'>$node-&gt;field_filedepot_file[] =
$nodefile;<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'>node_save($node);<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'>// Clear CCK data cache so the new value
will be loaded for display purposes<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'>cache_clear_all('content:' . $node-&gt;nid
. ':' . $node-&gt;vid, 'cache_content');<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'>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.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'>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.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'>I initially thought it was a CCK cache
issue but adding the cache_clear has not removed the issue.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'>Any ideas or suggestions as to the source
of this issue and how to solve it.<o:p></o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoPlainText><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;color:black'>Thanks!<o:p></o:p></span></font></p>

<p class=MsoPlainText><st1:City w:st="on"><st1:place w:st="on"><font size=2
  color=black face="Courier New"><span style='font-size:10.0pt;color:black'>Blaine</span></font></st1:place></st1:City><font
color=black><span style='color:black'> <o:p></o:p></span></font></p>

</div>

</body>

</html>