LogService::new_response_rating()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 11
rs 10
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xhelp;
4
5
/*
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * @copyright    {@link https://xoops.org/ XOOPS Project}
17
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
18
 * @author       Brian Wahoff <[email protected]>
19
 * @author       XOOPS Development Team
20
 */
21
22
// require_once XHELP_CLASS_PATH . '/Service.php';
23
24
/**
25
 * xhelp_logService class
26
 *
27
 * Part of the Messaging Subsystem.  Uses the LogMessageHandler class for logging
28
 *
29
 * @author  Brian Wahoff <[email protected]>
30
 */
31
class LogService extends Service
32
{
33
    /**
34
     * Instance of the LogMessageHandler
35
     *
36
     * @var LogMessageHandler
37
     */
38
    public $logMessageHandler;
39
40
    /**
41
     * Class Constructor
42
     */
43
    public function __construct()
44
    {
45
        /** @var \XoopsModules\Xhelp\LogMessageHandler $this- >logMessageHandler */
46
        $this->logMessageHandler = Helper::getInstance()
47
            ->getHandler('LogMessage');
48
        $this->init();
49
    }
50
51
    public function attachEvents(): void
52
    {
53
        $this->attachEvent('batch_dept', $this);
54
        $this->attachEvent('batch_owner', $this);
55
        $this->attachEvent('batch_priority', $this);
56
        $this->attachEvent('batch_response', $this);
57
        $this->attachEvent('batch_status', $this);
58
        $this->attachEvent('close_ticket', $this);
59
        $this->attachEvent('delete_file', $this);
60
        $this->attachEvent('edit_response', $this);
61
        $this->attachEvent('edit_ticket', $this);
62
        $this->attachEvent('merge_tickets', $this);
63
        $this->attachEvent('new_response', $this);
64
        $this->attachEvent('new_response_rating', $this);
65
        $this->attachEvent('new_ticket', $this);
66
        $this->attachEvent('reopen_ticket', $this);
67
        $this->attachEvent('update_owner', $this);
68
        $this->attachEvent('update_priority', $this);
69
        $this->attachEvent('update_status', $this);
70
        $this->attachEvent('new_faq', $this);
71
    }
72
73
    /**
74
     * Callback function for the 'new_ticket' event
75
     * @param Ticket $ticket Ticket that was added
76
     * @return bool        True on success, false on error
77
     */
78
    public function new_ticket(Ticket $ticket): bool
79
    {
80
        global $xoopsUser;
81
82
        $logMessage = $this->logMessageHandler->create();
83
        $logMessage->setVar('uid', $ticket->getVar('uid'));
84
        $logMessage->setVar('ticketid', $ticket->getVar('id'));
85
        $logMessage->setVar('lastUpdated', $ticket->getVar('posted'));
86
        $logMessage->setVar('posted', $ticket->getVar('posted'));
87
88
        if ($xoopsUser->getVar('uid') == $ticket->getVar('uid')) {
89
            $logMessage->setVar('action', \_XHELP_LOG_ADDTICKET);
90
        } else {
91
            // Will display who logged the ticket for the user
92
            $logMessage->setVar('action', \sprintf(\_XHELP_LOG_ADDTICKET_FORUSER, $xoopsUser::getUnameFromId($ticket->getVar('uid')), $xoopsUser->getVar('uname')));
93
        }
94
95
        return $this->logMessageHandler->insert($logMessage);
96
    }
97
98
    /**
99
     * Callback function for the 'update_priority' event
100
     * @param Ticket $ticket      Ticket that was modified
101
     * @param int    $oldpriority Original ticket priority
102
     * @return bool        True on success, false on error
103
     */
104
    public function update_priority(Ticket $ticket, int $oldpriority): bool
105
    {
106
        global $xoopsUser;
107
108
        $logMessage = $this->logMessageHandler->create();
109
        $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
110
        $logMessage->setVar('ticketid', $ticket->getVar('id'));
111
        $logMessage->setVar('lastUpdated', $ticket->getVar('lastUpdated'));
112
        $logMessage->setVar('posted', $ticket->getVar('posted'));
113
        $logMessage->setVar('action', \sprintf(\_XHELP_LOG_UPDATE_PRIORITY, $oldpriority, $ticket->getVar('priority')));
0 ignored issues
show
Bug introduced by
It seems like $ticket->getVar('priority') can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

113
        $logMessage->setVar('action', \sprintf(\_XHELP_LOG_UPDATE_PRIORITY, $oldpriority, /** @scrutinizer ignore-type */ $ticket->getVar('priority')));
Loading history...
114
115
        return $this->logMessageHandler->insert($logMessage);
116
    }
117
118
    /**
119
     * Callback function for the 'update_status' event
120
     * @param Ticket                          $ticket    Ticket that was modified
121
     * @param \XoopsModules\Xhelp\Status|null $oldstatus Original ticket status
122
     * @param Status                          $newstatus New ticket status
123
     * @return bool        True on success, false on error
124
     */
125
    public function update_status(Ticket $ticket, ?Status $oldstatus, Status $newstatus): bool
126
    {
127
        global $xoopsUser;
128
129
        $logMessage = $this->logMessageHandler->create();
130
        $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
131
        $logMessage->setVar('ticketid', $ticket->getVar('id'));
132
        $logMessage->setVar('lastUpdated', $ticket->getVar('lastUpdated'));
133
        $logMessage->setVar('posted', $ticket->getVar('posted'));
134
        $logMessage->setVar('action', \sprintf(\_XHELP_LOG_UPDATE_STATUS, $oldstatus->getVar('description'), $newstatus->getVar('description')));
0 ignored issues
show
Bug introduced by
The method getVar() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

134
        $logMessage->setVar('action', \sprintf(\_XHELP_LOG_UPDATE_STATUS, $oldstatus->/** @scrutinizer ignore-call */ getVar('description'), $newstatus->getVar('description')));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
It seems like $oldstatus->getVar('description') can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

134
        $logMessage->setVar('action', \sprintf(\_XHELP_LOG_UPDATE_STATUS, /** @scrutinizer ignore-type */ $oldstatus->getVar('description'), $newstatus->getVar('description')));
Loading history...
135
136
        return $this->logMessageHandler->insert($logMessage, true);
137
    }
138
139
    /**
140
     * Event: update_owner
141
     * Triggered after ticket ownership change (Individual)
142
     * Also See: batch_owner
143
     * @param Ticket $ticket   Ticket that was changed
144
     * @param int    $oldowner UID of previous owner
145
     * @param int    $newowner UID of new owner
146
     * @return bool        True on success, false on error
147
     */
148
    public function update_owner(Ticket $ticket, int $oldowner, int $newowner): bool
0 ignored issues
show
Unused Code introduced by
The parameter $oldowner is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

148
    public function update_owner(Ticket $ticket, /** @scrutinizer ignore-unused */ int $oldowner, int $newowner): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $newowner is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

148
    public function update_owner(Ticket $ticket, int $oldowner, /** @scrutinizer ignore-unused */ int $newowner): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
149
    {
150
        global $xoopsUser;
151
152
        $logMessage = $this->logMessageHandler->create();
153
        $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
154
        $logMessage->setVar('ticketid', $ticket->getVar('id'));
155
        $logMessage->setVar('lastUpdated', $ticket->getVar('lastUpdated'));
156
        if ($xoopsUser->getVar('uid') == $ticket->getVar('ownership')) {
157
            //User claimed ownership
158
            $logMessage->setVar('action', \_XHELP_LOG_CLAIM_OWNERSHIP);
159
        } else {
160
            //Ownership was assigned
161
            $logMessage->setVar('action', \sprintf(\_XHELP_LOG_ASSIGN_OWNERSHIP, $xoopsUser::getUnameFromId($ticket->getVar('ownership'))));
162
        }
163
164
        return $this->logMessageHandler->insert($logMessage);
165
    }
166
167
    /**
168
     * Callback function for the reopen_ticket event
169
     * @param Ticket $ticket Ticket that was re-opened
170
     * @return bool        True on success, false on error
171
     */
172
    public function reopen_ticket(Ticket $ticket): bool
173
    {
174
        global $xoopsUser;
175
176
        $logMessage = $this->logMessageHandler->create();
177
        $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
178
        $logMessage->setVar('ticketid', $ticket->getVar('id'));
179
        $logMessage->setVar('lastUpdated', $ticket->getVar('lastUpdated'));
180
        $logMessage->setVar('action', \_XHELP_LOG_REOPEN_TICKET);
181
182
        return $this->logMessageHandler->insert($logMessage);
183
    }
184
185
    /**
186
     * Callback function for the close_ticket event
187
     * @param Ticket $ticket Ticket that was closed
188
     * @return bool        True on success, false on error
189
     */
190
    public function close_ticket(Ticket $ticket): bool
191
    {
192
        global $xoopsUser;
193
194
        $logMessage = $this->logMessageHandler->create();
195
        $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
196
        $logMessage->setVar('ticketid', $ticket->getVar('id'));
197
        $logMessage->setVar('lastUpdated', $ticket->getVar('lastUpdated'));
198
        $logMessage->setVar('action', \_XHELP_LOG_CLOSE_TICKET);
199
200
        return $this->logMessageHandler->insert($logMessage);
201
    }
202
203
    /**
204
     * Add Log information for 'new_response' event
205
     * @param Ticket   $ticket      Ticket for Response
206
     * @param Response $newResponse Response that was added
207
     * @return bool           True on success, false on error
208
     */
209
    public function new_response(Ticket $ticket, Response $newResponse): bool
210
    {
211
        global $xoopsUser;
212
213
        $logMessage = $this->logMessageHandler->create();
214
        $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
215
        $logMessage->setVar('ticketid', $ticket->getVar('id'));
216
        $logMessage->setVar('action', \_XHELP_LOG_ADDRESPONSE);
217
        $logMessage->setVar('lastUpdated', $newResponse->getVar('updateTime'));
218
219
        return $this->logMessageHandler->insert($logMessage);
220
    }
221
222
    /**
223
     * Callback function for the 'new_response_rating' event
224
     * @param \XoopsModules\Xhelp\StaffReview $rating   Rating Information
225
     * @param Ticket                          $ticket   Ticket for Rating
226
     * @param Response                        $response Response that was rated
227
     * @return bool           True on success, false on error
228
     */
229
    public function new_response_rating(StaffReview $rating, Ticket $ticket, Response $response): bool
0 ignored issues
show
Unused Code introduced by
The parameter $response is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

229
    public function new_response_rating(StaffReview $rating, Ticket $ticket, /** @scrutinizer ignore-unused */ Response $response): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $ticket is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

229
    public function new_response_rating(StaffReview $rating, /** @scrutinizer ignore-unused */ Ticket $ticket, Response $response): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
230
    {
231
        global $xoopsUser;
232
233
        $logMessage = $this->logMessageHandler->create();
234
        $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
235
        $logMessage->setVar('ticketid', $rating->getVar('ticketid'));
236
        $logMessage->setVar('action', \sprintf(\_XHELP_LOG_ADDRATING, $rating->getVar('responseid')));
0 ignored issues
show
Bug introduced by
It seems like $rating->getVar('responseid') can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

236
        $logMessage->setVar('action', \sprintf(\_XHELP_LOG_ADDRATING, /** @scrutinizer ignore-type */ $rating->getVar('responseid')));
Loading history...
237
        $logMessage->setVar('lastUpdated', \time());
238
239
        return $this->logMessageHandler->insert($logMessage);
240
    }
241
242
    /**
243
     * Callback function for the 'edit_ticket' event
244
     * @param array|Ticket $oldTicket  Original Ticket Information
245
     * @param Ticket       $ticketInfo New Ticket Information
246
     * @return bool        True on success, false on error
247
     */
248
    public function edit_ticket($oldTicket, Ticket $ticketInfo): bool
0 ignored issues
show
Unused Code introduced by
The parameter $oldTicket is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

248
    public function edit_ticket(/** @scrutinizer ignore-unused */ $oldTicket, Ticket $ticketInfo): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
249
    {
250
        global $xoopsUser;
251
252
        $logMessage = $this->logMessageHandler->create();
253
        $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
254
        $logMessage->setVar('ticketid', $ticketInfo->getVar('id'));
255
        $logMessage->setVar('lastUpdated', $ticketInfo->getVar('posted'));
256
        $logMessage->setVar('posted', $ticketInfo->getVar('posted'));
257
        $logMessage->setVar('action', \_XHELP_LOG_EDITTICKET);
258
259
        return $this->logMessageHandler->insert($logMessage);
260
    }
261
262
    /**
263
     * Callback function for the 'edit_response' event
264
     * @param Ticket   $ticket
265
     * @param Response $response
266
     * @param Ticket   $oldticket
267
     * @param Response $oldresponse
268
     * @return bool True on success, false on error
269
     * @internal param array $args Array of arguments passed to EventService
270
     */
271
    public function edit_response(Ticket $ticket, Response $response, Ticket $oldticket, Response $oldresponse): bool
0 ignored issues
show
Unused Code introduced by
The parameter $oldticket is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

271
    public function edit_response(Ticket $ticket, Response $response, /** @scrutinizer ignore-unused */ Ticket $oldticket, Response $oldresponse): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $ticket is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

271
    public function edit_response(/** @scrutinizer ignore-unused */ Ticket $ticket, Response $response, Ticket $oldticket, Response $oldresponse): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $oldresponse is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

271
    public function edit_response(Ticket $ticket, Response $response, Ticket $oldticket, /** @scrutinizer ignore-unused */ Response $oldresponse): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
272
    {
273
        global $xoopsUser;
274
275
        $logMessage = $this->logMessageHandler->create();
276
        $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
277
        $logMessage->setVar('ticketid', $response->getVar('ticketid'));
278
        $logMessage->setVar('lastUpdated', $response->getVar('updateTime'));
279
        $logMessage->setVar('action', \sprintf(\_XHELP_LOG_EDIT_RESPONSE, $response->getVar('id')));
0 ignored issues
show
Bug introduced by
It seems like $response->getVar('id') can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

279
        $logMessage->setVar('action', \sprintf(\_XHELP_LOG_EDIT_RESPONSE, /** @scrutinizer ignore-type */ $response->getVar('id')));
Loading history...
280
281
        return $this->logMessageHandler->insert($logMessage);
282
    }
283
284
    /**
285
     * Add Log Events for 'batch_dept' event
286
     * @param array          $tickets Array of Ticket objects
287
     * @param Department|int $dept    New department for tickets
288
     * @return bool            True on success, false on error
289
     */
290
    public function batch_dept(array $tickets, $dept): bool
291
    {
292
        global $xoopsUser;
293
        $helper = Helper::getInstance();
294
295
        /** @var \XoopsModules\Xhelp\DepartmentHandler $departmentHandler */
296
        $departmentHandler = $helper->getHandler('Department');
297
        $deptObj           = $departmentHandler->get($dept);
298
299
        foreach ($tickets as $ticket) {
300
            $logMessage = $this->logMessageHandler->create();
301
            $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
302
            $logMessage->setVar('ticketid', $ticket->getVar('id'));
303
            $logMessage->setVar('lastUpdated', \time());
304
            $logMessage->setVar('action', \sprintf(\_XHELP_LOG_SETDEPT, $deptObj->getVar('department')));
0 ignored issues
show
Bug introduced by
It seems like $deptObj->getVar('department') can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

304
            $logMessage->setVar('action', \sprintf(\_XHELP_LOG_SETDEPT, /** @scrutinizer ignore-type */ $deptObj->getVar('department')));
Loading history...
305
            $this->logMessageHandler->insert($logMessage);
306
            unset($logMessage);
307
        }
308
309
        return true;
310
    }
311
312
    /**
313
     * Add Log Events for 'batch_priority' event
314
     * @param array $tickets  Array of Ticket objects
315
     * @param int   $priority New priority level for tickets
316
     * @return bool  True on success, false on error
317
     */
318
    public function batch_priority(array $tickets, int $priority): bool
319
    {
320
        global $xoopsUser;
321
322
        $priority = $priority;
323
        foreach ($tickets as $ticket) {
324
            $logMessage = $this->logMessageHandler->create();
325
            $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
326
            $logMessage->setVar('ticketid', $ticket->getVar('id'));
327
            $logMessage->setVar('lastUpdated', $ticket->getVar('lastUpdated'));
328
            $logMessage->setVar('posted', $ticket->getVar('posted'));
329
            $logMessage->setVar('action', \sprintf(\_XHELP_LOG_UPDATE_PRIORITY, $ticket->getVar('priority'), $priority));
330
            $this->logMessageHandler->insert($logMessage);
331
        }
332
333
        return true;
334
    }
335
336
    /**
337
     * Add Log Events for 'batch_owner' event
338
     * @param array $tickets Array of Ticket objects
339
     * @param int   $owner   New owner for tickets
340
     * @return bool  True on success, false on error
341
     */
342
    public function batch_owner(array $tickets, int $owner): bool
343
    {
344
        global $xoopsUser;
345
346
        $updated   = \time();
347
        $ownername = ($xoopsUser->getVar('uid') == $owner ? $xoopsUser->getVar('uname') : $xoopsUser::getUnameFromId($owner));
348
        foreach ($tickets as $ticket) {
349
            $logMessage = $this->logMessageHandler->create();
350
            $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
351
            $logMessage->setVar('ticketid', $ticket->getVar('id'));
352
            $logMessage->setVar('lastUpdated', $updated);
353
            if ($xoopsUser->getVar('uid') == $owner) {
354
                $logMessage->setVar('action', \_XHELP_LOG_CLAIM_OWNERSHIP);
355
            } else {
356
                $logMessage->setVar('action', \sprintf(\_XHELP_LOG_ASSIGN_OWNERSHIP, $ownername));
357
            }
358
            $this->logMessageHandler->insert($logMessage);
359
            unset($logMessage);
360
        }
361
362
        return true;
363
    }
364
365
    /**
366
     * Add Log Events for 'batch_status' event
367
     * @param array $tickets   Array of Ticket objects
368
     * @param int   $newstatus New status for tickets
369
     * @return bool  True on success, false on error
370
     */
371
    public function batch_status(array $tickets, int $newstatus): bool
372
    {
373
        global $xoopsUser;
374
375
        $updated = \time();
376
        $sStatus = Utility::getStatus($newstatus);
377
        $uid     = $xoopsUser->getVar('uid');
378
        foreach ($tickets as $ticket) {
379
            $logMessage = $this->logMessageHandler->create();
380
            $logMessage->setVar('uid', $uid);
381
            $logMessage->setVar('ticketid', $ticket->getVar('id'));
382
            $logMessage->setVar('lastUpdated', $updated);
383
            $logMessage->setVar('action', \sprintf(\_XHELP_LOG_UPDATE_STATUS, Utility::getStatus($ticket->getVar('status')), $sStatus));
384
            $this->logMessageHandler->insert($logMessage, true);
385
            unset($logMessage);
386
        }
387
388
        return true;
389
    }
390
391
    /**
392
     * Event: batch_response
393
     * Triggered after a batch response addition
394
     * Note: the $response->getVar('ticketid') field is empty for this function
395
     * @param array    $tickets  The Ticket objects that were modified
396
     * @param Response $response The response added to each ticket
397
     * @return bool
398
     */
399
    public function batch_response(array $tickets, Response $response): bool
0 ignored issues
show
Unused Code introduced by
The parameter $response is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

399
    public function batch_response(array $tickets, /** @scrutinizer ignore-unused */ Response $response): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
400
    {
401
        global $xoopsUser;
402
403
        $updateTime = \time();
404
        $uid        = $xoopsUser->getVar('uid');
405
406
        foreach ($tickets as $ticket) {
407
            $logMessage = $this->logMessageHandler->create();
408
            $logMessage->setVar('uid', $uid);
409
            $logMessage->setVar('ticketid', $ticket->getVar('id'));
410
            $logMessage->setVar('action', \_XHELP_LOG_ADDRESPONSE);
411
            $logMessage->setVar('lastUpdated', $updateTime);
412
            $this->logMessageHandler->insert($logMessage);
413
        }
414
415
        return true;
416
    }
417
418
    /**
419
     * Add Log Events for 'merge_tickets' event
420
     * @param int $ticketid      First ticket being merged
421
     * @param int $mergeTicketid Second ticket being merged
422
     * @param int $newTicket     Resulting merged ticket
423
     * @return bool True on success, false on error
424
     */
425
    public function merge_tickets(int $ticketid, int $mergeTicketid, int $newTicket): bool
0 ignored issues
show
Unused Code introduced by
The parameter $newTicket is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

425
    public function merge_tickets(int $ticketid, int $mergeTicketid, /** @scrutinizer ignore-unused */ int $newTicket): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
426
    {
427
        global $xoopsUser;
428
429
        $logMessage = $this->logMessageHandler->create();
430
        $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
431
        $logMessage->setVar('ticketid', $ticketid);
432
        $logMessage->setVar('action', \sprintf(\_XHELP_LOG_MERGETICKETS, $mergeTicketid, $ticketid));
433
        $logMessage->setVar('lastUpdated', \time());
434
        if ($this->logMessageHandler->insert($logMessage)) {
435
            return true;
436
        }
437
438
        return false;
439
    }
440
441
    /**
442
     * Add Log Events for 'delete_file' event
443
     * @param File $file File being deleted
444
     * @return bool      True on success, false on error
445
     */
446
    public function delete_file(File $file): bool
447
    {
448
        global $xoopsUser;
449
450
        $filename = $file->getVar('filename');
451
452
        $logMessage = $this->logMessageHandler->create();
453
        $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
454
        $logMessage->setVar('ticketid', $file->getVar('ticketid'));
455
        $logMessage->setVar('action', \sprintf(\_XHELP_LOG_DELETEFILE, $filename));
0 ignored issues
show
Bug introduced by
It seems like $filename can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

455
        $logMessage->setVar('action', \sprintf(\_XHELP_LOG_DELETEFILE, /** @scrutinizer ignore-type */ $filename));
Loading history...
456
        $logMessage->setVar('lastUpdated', \time());
457
458
        if ($this->logMessageHandler->insert($logMessage, true)) {
459
            return true;
460
        }
461
462
        return false;
463
    }
464
465
    /**
466
     * Event: new_faq
467
     * Triggered after FAQ addition
468
     * @param Ticket $ticket Ticket used as base for FAQ
469
     * @param Faq    $faq    FAQ that was added
470
     * @return bool
471
     */
472
    public function new_faq(Ticket $ticket, Faq $faq): bool
473
    {
474
        global $xoopsUser;
475
476
        $logMessage = $this->logMessageHandler->create();
477
        $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
478
        $logMessage->setVar('ticketid', $ticket->getVar('id'));
479
        $logMessage->setVar('action', \sprintf(\_XHELP_LOG_NEWFAQ, $faq->getVar('subject')));
0 ignored issues
show
Bug introduced by
It seems like $faq->getVar('subject') can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

479
        $logMessage->setVar('action', \sprintf(\_XHELP_LOG_NEWFAQ, /** @scrutinizer ignore-type */ $faq->getVar('subject')));
Loading history...
480
481
        return $this->logMessageHandler->insert($logMessage, true);
482
    }
483
484
    /**
485
     * Only have 1 instance of class used
486
     * @return Service {@link Service}
487
     */
488
    public static function getInstance(): Service
489
    {
490
        static $instance;
491
        if (null === $instance) {
492
            $instance = new static();
493
        }
494
495
        return $instance;
496
    }
497
}
498