From adec979fd5453cf213b776d7dceaaaac4eb05713 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 12 Aug 2012 15:07:03 +0200 Subject: more subscription refactoring BROKEN now the actual sending of bulk messages (digest, list) is reimplemented and partially tested. Still not complete --- lib/exe/indexer.php | 86 +++++------------------------------------------------ 1 file changed, 7 insertions(+), 79 deletions(-) (limited to 'lib/exe') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index e149770c0..270341fe6 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -166,92 +166,20 @@ function runSitemapper(){ * @author Adrian Lang */ function sendDigest() { - echo 'sendDigest(): started'.NL; - global $ID; global $conf; + global $ID; + + echo 'sendDigest(): started'.NL; if (!$conf['subscribers']) { echo 'sendDigest(): disabled'.NL; return false; } - $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) { - if (!subscription_lock($id)) { - continue; - } - foreach($users as $data) { - list($user, $style, $lastupdate) = $data; - $lastupdate = (int) $lastupdate; - if ($lastupdate + $conf['subscribe_time'] > time()) { - // Less than the configured time period passed since last - // update. - continue; - } - - // Work as the user to make sure ACLs apply correctly - $USERINFO = $auth->getUserData($user); - $_SERVER['REMOTE_USER'] = $user; - if ($USERINFO === false) { - continue; - } - - if (substr($id, -1, 1) === ':') { - // The subscription target is a namespace - $changes = getRecentsSince($lastupdate, null, getNS($id)); - } else { - if(auth_quickaclcheck($id) < AUTH_READ) continue; - - $meta = p_get_metadata($id); - $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']; - } - } - - 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); - } - subscription_unlock($id); - } + $sub = new Subscription(); + $sent = $sub->send_bulk($ID); - // restore current user info - $USERINFO = $olduinfo; - $_SERVER['REMOTE_USER'] = $olduser; + echo "sendDigest(): sent $sent mails".NL; echo 'sendDigest(): finished'.NL; - return true; + return (bool) $sent; } /** -- cgit v1.2.3 From 84c1127cc070777c8cbcf488f5422bc4b71470a8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 12 Aug 2012 17:30:01 +0200 Subject: correctly check if subscriptions are enabled --- lib/exe/indexer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/exe') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 270341fe6..bbfd51b39 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -170,7 +170,7 @@ function sendDigest() { global $ID; echo 'sendDigest(): started'.NL; - if (!$conf['subscribers']) { + if(!actionOK('subscribe')) { echo 'sendDigest(): disabled'.NL; return false; } -- cgit v1.2.3