@@ -40,12 +40,11 @@ function onTicketCreated(Ticket $ticket) {
40
40
$ plaintext = Format::html2text ($ ticket ->getMessages ()[0 ]->getBody ()->getClean ());
41
41
42
42
// Format the messages we'll send.
43
- $ heading = sprintf ('%s CONTROLSTART%sscp/tickets.php?id=%d|#%s - % sCONTROLEND %s '
43
+ $ heading = sprintf ('%s CONTROLSTART%sscp/tickets.php?id=%d|#%sCONTROLEND %s '
44
44
, __ ("New Ticket " )
45
45
, $ cfg ->getBaseUrl ()
46
46
, $ ticket ->getId ()
47
47
, $ ticket ->getNumber ()
48
- , $ ticket ->getSubject ()
49
48
, __ ("created " ));
50
49
$ body = sprintf ('%s %s (%s) %s '
51
50
, __ ("Created by " )
@@ -75,6 +74,10 @@ function onTicketUpdated(ThreadEntry $entry) {
75
74
76
75
// Need to fetch the ticket from the ThreadEntry
77
76
$ ticket = $ this ->getTicket ($ entry );
77
+ if (!$ ticket instanceof Ticket) {
78
+ // Admin created ticket's won't work here.
79
+ return ;
80
+ }
78
81
79
82
// Check to make sure this entry isn't the first (ie: a New ticket)
80
83
$ first_entry = $ ticket ->getMessages ()[0 ];
@@ -86,12 +89,11 @@ function onTicketUpdated(ThreadEntry $entry) {
86
89
$ plaintext = Format::html2text ($ entry ->getBody ()->getClean ());
87
90
88
91
// Format the messages we'll send
89
- $ heading = sprintf ('%s CONTROLSTART%sscp/tickets.php?id=%d|#%s % sCONTROLEND %s '
92
+ $ heading = sprintf ('%s CONTROLSTART%sscp/tickets.php?id=%d|#%sCONTROLEND %s '
90
93
, __ ("Ticket " )
91
94
, $ cfg ->getBaseUrl ()
92
95
, $ ticket ->getId ()
93
96
, $ ticket ->getNumber ()
94
- , $ ticket ->getSubject ()
95
97
, __ ("updated " ));
96
98
$ body = sprintf ('%s %s (%s) %s %s %s '
97
99
, __ ("by " )
@@ -125,6 +127,16 @@ function sendToSlack(Ticket $ticket, $heading, $body, $colour = 'good') {
125
127
$ ost ->logError ('Slack Plugin not configured ' , 'You need to read the Readme and configure a webhook URL before using this. ' );
126
128
}
127
129
130
+ // Check the subject, see if we want to filter it.
131
+ $ regex_subject_ignore = $ this ->getConfig ()->get ('slack-regex-subject-ignore ' );
132
+ // Filter on subject, and validate regex:
133
+ if ($ regex_subject_ignore && preg_match ("/ $ regex_subject_ignore/i " , $ ticket ->getSubject ())) {
134
+ $ ost ->logDebug ('Ignored Message ' , 'Slack notification was not sent because the subject ( ' . $ ticket ->getSubject () . ') matched regex ( ' . htmlspecialchars ($ regex_subject_ignore ) . '). ' );
135
+ return ;
136
+ } else {
137
+ error_log ("$ ticket_subject didn't trigger $ regex_subject_ignore " );
138
+ }
139
+
128
140
$ heading = $ this ->format_text ($ heading );
129
141
$ body = $ this ->format_text ($ body );
130
142
0 commit comments