2 require_once 'MTrackWeb.php';
4 class MTrackWeb_Cron_Notify extends MTrackWeb
9 $ff = HTML_FlexyFramework::get();
13 HTML_FlexyFramework::ensureSingle(__FILE__, $this);
20 DB_DataObject::debugLevel(1);
21 date_default_timezone_set('UTC');
23 // what's the baserul..
26 $MAX_DIFF = 200 * 1024;
27 $USE_BATCHING = false;
30 $e= DB_DataObject::factory('Events');
31 $e->action = 'MTRACK>NOTIFY';
33 $e->selectAdd('MAX(event_when) as event_when');
35 if (!$e->find(true)) {
36 $e->event_when = date('Y-m-d H:i:s', 0); // should be a long time ago..
41 stream_filter_register("mtrackcanonical", 'CanonicalLineEndingFilter');
42 stream_filter_register("mtrackunix", 'UnixLineEndingFilter');
44 $w = DB_DataObject::factory('core_watch');
45 // returns a list of user with the objects they are watching..
46 $watched = $w->watched($last,'email');
48 $CS = DB_DataObject::factory('mtrack_change');
51 foreach($watches as $uid => $ar) {
52 // we can now query mtrack_change for anything that occured in that list..
53 $messages[$uid] = $CS->gatherChanges($since, $uid, $ar);
62 $watched = MTrackWatch::getWatchedItemsAndWatchers($last, 'email');
63 printf("Got %d watchers\n", count($watched));
65 /* For each watcher, compute the changes.
66 * Group changes by ticket, sending one email per ticket.
67 * Group tickets into batch updates if the only fields that changed are
68 * bulk update style (milestone, assignment etc.)
70 * For the wiki repo, group by file so that serial edits within the batch
71 * period show up as a single email.
74 foreach ($watched as $user => $objects) {
75 $udata = MTrackAuth::getUserData($user);
77 foreach ($objects as $object => $items) {
78 list($otype, $oid) = explode(':', $object, 2);
80 $fname = "notify_$otype";
81 if (function_exists($fname)) {
82 call_user_func($fname, $object, $oid, $items, $user, $udata);
84 echo "WARN: no notifier for $otype $oid\n";
86 foreach ($items as $o) {
87 if ($o instanceof MTrackSCMEvent) {
88 $t = strtotime($o->ctime);
90 $t = strtotime($o->changedate);
102 class CanonicalLineEndingFilter extends php_user_filter {
103 function filter($in, $out, &$consumed, $closing)
105 while ($bucket = stream_bucket_make_writeable($in)) {
106 $bucket->data = preg_replace("/\r?\n/", "\r\n", $bucket->data);
107 $consumed += $bucket->datalen;
108 stream_bucket_append($out, $bucket);
113 class UnixLineEndingFilter extends php_user_filter {
114 function filter($in, $out, &$consumed, $closing)
116 while ($bucket = stream_bucket_make_writeable($in)) {
117 $bucket->data = preg_replace("/\r?\n/", "\n", $bucket->data);
118 $consumed += $bucket->datalen;
119 stream_bucket_append($out, $bucket);