Skip to content

Commit

Permalink
Don't autorepost if past deadline.
Browse files Browse the repository at this point in the history
  • Loading branch information
edwh committed Dec 9, 2024
1 parent 00466f7 commit 1c47ed1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/message/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 34 additions & 0 deletions test/ut/php/include/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('[email protected]', $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, '[email protected]', $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);
}
}

0 comments on commit 1c47ed1

Please sign in to comment.