3 class MTrackWeb_Cron_Notify extends MTrackWeb
8 $ff = HTML_FlexyFramework::get();
12 HTML_FlexyFramework::ensureSingle(__FILE__, $this);
20 date_default_timezone_set('UTC');
22 // what's the baserul..
25 $MAX_DIFF = 200 * 1024;
26 $USE_BATCHING = false;
29 $db = MTrackDB::get();
31 // default to the last 10 minutes, but prefer the last recorded run time
32 $last = MTrackDB::unixtime(time() - 600);
33 foreach (MTrackDB::q('select last_run from last_notification')->fetchAll()
37 $LATEST = strtotime($last);
38 if (getenv('DEBUG_TIME')) {
39 $dtime = strtotime(getenv('DEBUG_TIME'));
42 $last = MTrackDB::unixtime($LATEST);
43 echo "Using $last as last time (specified via DEBUG_TIME var)\n";
47 class CanonicalLineEndingFilter extends php_user_filter {
48 function filter($in, $out, &$consumed, $closing)
50 while ($bucket = stream_bucket_make_writeable($in)) {
51 $bucket->data = preg_replace("/\r?\n/", "\r\n", $bucket->data);
52 $consumed += $bucket->datalen;
53 stream_bucket_append($out, $bucket);
58 class UnixLineEndingFilter extends php_user_filter {
59 function filter($in, $out, &$consumed, $closing)
61 while ($bucket = stream_bucket_make_writeable($in)) {
62 $bucket->data = preg_replace("/\r?\n/", "\n", $bucket->data);
63 $consumed += $bucket->datalen;
64 stream_bucket_append($out, $bucket);
69 stream_filter_register("mtrackcanonical", 'CanonicalLineEndingFilter');
70 stream_filter_register("mtrackunix", 'UnixLineEndingFilter');
72 $watched = MTrackWatch::getWatchedItemsAndWatchers($last, 'email');
73 printf("Got %d watchers\n", count($watched));
75 /* For each watcher, compute the changes.
76 * Group changes by ticket, sending one email per ticket.
77 * Group tickets into batch updates if the only fields that changed are
78 * bulk update style (milestone, assignment etc.)
80 * For the wiki repo, group by file so that serial edits within the batch
81 * period show up as a single email.
84 foreach ($watched as $user => $objects) {
85 $udata = MTrackAuth::getUserData($user);
87 foreach ($objects as $object => $items) {
88 list($otype, $oid) = explode(':', $object, 2);
90 $fname = "notify_$otype";
91 if (function_exists($fname)) {
92 call_user_func($fname, $object, $oid, $items, $user, $udata);
94 echo "WARN: no notifier for $otype $oid\n";
96 foreach ($items as $o) {
97 if ($o instanceof MTrackSCMEvent) {
98 $t = strtotime($o->ctime);
100 $t = strtotime($o->changedate);