* @param integer $limit The maximum number of articles by digest.
* @return boolean Return false if digests are not enabled.
*/
- static function send_headlines_digests($debug = false) {
-
- require_once 'classes/ttrssmailer.php';
+ static function send_headlines_digests() {
$user_limit = 15; // amount of users to process (e.g. emails to send out)
$limit = 1000; // maximum amount of headlines to include
- if ($debug) _debug("Sending digests, batch of max $user_limit users, headline limit = $limit");
+ Debug::log("Sending digests, batch of max $user_limit users, headline limit = $limit");
if (DB_TYPE == "pgsql") {
- $interval_query = "last_digest_sent < NOW() - INTERVAL '1 days'";
+ $interval_qpart = "last_digest_sent < NOW() - INTERVAL '1 days'";
} else if (DB_TYPE == "mysql") {
- $interval_query = "last_digest_sent < DATE_SUB(NOW(), INTERVAL 1 DAY)";
+ $interval_qpart = "last_digest_sent < DATE_SUB(NOW(), INTERVAL 1 DAY)";
}
- $result = db_query("SELECT id,email FROM ttrss_users
- WHERE email != '' AND (last_digest_sent IS NULL OR $interval_query)");
+ $pdo = Db::pdo();
+
+ $res = $pdo->query("SELECT id,email FROM ttrss_users
+ WHERE email != '' AND (last_digest_sent IS NULL OR $interval_qpart)");
- while ($line = db_fetch_assoc($result)) {
+ while ($line = $res->fetch()) {
if (@get_pref('DIGEST_ENABLE', $line['id'], false)) {
$preferred_ts = strtotime(get_pref('DIGEST_PREFERRED_TIME', $line['id'], '00:00'));
time() - $preferred_ts <= 7200
) {
- if ($debug) _debug("Sending digest for UID:" . $line['id'] . " - " . $line["email"]);
+ Debug::log("Sending digest for UID:" . $line['id'] . " - " . $line["email"]);
$do_catchup = get_pref('DIGEST_CATCHUP', $line['id'], false);
if ($headlines_count > 0) {
- $mail = new ttrssMailer();
+ $mailer = new Mailer();
- $rc = $mail->quickMail($line["email"], $line["login"], DIGEST_SUBJECT, $digest, $digest_text);
+ //$rc = $mail->quickMail($line["email"], $line["login"], DIGEST_SUBJECT, $digest, $digest_text);
- if (!$rc && $debug) _debug("ERROR: " . $mail->ErrorInfo);
+ $rc = $mailer->mail(["to_name" => $line["login"],
+ "to_address" => $line["email"],
+ "subject" => DIGEST_SUBJECT,
+ "message" => $digest_text,
+ "message_html" => $digest]);
- if ($debug) _debug("RC=$rc");
+ //if (!$rc && $debug) Debug::log("ERROR: " . $mailer->lastError());
+
+ Debug::log("RC=$rc");
if ($rc && $do_catchup) {
- if ($debug) _debug("Marking affected articles as read...");
+ Debug::log("Marking affected articles as read...");
Article::catchupArticlesById($affected_ids, 0, $line["id"]);
}
} else {
- if ($debug) _debug("No headlines");
+ Debug::log("No headlines");
}
- db_query("UPDATE ttrss_users SET last_digest_sent = NOW()
- WHERE id = " . $line["id"]);
+ $sth = $pdo->prepare("UPDATE ttrss_users SET last_digest_sent = NOW()
+ WHERE id = ?");
+ $sth->execute([$line["id"]]);
}
}
}
- if ($debug) _debug("All done.");
+ Debug::log("All done.");
}
$affected_ids = array();
+ $days = (int) $days;
+
if (DB_TYPE == "pgsql") {
- $interval_query = "ttrss_entries.date_updated > NOW() - INTERVAL '$days days'";
+ $interval_qpart = "ttrss_entries.date_updated > NOW() - INTERVAL '$days days'";
} else if (DB_TYPE == "mysql") {
- $interval_query = "ttrss_entries.date_updated > DATE_SUB(NOW(), INTERVAL $days DAY)";
+ $interval_qpart = "ttrss_entries.date_updated > DATE_SUB(NOW(), INTERVAL $days DAY)";
}
- $result = db_query("SELECT ttrss_entries.title,
+ $pdo = Db::pdo();
+
+ $sth = $pdo->prepare("SELECT ttrss_entries.title,
ttrss_feeds.title AS feed_title,
COALESCE(ttrss_feed_categories.title, '" . __('Uncategorized') . "') AS cat_title,
date_updated,
WHERE
ref_id = ttrss_entries.id AND feed_id = ttrss_feeds.id
AND include_in_digest = true
- AND $interval_query
- AND ttrss_user_entries.owner_uid = $user_id
+ AND $interval_qpart
+ AND ttrss_user_entries.owner_uid = :user_id
AND unread = true
AND score >= 0
ORDER BY ttrss_feed_categories.title, ttrss_feeds.title, score DESC, date_updated DESC
- LIMIT $limit");
-
- $headlines_count = db_num_rows($result);
+ LIMIT :limit");
+ $sth->bindParam(':user_id', intval($user_id, 10), \PDO::PARAM_INT);
+ $sth->bindParam(':limit', intval($limit, 10), \PDO::PARAM_INT);
+ $sth->execute();
+ $headlines_count = 0;
$headlines = array();
- while ($line = db_fetch_assoc($result)) {
+ while ($line = $sth->fetch()) {
array_push($headlines, $line);
+ $headlines_count++;
}
for ($i = 0; $i < sizeof($headlines); $i++) {
$updated = make_local_datetime($line['last_updated'], false,
$user_id);
- /* if ($line["score"] != 0) {
- if ($line["score"] > 0) $line["score"] = '+' . $line["score"];
-
- $line["title"] .= " (".$line['score'].")";
- } */
-
if (get_pref('ENABLE_FEED_CATS', $user_id)) {
$line['feed_title'] = $line['cat_title'] . " / " . $line['feed_title'];
}
return array($tmp, $headlines_count, $affected_ids, $tmp_t);
}
-}
\ No newline at end of file
+}