summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2012-01-30 16:34:45 +0400
committerAndrew Dolgov <[email protected]>2012-01-30 16:34:45 +0400
commit61c1812f29dc76e93107b65dea80fde260269e8d (patch)
treeb87934bbc3be918590daafe959d149d846892ff7 /include
parent33f0fdd0a21ca7999e2d9d1a8db438711e518587 (diff)
implement preferred time for sending out digests
Diffstat (limited to 'include')
-rw-r--r--include/db-prefs.php6
-rw-r--r--include/functions.php87
-rw-r--r--include/rssfuncs.php2
-rw-r--r--include/sanity_check.php2
4 files changed, 52 insertions, 45 deletions
diff --git a/include/db-prefs.php b/include/db-prefs.php
index 7ee492009..b62e01a7b 100644
--- a/include/db-prefs.php
+++ b/include/db-prefs.php
@@ -2,7 +2,7 @@
require_once "config.php";
require_once "db.php";
- if (!defined('DISABLE_SESSIONS')) {
+ if (!defined('DISABLE_SESSIONS') && !defined('PREFS_NO_CACHE')) {
if (!$_SESSION["prefs_cache"])
$_SESSION["prefs_cache"] = array();
}
@@ -21,7 +21,7 @@
//$prefs_cache = false;
}
- if ($prefs_cache && !defined('DISABLE_SESSIONS')) {
+ if ($prefs_cache && !defined('DISABLE_SESSIONS') && !defined('PREFS_NO_CACHE')) {
if ($_SESSION["prefs_cache"] && @$_SESSION["prefs_cache"][$pref_name]) {
$tuple = $_SESSION["prefs_cache"][$pref_name];
return convert_pref_type($tuple["value"], $tuple["type"]);
@@ -102,7 +102,7 @@
$type_name = "";
$current_value = "";
- if (!defined('DISABLE_SESSIONS')) {
+ if (!defined('DISABLE_SESSIONS') && !defined('PREFS_NO_CACHE')) {
if ($_SESSION["prefs_cache"] && @$_SESSION["prefs_cache"][$pref_name]) {
$type_name = $_SESSION["prefs_cache"][$pref_name]["type"];
$current_value = $_SESSION["prefs_cache"][$pref_name]["value"];
diff --git a/include/functions.php b/include/functions.php
index 44331d72e..9eb66de3e 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -2689,14 +2689,13 @@
require_once 'lib/phpmailer/class.phpmailer.php';
$user_limit = 15; // amount of users to process (e.g. emails to send out)
- $days = 1;
- if ($debug) _debug("Sending digests, batch of max $user_limit users, days = $days, headline limit = $limit");
+ if ($debug) _debug("Sending digests, batch of max $user_limit users, headline limit = $limit");
if (DB_TYPE == "pgsql") {
- $interval_query = "last_digest_sent < NOW() - INTERVAL '$days days'";
+ $interval_query = "last_digest_sent < NOW() - INTERVAL '1 days'";
} else if (DB_TYPE == "mysql") {
- $interval_query = "last_digest_sent < DATE_SUB(NOW(), INTERVAL $days DAY)";
+ $interval_query = "last_digest_sent < DATE_SUB(NOW(), INTERVAL 1 DAY)";
}
$result = db_query($link, "SELECT id,email FROM ttrss_users
@@ -2705,58 +2704,64 @@
while ($line = db_fetch_assoc($result)) {
if (get_pref($link, 'DIGEST_ENABLE', $line['id'], false)) {
- print "Sending digest for UID:" . $line['id'] . " - " . $line["email"] . " ... ";
+ $preferred_ts = strtotime(get_pref($link, 'DIGEST_PREFERRED_TIME', $line['id'], '00:00'));
- $do_catchup = get_pref($link, 'DIGEST_CATCHUP', $line['id'], false);
+ if ($preferred_ts && time() >= $preferred_ts) {
- $tuple = prepare_headlines_digest($link, $line["id"], $days, $limit);
- $digest = $tuple[0];
- $headlines_count = $tuple[1];
- $affected_ids = $tuple[2];
- $digest_text = $tuple[3];
+ if ($debug) print "Sending digest for UID:" . $line['id'] . " - " . $line["email"] . " ... ";
- if ($headlines_count > 0) {
+ $do_catchup = get_pref($link, 'DIGEST_CATCHUP', $line['id'], false);
- $mail = new PHPMailer();
+ $tuple = prepare_headlines_digest($link, $line["id"], 1, $limit);
+ $digest = $tuple[0];
+ $headlines_count = $tuple[1];
+ $affected_ids = $tuple[2];
+ $digest_text = $tuple[3];
- $mail->PluginDir = "lib/phpmailer/";
- $mail->SetLanguage("en", "lib/phpmailer/language/");
+ if ($headlines_count > 0) {
- $mail->CharSet = "UTF-8";
+ $mail = new PHPMailer();
- $mail->From = SMTP_FROM_ADDRESS;
- $mail->FromName = SMTP_FROM_NAME;
- $mail->AddAddress($line["email"], $line["login"]);
+ $mail->PluginDir = "lib/phpmailer/";
+ $mail->SetLanguage("en", "lib/phpmailer/language/");
- if (SMTP_HOST) {
- $mail->Host = SMTP_HOST;
- $mail->Mailer = "smtp";
- $mail->SMTPAuth = SMTP_LOGIN != '';
- $mail->Username = SMTP_LOGIN;
- $mail->Password = SMTP_PASSWORD;
- }
+ $mail->CharSet = "UTF-8";
+
+ $mail->From = SMTP_FROM_ADDRESS;
+ $mail->FromName = SMTP_FROM_NAME;
+ $mail->AddAddress($line["email"], $line["login"]);
- $mail->IsHTML(true);
- $mail->Subject = DIGEST_SUBJECT;
- $mail->Body = $digest;
- $mail->AltBody = $digest_text;
+ if (SMTP_HOST) {
+ $mail->Host = SMTP_HOST;
+ $mail->Mailer = "smtp";
+ $mail->SMTPAuth = SMTP_LOGIN != '';
+ $mail->Username = SMTP_LOGIN;
+ $mail->Password = SMTP_PASSWORD;
+ }
- $rc = $mail->Send();
+ $mail->IsHTML(true);
+ $mail->Subject = DIGEST_SUBJECT;
+ $mail->Body = $digest;
+ $mail->AltBody = $digest_text;
- if (!$rc) print "ERROR: " . $mail->ErrorInfo;
+ $rc = $mail->Send();
- print "RC=$rc\n";
+ if (!$rc && $debug) print "ERROR: " . $mail->ErrorInfo;
- if ($rc && $do_catchup) {
- print "Marking affected articles as read...\n";
- catchupArticlesById($link, $affected_ids, 0, $line["id"]);
+ if ($debug) print "RC=$rc\n";
+
+ if ($rc && $do_catchup) {
+ if ($debug) print "Marking affected articles as read...\n";
+ catchupArticlesById($link, $affected_ids, 0, $line["id"]);
+ }
+ } else {
+ if ($debug) print "No headlines\n";
}
- } else {
- print "No headlines\n";
- }
- db_query($link, "UPDATE ttrss_users SET last_digest_sent = NOW()
- WHERE id = " . $line["id"]);
+ db_query($link, "UPDATE ttrss_users SET last_digest_sent = NOW()
+ WHERE id = " . $line["id"]);
+
+ }
}
}
diff --git a/include/rssfuncs.php b/include/rssfuncs.php
index 1028371cf..51b7d7c33 100644
--- a/include/rssfuncs.php
+++ b/include/rssfuncs.php
@@ -60,6 +60,8 @@
function update_daemon_common($link, $limit = DAEMON_FEED_LIMIT, $from_http = false, $debug = true) {
// Process all other feeds using last_updated and interval parameters
+ define('PREFS_NO_CACHE', true);
+
// Test if the user has loggued in recently. If not, it does not update its feeds.
if (!SINGLE_USER_MODE && DAEMON_UPDATE_LOGIN_LIMIT > 0) {
if (DB_TYPE == "pgsql") {
diff --git a/include/sanity_check.php b/include/sanity_check.php
index 1cd2873df..d1b2873ca 100644
--- a/include/sanity_check.php
+++ b/include/sanity_check.php
@@ -6,7 +6,7 @@
} else {
define('EXPECTED_CONFIG_VERSION', 25);
- define('SCHEMA_VERSION', 88);
+ define('SCHEMA_VERSION', 89);
require_once "config.php";
require_once "sanity_config.php";