version 0.3.0
[fms.git] / src / freenet / boardlistinserter.cpp
index 6099ff6..69ca362 100644 (file)
@@ -1,6 +1,10 @@
 #include "../../include/freenet/boardlistinserter.h"\r
 #include "../../include/freenet/boardlistxml.h"\r
 \r
+#include <Poco/DateTime.h>\r
+#include <Poco/Timespan.h>\r
+#include <Poco/DateTimeFormatter.h>\r
+\r
 #ifdef XMEM\r
        #include <xmem.h>\r
 #endif\r
@@ -20,19 +24,16 @@ void BoardListInserter::CheckForNeededInsert()
        // only do 1 insert at a time\r
        if(m_inserting.size()==0)\r
        {\r
-               DateTime today;\r
-               DateTime daysback;\r
-               \r
-               today.SetToGMTime();\r
-               daysback.SetToGMTime();\r
+               Poco::DateTime today;\r
+               Poco::DateTime daysback;\r
 \r
-               // 20 days\r
-               daysback.Add(0,0,0,-20);\r
+               // 20 days back\r
+               daysback-=Poco::Timespan(20,0,0,0,0);\r
 \r
                // get identities who posted messages to boards in the past 20 days\r
                SQLite3DB::Statement st=m_db->Prepare("SELECT tblLocalIdentity.LocalIdentityID FROM tblLocalIdentity INNER JOIN tblMessageInserts ON tblLocalIdentity.LocalIdentityID=tblMessageInserts.LocalIdentityID WHERE tblLocalIdentity.PublishBoardList='true' AND (tblLocalIdentity.LastInsertedBoardList<? OR tblLocalIdentity.LastInsertedBoardList IS NULL) AND tblMessageInserts.Day>=? GROUP BY tblLocalIdentity.LocalIdentityID;");\r
-               st.Bind(0,today.Format("%Y-%m-%d"));\r
-               st.Bind(1,daysback.Format("%Y-%m-%d"));\r
+               st.Bind(0,Poco::DateTimeFormatter::format(today,"%Y-%m-%d"));\r
+               st.Bind(1,Poco::DateTimeFormatter::format(daysback,"%Y-%m-%d"));\r
                st.Step();\r
 \r
                if(st.RowReturned())\r
@@ -70,7 +71,7 @@ const bool BoardListInserter::HandlePutFailed(FCPMessage &message)
 \r
 const bool BoardListInserter::HandlePutSuccessful(FCPMessage &message)\r
 {\r
-       DateTime now;\r
+       Poco::DateTime now;\r
        std::vector<std::string> idparts;\r
        long localidentityid;\r
        long index;\r
@@ -85,15 +86,14 @@ const bool BoardListInserter::HandlePutSuccessful(FCPMessage &message)
        st.Bind(2,index);\r
        st.Step();\r
 \r
-       now.SetToGMTime();\r
        st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedBoardList=? WHERE LocalIdentityID=?;");\r
-       st.Bind(0,now.Format("%Y-%m-%d %H:%M:%S"));\r
+       st.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S"));\r
        st.Bind(1,localidentityid);\r
        st.Step();\r
 \r
        RemoveFromInsertList(localidentityid);\r
 \r
-       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"BoardListInserter::HandlePutSuccessful successfully inserted BoardList.");\r
+       m_log->debug("BoardListInserter::HandlePutSuccessful successfully inserted BoardList.");\r
 \r
        return true;\r
 }\r
@@ -105,8 +105,8 @@ void BoardListInserter::Initialize()
 \r
 const bool BoardListInserter::StartInsert(const long &localidentityid)\r
 {\r
-       DateTime daysback;\r
-       DateTime now;\r
+       Poco::DateTime daysback;\r
+       Poco::DateTime now;\r
        BoardListXML xml;\r
        FCPMessage message;\r
        std::string data;\r
@@ -116,14 +116,13 @@ const bool BoardListInserter::StartInsert(const long &localidentityid)
        std::string indexstr="";\r
        std::string localidentityidstr;\r
 \r
-       now.SetToGMTime();\r
-       daysback.SetToGMTime();\r
-       daysback.Add(0,0,0,-20);\r
+       // 20 days back\r
+       daysback-=Poco::Timespan(20,0,0,0,0);\r
 \r
        // get boards\r
        SQLite3DB::Statement st=m_db->Prepare("SELECT BoardName,BoardDescription FROM tblBoard INNER JOIN tblMessageBoard ON tblBoard.BoardID=tblMessageBoard.BoardID INNER JOIN tblMessage ON tblMessageBoard.MessageID=tblMessage.MessageID INNER JOIN tblMessageInserts ON tblMessage.MessageUUID=tblMessageInserts.MessageUUID WHERE tblMessageInserts.LocalIdentityID=? AND tblMessageInserts.Day>=? GROUP BY tblBoard.BoardID;");\r
        st.Bind(0,localidentityid);\r
-       st.Bind(1,daysback.Format("%Y-%m-%d"));\r
+       st.Bind(1,Poco::DateTimeFormatter::format(daysback,"%Y-%m-%d"));\r
        st.Step();\r
 \r
        while(st.RowReturned())\r
@@ -152,7 +151,7 @@ const bool BoardListInserter::StartInsert(const long &localidentityid)
        index=0;\r
        st=m_db->Prepare("SELECT MAX(InsertIndex) FROM tblBoardListInserts WHERE LocalIdentityID=? AND Day=?;");\r
        st.Bind(0,localidentityid);\r
-       st.Bind(1,now.Format("%Y-%m-%d"));\r
+       st.Bind(1,Poco::DateTimeFormatter::format(now,"%Y-%m-%d"));\r
        st.Step();\r
        if(st.RowReturned())\r
        {\r
@@ -169,7 +168,7 @@ const bool BoardListInserter::StartInsert(const long &localidentityid)
        StringFunctions::Convert(localidentityid,localidentityidstr);\r
 \r
        message.SetName("ClientPut");\r
-       message["URI"]=privatekey+m_messagebase+"|"+now.Format("%Y-%m-%d")+"|BoardList|"+indexstr+".xml";\r
+       message["URI"]=privatekey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|BoardList|"+indexstr+".xml";\r
        message["Identifier"]=m_fcpuniquename+"|"+localidentityidstr+"|"+indexstr+"|"+message["URI"];\r
        message["UploadFrom"]="direct";\r
        message["DataLength"]=datasizestr;\r