function finish($id = 0, $cancel = false, $test = false)
{
global $pommo;
$dbo =& Pommo::$_dbo;
$status = $cancel ? 2 : 0;
$query = "\n DELETE FROM " . $dbo->table['mailing_current'] . "\n WHERE current_id=%i";
$query = $dbo->prepare($query, array($id));
if ($dbo->affected($query) < 1) {
return false;
}
if ($test) {
// remove if this was a test mailing
// remove all notices
Pommo_Mail_Ctl::delNotices($id, 0);
// remove mailing from DB
$query = "\n DELETE FROM " . $dbo->table['mailings'] . "\n WHERE mailing_id=%i";
$query = $dbo->prepare($query, array($id));
} else {
// shorten notices to last 50
Pommo_Mail_Ctl::delNotices($id);
// update mailing in DB
$query = "\n UPDATE " . $dbo->table['mailings'] . "\n SET\n finished=FROM_UNIXTIME(%i),\n status=%i,\n sent=(SELECT count(subscriber_id) FROM " . $dbo->table['queue'] . " WHERE status > 0)\n WHERE mailing_id=%i";
$query = $dbo->prepare($query, array(time(), $status, $id));
}
if (!$dbo->query($query)) {
return false;
}
return true;
}