diff --git a/include/message/Message.php b/include/message/Message.php index fa9ebc498..bc1bfcbe5 100644 --- a/include/message/Message.php +++ b/include/message/Message.php @@ -4604,13 +4604,14 @@ public function autoRepostGroup($type, $mindate, $groupid = NULL, $msgid = NULL) INNER JOIN users ON messages.fromuser = users.id INNER JOIN memberships ON memberships.userid = messages.fromuser AND memberships.groupid = messages_groups.groupid LEFT OUTER JOIN messages_outcomes ON messages.id = messages_outcomes.msgid -LEFT OUTER JOIN messages_promises ON messages_promises.msgid = messages.id +LEFT OUTER JOIN messages_promises ON messages_promises.msgid = messages.id WHERE messages_groups.arrival > ? AND messages_groups.groupid = ? AND messages_groups.collection = 'Approved' AND messages_outcomes.msgid IS NULL AND messages_promises.msgid IS NULL AND messages.type IN ('Offer', 'Wanted') AND messages.source = ? AND messages.deleted IS NULL AND (memberships.ourPostingStatus IS NULL OR memberships.ourPostingStatus != ?) - AND users.deleted IS NULL $msgq;"; + AND users.deleted IS NULL $msgq + AND (messages.deadline IS NULL OR messages.deadline > DATE(NOW()));"; #error_log("$sql, $mindate, {$group['id']}"); $messages = $this->dbhr->preQuery($sql, [ $mindate, diff --git a/test/ut/php/include/MessageTest.php b/test/ut/php/include/MessageTest.php index f36fe3d78..48b090795 100644 --- a/test/ut/php/include/MessageTest.php +++ b/test/ut/php/include/MessageTest.php @@ -1138,5 +1138,39 @@ public function testDeadline() { ] ], $outcomes); } + + public function testDeadlineRepost() { + $m = new Message($this->dbhr, $this->dbhm); + + $email = 'ut-' . rand() . '@' . USER_DOMAIN; + $this->user->addEmail($email); + + $msg = $this->unique(file_get_contents(IZNIK_BASE . '/test/ut/php/msgs/basic')); + $msg = str_replace('test@test.com', $email, $msg); + $msg = str_replace('Basic test', 'OFFER: Test not due (Tuvalu High Street)', $msg); + $msg = str_ireplace('freegleplayground', 'testgroup', $msg); + + $r = new MailRouter($this->dbhr, $this->dbhm); + $email = 'ut-' . rand() . '@' . USER_DOMAIN; + $this->user->addEmail($email); + list ($id1, $failok) = $r->received(Message::EMAIL, $email, 'to@test.com', $msg); + $m = new Message($this->dbhr, $this->dbhm, $id1); + $m->setPrivate('source', Message::PLATFORM); + $rc = $r->route(); + $this->assertEquals(MailRouter::APPROVED, $rc); + + $deadline = '2016-01-01'; + $m->setPrivate('deadline', $deadline); + + $this->log("Expect repost"); + $mysqltime = date("Y-m-d H:i:s", strtotime('77 hours ago')); + $this->dbhm->preExec("UPDATE messages_groups SET arrival = '$mysqltime' WHERE msgid = ?;", [ $id1 ]); + $this->dbhm->preExec("UPDATE messages_groups SET lastautopostwarning = '2016-01-01' WHERE msgid = ?;", [ $id1 ]); + + # No autorepost because past deadline. + list ($count, $warncount) = $m->autoRepostGroup(Group::GROUP_FREEGLE, '2016-01-01', $this->gid); + $this->assertEquals(0, $count); + $this->assertEquals(0, $warncount); + } }