xref: /web-bugs/scripts/cron/email-assigned (revision 9d47b05f)
1#!/usr/bin/env php
2<?php /* vim: set ft=phpbugdb noet ts=4 sw=4 : */
3
4use App\Repository\BugRepository;
5
6require __DIR__ . '/../../include/prepend.php';
7
8/*
9  Many times bugs are assigned to humans but not given the 'Assigned' status. Our bug tracker
10  is a little odd that way.
11  'No Feedback' was once a part of this, but no longer: https://news.php.net/php.webmaster/8828
12*/
13foreach ($container->get(BugRepository::class)->findAllAssigned() as $assigned => $binfos) {
14
15    $mbody      = format_email_body($binfos);
16    $email_user = $assigned . '@php.net';
17
18    mail($email_user, 'Assigned PHP bugs reminder', $mbody, 'From: php-bugs@lists.php.net', '-fphp-bugs@lists.php.net');
19}
20
21function format_email_body($binfos) {
22
23    $links            = '';
24    $count            = count($binfos);
25    $earliest_changed = time();
26    $earliest_opened  = time();
27
28    foreach ($binfos as $binfo) {
29
30        if ($earliest_changed > $binfo['ts_changed']) {
31            $earliest_changed = $binfo['ts_changed'];
32        }
33        if ($earliest_opened > $binfo['ts_opened']) {
34            $earliest_opened = $binfo['ts_opened'];
35        }
36
37        $link_title = strlen($binfo['sdesc']) < 65 ? $binfo['sdesc'] : substr($binfo['sdesc'], 0, 65) . '...';
38
39        $links .= " Title: $link_title\r\n";
40        $links .= " Type:  {$binfo['bug_type']} with Status: {$binfo['status']}\r\n";
41        $links .= " Link:  https://bugs.php.net/{$binfo['id']}\r\n\r\n";
42    }
43
44    $assigned = $binfo['assign'];
45    $salute   = ($count === 1) ? 'one bug report' : "$count bug reports";
46    $date_c   = date('M d, Y', $earliest_changed);
47    $date_o   = date('M d, Y', $earliest_opened);
48
49    $body = <<<MAIL_BODY
50Hello $assigned,
51
52This is a gentle reminder about the $salute assigned to you.
53
54Dates:
55 Earliest opened date:       $date_o
56 Earliest last change date:  $date_c
57
58Your assigned bug information:
59$links
60MAIL_BODY;
61
62    return $body;
63}
64