version 0.1.10
[fms.git] / src / freenet / identityinserter.cpp
index 4fac82f..3fabf00 100644 (file)
@@ -80,16 +80,27 @@ const bool IdentityInserter::HandleMessage(FCPMessage &message)
 \r
                if(message.GetName()=="PutSuccessful")\r
                {\r
-                       m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false', LastInsertedIdentity='"+now.Format("%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";");\r
+                       // a little hack here - if we just inserted index yesterday and it is now the next day - we would have inserted todays date not yesterdays as LastInsertedIdentity.\r
+                       // If this is the case, we will skip updating LastInsertedIdentity so that we can insert this identity again for today\r
+                       DateTime lastdate;\r
+                       lastdate.Set(idparts[4]);\r
+                       if(lastdate.GetDay()==now.GetDay())\r
+                       {\r
+                               m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false', LastInsertedIdentity='"+now.Format("%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";");\r
+                       }\r
+                       else\r
+                       {\r
+                               m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false' WHERE LocalIdentityID="+idparts[1]+";");\r
+                       }\r
                        m_db->Execute("INSERT INTO tblLocalIdentityInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");");\r
-                       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" inserted Identity xml");\r
+                       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityInserter::HandleMessage inserted Identity xml");\r
                        return true;\r
                }\r
 \r
                if(message.GetName()=="PutFailed")\r
                {\r
                        m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false' WHERE LocalIdentityID="+idparts[1]+";");\r
-                       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" failure inserting identity xml.  Code="+message["Code"]+" Description="+message["CodeDescription"]);\r
+                       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityInserter::HandleMessage failure inserting Identity xml.  Code="+message["Code"]+" Description="+message["CodeDescription"]);\r
                        \r
                        // if code 9 (collision), then insert index into inserted table\r
                        if(message["Code"]=="9")\r
@@ -172,7 +183,7 @@ void IdentityInserter::StartInsert(const long localidentityid)
                }\r
                StringFunctions::Convert(index,indexstr);\r
 \r
-               Option::instance()->Get("MessageBase",messagebase);\r
+               Option::Instance()->Get("MessageBase",messagebase);\r
 \r
                if(rs.GetField(0))\r
                {\r