From 5b75cd1f5c479ada468fbf62a733c54edad152f1 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Tue, 5 Jan 2010 14:14:00 +0100 Subject: New mail subscription with digest --- lib/exe/indexer.php | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'lib/exe/indexer.php') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 1c4128eb7..eb1556e1d 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -37,6 +37,7 @@ if ($evt->advise_before()) { runIndexer() or metaUpdate() or runSitemapper() or + sendDigest() or runTrimRecentChanges() or runTrimRecentChanges(true) or $evt->advise_after(); @@ -334,6 +335,75 @@ function runSitemapper(){ return true; } +/** + * Send digest and list mails for all subscriptions which are in effect for the + * current page + * + * @author Adrian Lang + */ +function sendDigest() { + require_once DOKU_INC . 'inc/subscription.php'; + echo 'sendDigest(): start'.NL; + global $ID; + global $conf; + if (!$conf['subscribers']) { + return; + } + + $subscriptions = subscription_find($ID, array('style' => '(digest|list)', + 'escaped' => true)); + global $auth; + global $lang; + global $conf; + foreach($subscriptions as $id => $users) { + foreach($users as $data) { + list($user, $style, $lastupdate) = $data; + $lastupdate = (int) $lastupdate; + if ($lastupdate + $conf['subscribe_interval'] > time()) { + // Less than a day passed since last update. + continue; + } + // TODO: Does that suffice for namespaces? + $info = $auth->getUserData($user); + if ($info === false) { + continue; + } + $level = auth_aclcheck($id, $user, $info['grps']); + if ($level < AUTH_READ) { + continue; + } + + if (substr($id, -1, 1) === ':') { + // The subscription target is a namespace + $changes = getRecentsSince($lastupdate, null, getNS($id)); + if (count($changes) === 0) { + continue; + } + if ($style === 'digest') { + foreach($changes as $change) { + subscription_send_digest($info['mail'], $change, + $lastupdate); + } + } elseif ($style === 'list') { + subscription_send_list($info['mail'], $changes, $id); + } + // TODO: Handle duplicate subscriptions. + } else { + $meta = p_get_metadata($id); + $rev = $meta['last_change']['date']; + if ($rev < $lastupdate) { + // There is no new revision. + continue; + } + subscription_send_digest($info['mail'], $meta['last_change'], + $lastupdate); + } + // Update notification time. + subscription_set($id, $user, $style, true); + } + } +} + /** * Formats a timestamp as ISO 8601 date * -- cgit v1.2.3 From 8881fcc99a05f20da8fdd0f1c52f801fd84a8bb7 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Thu, 19 Nov 2009 15:25:25 +0100 Subject: Add events to subscription. --- lib/exe/indexer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/exe/indexer.php') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index eb1556e1d..70aa607a9 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -399,7 +399,7 @@ function sendDigest() { $lastupdate); } // Update notification time. - subscription_set($id, $user, $style, true); + subscription_set($user, $id, $style, time(), true); } } } -- cgit v1.2.3 From 3a5a6f4fe4a9f768f5c6418ba0694d67594ed701 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 23 Nov 2009 17:16:03 +0100 Subject: correctly handle permissions in digest mailer Ignore-this: c34455078907459a846cf7f00e2b586b darcs-hash:20091123161603-6e07b-927477d6ca50e665228487eb0d3ce9787dbe455b.gz --- lib/exe/indexer.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'lib/exe/indexer.php') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 70aa607a9..1766c54f1 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -342,19 +342,24 @@ function runSitemapper(){ * @author Adrian Lang */ function sendDigest() { - require_once DOKU_INC . 'inc/subscription.php'; echo 'sendDigest(): start'.NL; global $ID; global $conf; if (!$conf['subscribers']) { return; } - + require_once DOKU_INC . 'inc/subscription.php'; $subscriptions = subscription_find($ID, array('style' => '(digest|list)', 'escaped' => true)); global $auth; global $lang; global $conf; + global $USERINFO; + + // remember current user info + $olduinfo = $USERINFO; + $olduser = $_SERVER['REMOTE_USER']; + foreach($subscriptions as $id => $users) { foreach($users as $data) { list($user, $style, $lastupdate) = $data; @@ -363,13 +368,11 @@ function sendDigest() { // Less than a day passed since last update. continue; } - // TODO: Does that suffice for namespaces? - $info = $auth->getUserData($user); - if ($info === false) { - continue; - } - $level = auth_aclcheck($id, $user, $info['grps']); - if ($level < AUTH_READ) { + + // Work as the user to make sure ACLs apply correctly + $USERINFO = $auth->getUserData($user); + $_SERVER['REMOTE_USER'] = $user; + if ($USERINFO === false) { continue; } @@ -389,6 +392,8 @@ function sendDigest() { } // TODO: Handle duplicate subscriptions. } else { + if(auth_quickacl($id) < AUTH_READ) continue; + $meta = p_get_metadata($id); $rev = $meta['last_change']['date']; if ($rev < $lastupdate) { @@ -402,6 +407,10 @@ function sendDigest() { subscription_set($user, $id, $style, time(), true); } } + + // restore current user info + $USERINFO = $olduinfo; + $_SERVER['REMOTE_USER'] = $olduser; } /** -- cgit v1.2.3 From 2f27189ab6f07352f435e91bab0c28dfc4899583 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 24 Nov 2009 12:58:05 +0100 Subject: wrong function name fixed Ignore-this: b74163181c2e41d3be022a6185f3e1c1 darcs-hash:20091124115805-6e07b-e808cf44a00a65ff8c70cc7e8de4dfedadf96cbd.gz --- lib/exe/indexer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/exe/indexer.php') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 1766c54f1..53f2c129d 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -392,7 +392,7 @@ function sendDigest() { } // TODO: Handle duplicate subscriptions. } else { - if(auth_quickacl($id) < AUTH_READ) continue; + if(auth_quickaclcheck($id) < AUTH_READ) continue; $meta = p_get_metadata($id); $rev = $meta['last_change']['date']; -- cgit v1.2.3 From 34240a5903c7499900c8ecf0a5592d28f67aaf46 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Mon, 30 Nov 2009 14:50:40 +0100 Subject: Fix $info var reference in digest send darcs-hash:20091130135040-e4919-40b6614fe28ea07dc5796661ddda6d005264ddbc.gz --- lib/exe/indexer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/exe/indexer.php') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 53f2c129d..84eb9d482 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -384,11 +384,11 @@ function sendDigest() { } if ($style === 'digest') { foreach($changes as $change) { - subscription_send_digest($info['mail'], $change, + subscription_send_digest($USERINFO['mail'], $change, $lastupdate); } } elseif ($style === 'list') { - subscription_send_list($info['mail'], $changes, $id); + subscription_send_list($USERINFO['mail'], $changes, $id); } // TODO: Handle duplicate subscriptions. } else { @@ -400,7 +400,7 @@ function sendDigest() { // There is no new revision. continue; } - subscription_send_digest($info['mail'], $meta['last_change'], + subscription_send_digest($USERINFO['mail'], $meta['last_change'], $lastupdate); } // Update notification time. -- cgit v1.2.3 From 24b3cb1ac0784ffa2acabf021fdd06c6d49cc7b1 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 1 Feb 2010 16:20:40 +0100 Subject: removed require's in lib/exe/* --- lib/exe/indexer.php | 8 -------- 1 file changed, 8 deletions(-) (limited to 'lib/exe/indexer.php') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 84eb9d482..828834c86 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -8,8 +8,6 @@ if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); define('DOKU_DISABLE_GZIP_OUTPUT',1); require_once(DOKU_INC.'inc/init.php'); -require_once(DOKU_INC.'inc/auth.php'); -require_once(DOKU_INC.'inc/events.php'); session_write_close(); //close session if(!defined('NL')) define('NL',"\n"); @@ -177,8 +175,6 @@ function runIndexer(){ } if($conf['dperm']) chmod($lock, $conf['dperm']); - require_once(DOKU_INC.'inc/indexer.php'); - // upgrade to version 2 if (!@file_exists($conf['indexdir'].'/pageword.idx')) idx_upgradePageWords(); @@ -211,11 +207,8 @@ function metaUpdate(){ if (@file_exists($file)) return false; if (!@file_exists(wikiFN($ID))) return false; - require_once(DOKU_INC.'inc/common.php'); - require_once(DOKU_INC.'inc/parserutils.php'); global $conf; - // gather some additional info from changelog $info = io_grep($conf['changelog'], '/^(\d+)\t(\d+\.\d+\.\d+\.\d+)\t'.preg_quote($ID,'/').'\t([^\t]+)\t([^\t\n]+)/', @@ -348,7 +341,6 @@ function sendDigest() { if (!$conf['subscribers']) { return; } - require_once DOKU_INC . 'inc/subscription.php'; $subscriptions = subscription_find($ID, array('style' => '(digest|list)', 'escaped' => true)); global $auth; -- cgit v1.2.3 From 25fabd1de0b6421edfdfb47904354a7b8bff16e0 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Fri, 5 Feb 2010 10:03:19 +0100 Subject: Fix documentation for subscribe_time --- lib/exe/indexer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/exe/indexer.php') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 84eb9d482..35aa1beef 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -365,7 +365,8 @@ function sendDigest() { list($user, $style, $lastupdate) = $data; $lastupdate = (int) $lastupdate; if ($lastupdate + $conf['subscribe_interval'] > time()) { - // Less than a day passed since last update. + // Less than the configured time period passed since last + // update. continue; } -- cgit v1.2.3 From 70421c96f055e574aa6e9602492ca4b35a33b9f2 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Mon, 8 Feb 2010 15:44:26 +0100 Subject: Correct subscribe config parameter name --- lib/exe/indexer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/exe/indexer.php') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 35aa1beef..821163473 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -364,7 +364,7 @@ function sendDigest() { foreach($users as $data) { list($user, $style, $lastupdate) = $data; $lastupdate = (int) $lastupdate; - if ($lastupdate + $conf['subscribe_interval'] > time()) { + if ($lastupdate + $conf['subscribe_time'] > time()) { // Less than the configured time period passed since last // update. continue; -- cgit v1.2.3 From 3e0c7aa328ac721b3bcf17822f9ed3659ad93d14 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Tue, 4 May 2010 12:07:35 +0200 Subject: Add locking for indexer-based notifications --- lib/exe/indexer.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/exe/indexer.php') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index eb5670005..7e55915f4 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -353,6 +353,9 @@ function sendDigest() { $olduser = $_SERVER['REMOTE_USER']; foreach($subscriptions as $id => $users) { + if (!subscription_lock($id)) { + continue; + } foreach($users as $data) { list($user, $style, $lastupdate) = $data; $lastupdate = (int) $lastupdate; @@ -399,6 +402,7 @@ function sendDigest() { // Update notification time. subscription_set($user, $id, $style, time(), true); } + subscription_unlock($id); } // restore current user info -- cgit v1.2.3 From 159ef5962053a685e348239dfa0b3648ed516962 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Wed, 16 Jun 2010 16:09:06 +0200 Subject: Remove temp indexer upgrade stuff from 579b0f7e --- lib/exe/indexer.php | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'lib/exe/indexer.php') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 7e55915f4..1e6eb5685 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -134,18 +134,6 @@ function runIndexer(){ global $conf; print "runIndexer(): started".NL; - // Move index files (if needed) - // Uses the importoldindex plugin to upgrade the index automatically. - // FIXME: Remove this from runIndexer when it is no longer needed. - if (@file_exists($conf['cachedir'].'/page.idx') && - (!@file_exists($conf['indexdir'].'/page.idx') || - !filesize($conf['indexdir'].'/page.idx')) && - !@file_exists($conf['indexdir'].'/index_importing')) { - echo "trigger TEMPORARY_INDEX_UPGRADE_EVENT\n"; - $tmp = array(); // no event data - trigger_event('TEMPORARY_INDEX_UPGRADE_EVENT', $tmp); - } - if(!$ID) return false; // check if indexing needed -- cgit v1.2.3 From a0070b52bbd24f6972b819fa8ff4bdbfe81b5bbc Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Wed, 16 Jun 2010 16:15:28 +0200 Subject: Add title index to the indexer files, improve indexer calls --- lib/exe/indexer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/exe/indexer.php') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 1e6eb5685..75228779e 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -255,7 +255,7 @@ function runSitemapper(){ return false; } - $pages = file($conf['indexdir'].'/page.idx'); + $pages = idx_getIndex('page', ''); print 'runSitemapper(): creating sitemap using '.count($pages).' pages'.NL; // build the sitemap -- cgit v1.2.3 From 41c141178e9733bbf38f8e937d3dea63058af0dc Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Tue, 10 Aug 2010 12:26:19 +0200 Subject: Ignore small & own changes in digest & list mails --- lib/exe/indexer.php | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'lib/exe/indexer.php') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 75228779e..f8e2f7981 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -363,30 +363,40 @@ function sendDigest() { if (substr($id, -1, 1) === ':') { // The subscription target is a namespace $changes = getRecentsSince($lastupdate, null, getNS($id)); - if (count($changes) === 0) { - continue; - } - if ($style === 'digest') { - foreach($changes as $change) { - subscription_send_digest($USERINFO['mail'], $change, - $lastupdate); - } - } elseif ($style === 'list') { - subscription_send_list($USERINFO['mail'], $changes, $id); - } - // TODO: Handle duplicate subscriptions. } else { if(auth_quickaclcheck($id) < AUTH_READ) continue; $meta = p_get_metadata($id); - $rev = $meta['last_change']['date']; - if ($rev < $lastupdate) { - // There is no new revision. - continue; + $changes = array($meta['last_change']); + } + + // Filter out pages only changed in small and own edits + $change_ids = array(); + foreach($changes as $rev) { + $n = 0; + while (!is_null($rev) && $rev['date'] >= $lastupdate && + ($_SERVER['REMOTE_USER'] === $rev['user'] || + $rev['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT)) { + $rev = getRevisions($rev['id'], $n++, 1); + $rev = (count($rev) > 0) ? $rev[0] : null; + } + + if (!is_null($rev) && $rev['date'] >= $lastupdate) { + // Some change was not a minor one and not by myself + $change_ids[] = $rev['id']; } - subscription_send_digest($USERINFO['mail'], $meta['last_change'], - $lastupdate); } + + if ($style === 'digest') { + foreach($change_ids as $change_id) { + subscription_send_digest($USERINFO['mail'], $change_id, + $lastupdate); + } + } elseif ($style === 'list') { + subscription_send_list($USERINFO['mail'], $change_ids, $id); + } + // TODO: Handle duplicate subscriptions. + // Update notification time. subscription_set($user, $id, $style, time(), true); } -- cgit v1.2.3