function repeatMessage($msgid) { # if (!USE_REPETITION && !USE_RSS) return; # get the future embargo, either "repeat" minutes after the old embargo # or "repeat" after this very moment to make sure that we're not sending the # message every time running the queue when there's no embargo set. $msgdata = Sql_Fetch_Array_Query(sprintf('select *,date_add(embargo,interval repeatinterval minute) as newembargo, date_add(now(),interval repeatinterval minute) as newembargo2, date_add(embargo,interval repeatinterval minute) > now() as isfuture from %s where id = %d and repeatuntil > now()', $GLOBALS["tables"]["message"], $msgid)); if (!$msgdata["id"] || !$msgdata["repeatinterval"]) { return; } # copy the new message Sql_Query(sprintf(' insert into %s (entered) values(now())', $GLOBALS["tables"]["message"])); $id = Sql_Insert_id(); require dirname(__FILE__) . '/structure.php'; if (!is_array($DBstruct["message"])) { logEvent("Error including structure when trying to duplicate message {$msgid}"); return; } foreach ($DBstruct["message"] as $column => $rec) { if ($column != "id" && $column != "entered" && $column != "sendstart") { Sql_Query(sprintf('update %s set %s = "%s" where id = %d', $GLOBALS["tables"]["message"], $column, addslashes($msgdata[$column]), $id)); } } $req = Sql_Query(sprintf('select * from %s where id = %d', $GLOBALS['tables']['messagedata'], $msgid)); while ($row = Sql_Fetch_Array($req)) { Sql_Query(sprintf('insert into %s (name,id,data) values("%s",%d,"%s")', $GLOBALS['tables']['messagedata'], $row['name'], $id, addslashes($row['data']))); } # check whether the new embargo is not on an exclusion if (is_array($GLOBALS["repeat_exclude"])) { $repeatinterval = $msgdata["repeatinterval"]; $loopcnt = 0; while (excludedDateForRepetition($msgdata["newembargo"])) { $repeatinterval += $msgdata["repeatinterval"]; $loopcnt++; $msgdata = Sql_Fetch_Array_Query(sprintf('select *,date_add(embargo,interval %d minute) as newembargo, date_add(now(),interval %d minute) as newembargo2, date_add(embargo,interval %d minute) > now() as isfuture from %s where id = %d and repeatuntil > now()', $repeatinterval, $repeatinterval, $repeatinterval, $GLOBALS["tables"]["message"], $msgid)); if ($loopcnt > 15) { logEvent("Unable to find new embargo date too many exclusions? for message {$msgid}"); return; } } } # correct some values if (!$msgdata["isfuture"]) { $msgdata["newembargo"] = $msgdata["newembargo2"]; } Sql_Query(sprintf('update %s set embargo = "%s",status = "submitted",sent = "" where id = %d', $GLOBALS["tables"]["message"], $msgdata["newembargo"], $id)); // bug 0009687: maybe add "ashtml","astextandhtml" and put them in ashtml? foreach (array("processed", "astext", "ashtml", "astextandhtml", "aspdf", "astextandpdf", "viewed", "bouncecount") as $item) { Sql_Query(sprintf('update %s set %s = 0 where id = %d', $GLOBALS["tables"]["message"], $item, $id)); } # lists $req = Sql_Query(sprintf('select listid from %s where messageid = %d', $GLOBALS["tables"]["listmessage"], $msgid)); while ($row = Sql_Fetch_Row($req)) { Sql_Query(sprintf('insert into %s (messageid,listid,entered) values(%d,%d,now())', $GLOBALS["tables"]["listmessage"], $id, $row[0])); } # attachments $req = Sql_Query(sprintf('select * from %s,%s where %s.messageid = %d and %s.attachmentid = %s.id', $GLOBALS["tables"]["message_attachment"], $GLOBALS["tables"]["attachment"], $GLOBALS["tables"]["message_attachment"], $msgid, $GLOBALS["tables"]["message_attachment"], $GLOBALS["tables"]["attachment"])); while ($row = Sql_Fetch_Array($req)) { if (is_file($row["remotefile"])) { # if the "remote file" is actually local, we want to refresh the attachment, so we set # filename to nothing $row["filename"] = ""; } Sql_Query(sprintf('insert into %s (filename,remotefile,mimetype,description,size) values("%s","%s","%s","%s",%d)', $GLOBALS["tables"]["attachment"], addslashes($row["filename"]), addslashes($row["remotefile"]), addslashes($row["mimetype"]), addslashes($row["description"]), $row["size"])); $attid = Sql_Insert_id(); Sql_Query(sprintf('insert into %s (messageid,attachmentid) values(%d,%d)', $GLOBALS["tables"]["message_attachment"], $id, $attid)); } logEvent("Message {$msgid} was successfully rescheduled as message {$id}"); }
function repeatMessage($msgid) { # if (!USE_REPETITION && !USE_rss) return; $data = loadMessageData($msgid); ## do not repeat when it has already been done if ($data['repeatinterval'] == 0 || !empty($data['repeatedid'])) { return; } # calculate the future embargo, a multiple of repeatinterval minutes after the current embargo $msgdata = Sql_Fetch_Array_Query(sprintf('SELECT *, embargo + INTERVAL (FLOOR(TIMESTAMPDIFF(MINUTE, embargo, GREATEST(embargo, NOW())) / repeatinterval) + 1) * repeatinterval MINUTE AS newembargo FROM %s WHERE id = %d AND now() < repeatuntil', $GLOBALS['tables']['message'], $msgid)); if (!$msgdata) { logEvent("Message {$msgid} not repeated due to reaching the repeatuntil date"); return; } # check whether the new embargo is not on an exclusion if (isset($GLOBALS['repeat_exclude']) && is_array($GLOBALS['repeat_exclude'])) { $loopcnt = 0; while (excludedDateForRepetition($msgdata['newembargo'])) { if (++$loopcnt > 15) { logEvent("Unable to find new embargo date too many exclusions? for message {$msgid}"); return; } $result = Sql_Fetch_Array_Query(sprintf("SELECT '%s' + INTERVAL repeatinterval MINUTE AS newembargo\n FROM %s\n WHERE id = %d", $msgdata['newembargo'], $GLOBALS['tables']['message'], $msgid)); $msgdata['newembargo'] = $result['newembargo']; } } # copy the new message Sql_Query(sprintf(' insert into %s (entered) values(now())', $GLOBALS['tables']['message'])); $newid = Sql_Insert_id(); require dirname(__FILE__) . '/structure.php'; if (!is_array($DBstruct['message'])) { logEvent("Error including structure when trying to duplicate message {$msgid}"); return; } foreach ($DBstruct['message'] as $column => $rec) { if ($column != 'id' && $column != 'entered' && $column != 'sendstart') { Sql_Query(sprintf('update %s set %s = "%s" where id = %d', $GLOBALS['tables']['message'], $column, addslashes($msgdata[$column]), $newid)); } } $req = Sql_Query(sprintf("SELECT *\n FROM %s\n WHERE id = %d AND name NOT IN ('id')", $GLOBALS['tables']['messagedata'], $msgid)); while ($row = Sql_Fetch_Array($req)) { setMessageData($newid, $row['name'], $row['data']); } Sql_Query(sprintf('update %s set embargo = "%s",status = "submitted",sent = "" where id = %d', $GLOBALS['tables']['message'], $msgdata['newembargo'], $newid)); list($e['year'], $e['month'], $e['day'], $e['hour'], $e['minute'], $e['second']) = sscanf($msgdata['newembargo'], '%04d-%02d-%02d %02d:%02d:%02d'); unset($e['second']); setMessageData($newid, 'embargo', $e); foreach (array('processed', 'astext', 'ashtml', 'astextandhtml', 'aspdf', 'astextandpdf', 'viewed', 'bouncecount') as $item) { Sql_Query(sprintf('update %s set %s = 0 where id = %d', $GLOBALS['tables']['message'], $item, $newid)); } # lists $req = Sql_Query(sprintf('select listid from %s where messageid = %d', $GLOBALS['tables']['listmessage'], $msgid)); while ($row = Sql_Fetch_Row($req)) { Sql_Query(sprintf('insert into %s (messageid,listid,entered) values(%d,%d,now())', $GLOBALS['tables']['listmessage'], $newid, $row[0])); } # attachments $req = Sql_Query(sprintf('select * from %s,%s where %s.messageid = %d and %s.attachmentid = %s.id', $GLOBALS['tables']['message_attachment'], $GLOBALS['tables']['attachment'], $GLOBALS['tables']['message_attachment'], $msgid, $GLOBALS['tables']['message_attachment'], $GLOBALS['tables']['attachment'])); while ($row = Sql_Fetch_Array($req)) { if (is_file($row['remotefile'])) { # if the "remote file" is actually local, we want to refresh the attachment, so we set # filename to nothing $row['filename'] = ''; } Sql_Query(sprintf('insert into %s (filename,remotefile,mimetype,description,size) values("%s","%s","%s","%s",%d)', $GLOBALS['tables']['attachment'], addslashes($row['filename']), addslashes($row['remotefile']), addslashes($row['mimetype']), addslashes($row['description']), $row['size'])); $attid = Sql_Insert_id(); Sql_Query(sprintf('insert into %s (messageid,attachmentid) values(%d,%d)', $GLOBALS['tables']['message_attachment'], $newid, $attid)); } logEvent("Message {$msgid} was successfully rescheduled as message {$newid}"); ## remember we duplicated, in order to avoid doing it again (eg when requeuing) setMessageData($msgid, 'repeatedid', $newid); if (getConfig('pqchoice') == 'phplistdotcom') { activateRemoteQueue(); } }
function repeatMessage($msgid) { # if (!USE_REPETITION && !USE_rss) return; $data = loadMessageData($msgid); ## do not repeat when it has already been done if (!empty($data['repeatedid'])) { return; } # get the future embargo, either "repeat" minutes after the old embargo # or "repeat" after this very moment to make sure that we're not sending the # message every time running the queue when there's no embargo set. $msgdata = Sql_Fetch_Array_Query(sprintf('select *,date_add(embargo,interval repeatinterval minute) as newembargo, date_add(now(),interval repeatinterval minute) as newembargo2, date_add(embargo,interval repeatinterval minute) > now() as isfuture from %s where id = %d and repeatuntil > now()', $GLOBALS["tables"]["message"], $msgid)); if (!$msgdata["id"] || !$msgdata["repeatinterval"]) { return; } # copy the new message $query = ' insert into ' . $GLOBALS['tables']['message'] . ' (entered)' . ' values' . ' (current_timestamp)'; Sql_Query($query); $newid = Sql_Insert_Id($GLOBALS['tables']['message'], 'id'); require dirname(__FILE__) . '/structure.php'; if (!is_array($DBstruct["message"])) { logEvent("Error including structure when trying to duplicate message {$msgid}"); return; } foreach ($DBstruct["message"] as $column => $rec) { if ($column != "id" && $column != "entered" && $column != "sendstart") { Sql_Query(sprintf('update %s set %s = "%s" where id = %d', $GLOBALS["tables"]["message"], $column, addslashes($msgdata[$column]), $newid)); } } $req = Sql_Query(sprintf('select * from %s where id = %d', $GLOBALS['tables']['messagedata'], $msgid)); while ($row = Sql_Fetch_Array($req)) { setMessageData($newid, $row['name'], $row['data']); } # check whether the new embargo is not on an exclusion if (isset($GLOBALS["repeat_exclude"]) && is_array($GLOBALS["repeat_exclude"])) { $repeatinterval = $msgdata["repeatinterval"]; $loopcnt = 0; while (excludedDateForRepetition($msgdata["newembargo"])) { $repeat += $msgdata["repeatinterval"]; $loopcnt++; $msgdata = Sql_Fetch_Array_Query(sprintf('select *,date_add(embargo,interval %d minute) as newembargo, date_add(current_timestamp,interval %d minute) as newembargo2, date_add(embargo,interval %d minute) > current_timestamp as isfuture from %s where id = %d and repeatuntil > current_timestamp', $repeatinterval, $repeatinterval, $repeatinterval, $GLOBALS["tables"]["message"], $msgid)); if ($loopcnt > 15) { logEvent("Unable to find new embargo date too many exclusions? for message {$msgid}"); return; } } } # correct some values if (!$msgdata["isfuture"]) { $msgdata["newembargo"] = $msgdata["newembargo2"]; } Sql_Query(sprintf('update %s set embargo = "%s",status = "submitted",sent = "" where id = %d', $GLOBALS["tables"]["message"], $msgdata["newembargo"], $newid)); list($e['year'], $e['month'], $e['day'], $e['hour'], $e['minute'], $e['second']) = sscanf($msgdata["newembargo"], '%04d-%02d-%02d %02d:%02d:%02d'); unset($e['second']); setMessageData($newid, 'embargo', $e); foreach (array("processed", "astext", "ashtml", "astextandhtml", "aspdf", "astextandpdf", "viewed", "bouncecount") as $item) { Sql_Query(sprintf('update %s set %s = 0 where id = %d', $GLOBALS["tables"]["message"], $item, $newid)); } # lists $req = Sql_Query(sprintf('select listid from %s where messageid = %d', $GLOBALS["tables"]["listmessage"], $msgid)); while ($row = Sql_Fetch_Row($req)) { Sql_Query(sprintf('insert into %s (messageid,listid,entered) values(%d,%d,current_timestamp)', $GLOBALS["tables"]["listmessage"], $newid, $row[0])); } # attachments $req = Sql_Query(sprintf('select * from %s,%s where %s.messageid = %d and %s.attachmentid = %s.id', $GLOBALS["tables"]["message_attachment"], $GLOBALS["tables"]["attachment"], $GLOBALS["tables"]["message_attachment"], $msgid, $GLOBALS["tables"]["message_attachment"], $GLOBALS["tables"]["attachment"])); while ($row = Sql_Fetch_Array($req)) { if (is_file($row["remotefile"])) { # if the "remote file" is actually local, we want to refresh the attachment, so we set # filename to nothing $row["filename"] = ""; } Sql_Query(sprintf('insert into %s (filename,remotefile,mimetype,description,size) values("%s","%s","%s","%s",%d)', $GLOBALS["tables"]["attachment"], addslashes($row["filename"]), addslashes($row["remotefile"]), addslashes($row["mimetype"]), addslashes($row["description"]), $row["size"])); $attid = Sql_Insert_Id($GLOBALS['tables']['attachment'], 'id'); Sql_Query(sprintf('insert into %s (messageid,attachmentid) values(%d,%d)', $GLOBALS["tables"]["message_attachment"], $newid, $attid)); } logEvent("Message {$msgid} was successfully rescheduled as message {$newid}"); ## remember we duplicated, in order to avoid doing it again (eg when requeuing) setMessageData($msgid, 'repeatedid', $newid); }