mirror of
https://git.tt-rss.org/fox/tt-rss.git
synced 2025-10-10 18:41:00 +02:00
implement preferred time for sending out digests
This commit is contained in:
parent
33f0fdd0a2
commit
61c1812f29
@ -8,7 +8,9 @@ class Backend extends Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function digestSend() {
|
function digestSend() {
|
||||||
send_headlines_digests($this->link);
|
define('PREFS_NO_CACHE', true);
|
||||||
|
|
||||||
|
send_headlines_digests($this->link, 100, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function help() {
|
function help() {
|
||||||
|
@ -464,6 +464,11 @@ class Pref_Prefs extends Protected_Handler {
|
|||||||
onclick=\"insertSSLserial('')\">" .
|
onclick=\"insertSSLserial('')\">" .
|
||||||
__('Clear') . "</button>";
|
__('Clear') . "</button>";
|
||||||
|
|
||||||
|
} else if ($pref_name = 'DIGEST_RPEFERRED_TIME') {
|
||||||
|
print "<input dojoType=\"dijit.form.ValidationTextBox\"
|
||||||
|
id=\"$pref_name\" regexp=\"[012]\d:\d\d\" placeHolder=\"12:00\"
|
||||||
|
name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">".
|
||||||
|
T_sprintf("Current server time: %s", date("H:i")) . "</div>";
|
||||||
} else {
|
} else {
|
||||||
$regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
|
$regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
require_once "config.php";
|
require_once "config.php";
|
||||||
require_once "db.php";
|
require_once "db.php";
|
||||||
|
|
||||||
if (!defined('DISABLE_SESSIONS')) {
|
if (!defined('DISABLE_SESSIONS') && !defined('PREFS_NO_CACHE')) {
|
||||||
if (!$_SESSION["prefs_cache"])
|
if (!$_SESSION["prefs_cache"])
|
||||||
$_SESSION["prefs_cache"] = array();
|
$_SESSION["prefs_cache"] = array();
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@
|
|||||||
//$prefs_cache = false;
|
//$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]) {
|
if ($_SESSION["prefs_cache"] && @$_SESSION["prefs_cache"][$pref_name]) {
|
||||||
$tuple = $_SESSION["prefs_cache"][$pref_name];
|
$tuple = $_SESSION["prefs_cache"][$pref_name];
|
||||||
return convert_pref_type($tuple["value"], $tuple["type"]);
|
return convert_pref_type($tuple["value"], $tuple["type"]);
|
||||||
@ -102,7 +102,7 @@
|
|||||||
$type_name = "";
|
$type_name = "";
|
||||||
$current_value = "";
|
$current_value = "";
|
||||||
|
|
||||||
if (!defined('DISABLE_SESSIONS')) {
|
if (!defined('DISABLE_SESSIONS') && !defined('PREFS_NO_CACHE')) {
|
||||||
if ($_SESSION["prefs_cache"] && @$_SESSION["prefs_cache"][$pref_name]) {
|
if ($_SESSION["prefs_cache"] && @$_SESSION["prefs_cache"][$pref_name]) {
|
||||||
$type_name = $_SESSION["prefs_cache"][$pref_name]["type"];
|
$type_name = $_SESSION["prefs_cache"][$pref_name]["type"];
|
||||||
$current_value = $_SESSION["prefs_cache"][$pref_name]["value"];
|
$current_value = $_SESSION["prefs_cache"][$pref_name]["value"];
|
||||||
|
@ -2689,14 +2689,13 @@
|
|||||||
require_once 'lib/phpmailer/class.phpmailer.php';
|
require_once 'lib/phpmailer/class.phpmailer.php';
|
||||||
|
|
||||||
$user_limit = 15; // amount of users to process (e.g. emails to send out)
|
$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") {
|
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") {
|
} 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
|
$result = db_query($link, "SELECT id,email FROM ttrss_users
|
||||||
@ -2705,58 +2704,64 @@
|
|||||||
while ($line = db_fetch_assoc($result)) {
|
while ($line = db_fetch_assoc($result)) {
|
||||||
|
|
||||||
if (get_pref($link, 'DIGEST_ENABLE', $line['id'], false)) {
|
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);
|
if ($debug) print "Sending digest for UID:" . $line['id'] . " - " . $line["email"] . " ... ";
|
||||||
$digest = $tuple[0];
|
|
||||||
$headlines_count = $tuple[1];
|
|
||||||
$affected_ids = $tuple[2];
|
|
||||||
$digest_text = $tuple[3];
|
|
||||||
|
|
||||||
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/";
|
if ($headlines_count > 0) {
|
||||||
$mail->SetLanguage("en", "lib/phpmailer/language/");
|
|
||||||
|
|
||||||
$mail->CharSet = "UTF-8";
|
$mail = new PHPMailer();
|
||||||
|
|
||||||
$mail->From = SMTP_FROM_ADDRESS;
|
$mail->PluginDir = "lib/phpmailer/";
|
||||||
$mail->FromName = SMTP_FROM_NAME;
|
$mail->SetLanguage("en", "lib/phpmailer/language/");
|
||||||
$mail->AddAddress($line["email"], $line["login"]);
|
|
||||||
|
|
||||||
if (SMTP_HOST) {
|
$mail->CharSet = "UTF-8";
|
||||||
$mail->Host = SMTP_HOST;
|
|
||||||
$mail->Mailer = "smtp";
|
$mail->From = SMTP_FROM_ADDRESS;
|
||||||
$mail->SMTPAuth = SMTP_LOGIN != '';
|
$mail->FromName = SMTP_FROM_NAME;
|
||||||
$mail->Username = SMTP_LOGIN;
|
$mail->AddAddress($line["email"], $line["login"]);
|
||||||
$mail->Password = SMTP_PASSWORD;
|
|
||||||
|
if (SMTP_HOST) {
|
||||||
|
$mail->Host = SMTP_HOST;
|
||||||
|
$mail->Mailer = "smtp";
|
||||||
|
$mail->SMTPAuth = SMTP_LOGIN != '';
|
||||||
|
$mail->Username = SMTP_LOGIN;
|
||||||
|
$mail->Password = SMTP_PASSWORD;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail->IsHTML(true);
|
||||||
|
$mail->Subject = DIGEST_SUBJECT;
|
||||||
|
$mail->Body = $digest;
|
||||||
|
$mail->AltBody = $digest_text;
|
||||||
|
|
||||||
|
$rc = $mail->Send();
|
||||||
|
|
||||||
|
if (!$rc && $debug) print "ERROR: " . $mail->ErrorInfo;
|
||||||
|
|
||||||
|
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";
|
||||||
}
|
}
|
||||||
|
|
||||||
$mail->IsHTML(true);
|
db_query($link, "UPDATE ttrss_users SET last_digest_sent = NOW()
|
||||||
$mail->Subject = DIGEST_SUBJECT;
|
WHERE id = " . $line["id"]);
|
||||||
$mail->Body = $digest;
|
|
||||||
$mail->AltBody = $digest_text;
|
|
||||||
|
|
||||||
$rc = $mail->Send();
|
|
||||||
|
|
||||||
if (!$rc) print "ERROR: " . $mail->ErrorInfo;
|
|
||||||
|
|
||||||
print "RC=$rc\n";
|
|
||||||
|
|
||||||
if ($rc && $do_catchup) {
|
|
||||||
print "Marking affected articles as read...\n";
|
|
||||||
catchupArticlesById($link, $affected_ids, 0, $line["id"]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
print "No headlines\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
db_query($link, "UPDATE ttrss_users SET last_digest_sent = NOW()
|
|
||||||
WHERE id = " . $line["id"]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +60,8 @@
|
|||||||
function update_daemon_common($link, $limit = DAEMON_FEED_LIMIT, $from_http = false, $debug = true) {
|
function update_daemon_common($link, $limit = DAEMON_FEED_LIMIT, $from_http = false, $debug = true) {
|
||||||
// Process all other feeds using last_updated and interval parameters
|
// 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.
|
// 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 (!SINGLE_USER_MODE && DAEMON_UPDATE_LOGIN_LIMIT > 0) {
|
||||||
if (DB_TYPE == "pgsql") {
|
if (DB_TYPE == "pgsql") {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
define('EXPECTED_CONFIG_VERSION', 25);
|
define('EXPECTED_CONFIG_VERSION', 25);
|
||||||
define('SCHEMA_VERSION', 88);
|
define('SCHEMA_VERSION', 89);
|
||||||
|
|
||||||
require_once "config.php";
|
require_once "config.php";
|
||||||
require_once "sanity_config.php";
|
require_once "sanity_config.php";
|
||||||
|
@ -260,7 +260,7 @@ create table ttrss_tags (id integer primary key auto_increment,
|
|||||||
|
|
||||||
create table ttrss_version (schema_version int not null) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
|
create table ttrss_version (schema_version int not null) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
|
||||||
|
|
||||||
insert into ttrss_version values (88);
|
insert into ttrss_version values (89);
|
||||||
|
|
||||||
create table ttrss_enclosures (id integer primary key auto_increment,
|
create table ttrss_enclosures (id integer primary key auto_increment,
|
||||||
content_url text not null,
|
content_url text not null,
|
||||||
@ -392,6 +392,8 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu
|
|||||||
|
|
||||||
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('SSL_CERT_SERIAL', 2, '', 'Login with an SSL certificate',3, 'Click to register your SSL client certificate with tt-rss');
|
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('SSL_CERT_SERIAL', 2, '', 'Login with an SSL certificate',3, 'Click to register your SSL client certificate with tt-rss');
|
||||||
|
|
||||||
|
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('DIGEST_PREFERRED_TIME', 2, '00:00', 'Try to send digests around specified time', 1, 'Uses server timezone');
|
||||||
|
|
||||||
create table ttrss_user_prefs (
|
create table ttrss_user_prefs (
|
||||||
owner_uid integer not null,
|
owner_uid integer not null,
|
||||||
pref_name varchar(250),
|
pref_name varchar(250),
|
||||||
|
@ -229,7 +229,7 @@ create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id);
|
|||||||
|
|
||||||
create table ttrss_version (schema_version int not null);
|
create table ttrss_version (schema_version int not null);
|
||||||
|
|
||||||
insert into ttrss_version values (88);
|
insert into ttrss_version values (89);
|
||||||
|
|
||||||
create table ttrss_enclosures (id serial not null primary key,
|
create table ttrss_enclosures (id serial not null primary key,
|
||||||
content_url text not null,
|
content_url text not null,
|
||||||
@ -354,6 +354,8 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu
|
|||||||
|
|
||||||
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('SSL_CERT_SERIAL', 2, '', 'Login with an SSL certificate',3, 'Click to register your SSL client certificate with tt-rss');
|
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('SSL_CERT_SERIAL', 2, '', 'Login with an SSL certificate',3, 'Click to register your SSL client certificate with tt-rss');
|
||||||
|
|
||||||
|
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('DIGEST_PREFERRED_TIME', 2, '00:00', 'Try to send digests around specified time', 1, 'Uses server timezone');
|
||||||
|
|
||||||
create table ttrss_user_prefs (
|
create table ttrss_user_prefs (
|
||||||
owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
|
owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
|
||||||
pref_name varchar(250) not null references ttrss_prefs(pref_name) ON DELETE CASCADE,
|
pref_name varchar(250) not null references ttrss_prefs(pref_name) ON DELETE CASCADE,
|
||||||
|
7
schema/versions/mysql/89.sql
Normal file
7
schema/versions/mysql/89.sql
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
begin;
|
||||||
|
|
||||||
|
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('DIGEST_PREFERRED_TIME', 2, '00:00', 'Try to send digests around specified time', 1, 'Uses server timezone');
|
||||||
|
|
||||||
|
update ttrss_version set schema_version = 89;
|
||||||
|
|
||||||
|
commit;
|
7
schema/versions/pgsql/89.sql
Normal file
7
schema/versions/pgsql/89.sql
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
begin;
|
||||||
|
|
||||||
|
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('DIGEST_PREFERRED_TIME', 2, '00:00', 'Try to send digests around specified time', 1, 'Uses server timezone');
|
||||||
|
|
||||||
|
update ttrss_version set schema_version = 89;
|
||||||
|
|
||||||
|
commit;
|
Loading…
x
Reference in New Issue
Block a user