[TASK] Remove IP address from details field of sys_log entry
[Packages/TYPO3.CMS.git] / typo3 / sysext / belog / Classes / Domain / Model / LogEntry.php
1 <?php
2 namespace TYPO3\CMS\Belog\Domain\Model;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * A sys log entry
19 * This model is 'complete': All current database properties are in there.
20 *
21 * @todo : This should be stuffed to some more central place
22 */
23 class LogEntry extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
24 {
25 /**
26 * Storage page ID of the log entry
27 *
28 * @var int
29 */
30 protected $pid = 0;
31
32 /**
33 * This is not a relation to BeUser model, since the user does
34 * not always exist, but we want the uid in then anyway.
35 * This case is ugly in extbase, the best way we
36 * have found now is to resolve the username (if it exists) in a
37 * view helper and just use the uid of the be user here.
38 *
39 * @var int
40 */
41 protected $backendUserUid = 0;
42
43 /**
44 * Action ID of the action that happened, for example 3 was a file action
45 *
46 * @var int
47 */
48 protected $action = 0;
49
50 /**
51 * UID of the record the event happened to
52 *
53 * @var int
54 */
55 protected $recordUid = 0;
56
57 /**
58 * Table name
59 *
60 * @var string
61 */
62 protected $tableName = 0;
63
64 /**
65 * PID of the record the event happened to
66 *
67 * @var int
68 */
69 protected $recordPid = 0;
70
71 /**
72 * Error code
73 *
74 * @var int
75 */
76 protected $error = 0;
77
78 /**
79 * This is the log message itself, but possibly with %s substitutions.
80 *
81 * @var string
82 */
83 protected $details = '';
84
85 /**
86 * Timestamp when the log entry was written
87 *
88 * @var int
89 */
90 protected $tstamp = 0;
91
92 /**
93 * Type code
94 *
95 * @var int
96 */
97 protected $type = 0;
98
99 /**
100 * Details number
101 *
102 * @var int
103 */
104 protected $detailsNumber = 0;
105
106 /**
107 * IP address of client
108 *
109 * @var string
110 */
111 protected $ip = '';
112
113 /**
114 * Serialized log data. This is a serialized array with substitutions for $this->details.
115 *
116 * @var string
117 */
118 protected $logData = '';
119
120 /**
121 * Event PID
122 *
123 * @var int
124 */
125 protected $eventPid = 0;
126
127 /**
128 * This is only the UID and not the full workspace object for the same reason as in $beUserUid.
129 *
130 * @var int
131 */
132 protected $workspaceUid = 0;
133
134 /**
135 * New ID
136 *
137 * @var string
138 */
139 protected $newId = 0;
140
141 /**
142 * Set pid
143 *
144 * @param int $pid
145 */
146 public function setPid($pid)
147 {
148 $this->pid = (int)$pid;
149 }
150
151 /**
152 * Get pid
153 *
154 * @return int
155 */
156 public function getPid()
157 {
158 return $this->pid;
159 }
160
161 /**
162 * Set backend user uid
163 *
164 * @param int $beUserUid
165 */
166 public function setBackendUserUid($beUserUid)
167 {
168 $this->backendUserUid = $beUserUid;
169 }
170
171 /**
172 * Get backend user id
173 *
174 * @return int
175 */
176 public function getBackendUserUid()
177 {
178 return $this->backendUserUid;
179 }
180
181 /**
182 * Set action
183 *
184 * @param int $action
185 */
186 public function setAction($action)
187 {
188 $this->action = $action;
189 }
190
191 /**
192 * Get action
193 *
194 * @return int
195 */
196 public function getAction()
197 {
198 return (int)$this->action;
199 }
200
201 /**
202 * Set record uid
203 *
204 * @param int $recordUid
205 */
206 public function setRecordUid($recordUid)
207 {
208 $this->recordUid = $recordUid;
209 }
210
211 /**
212 * Get record uid
213 *
214 * @return int
215 */
216 public function getRecordUid()
217 {
218 return (int)$this->recordUid;
219 }
220
221 /**
222 * Set table name
223 *
224 * @param string $tableName
225 */
226 public function setTableName($tableName)
227 {
228 $this->tableName = $tableName;
229 }
230
231 /**
232 * Get table name
233 *
234 * @return string
235 */
236 public function getTableName()
237 {
238 return $this->tableName;
239 }
240
241 /**
242 * Set record pid
243 *
244 * @param int $recordPid
245 */
246 public function setRecordPid($recordPid)
247 {
248 $this->recordPid = $recordPid;
249 }
250
251 /**
252 * Get record pid
253 *
254 * @return int
255 */
256 public function getRecordPid()
257 {
258 return (int)$this->recordPid;
259 }
260
261 /**
262 * Set error
263 *
264 * @param int $error
265 */
266 public function setError($error)
267 {
268 $this->error = $error;
269 }
270
271 /**
272 * Get error
273 *
274 * @return int
275 */
276 public function getError()
277 {
278 return (int)$this->error;
279 }
280
281 /**
282 * Get class name for the error code
283 *
284 * @return string
285 */
286 public function getErrorIconClass(): string
287 {
288 switch ($this->getError()) {
289 case 1:
290 return 'status-dialog-warning';
291 case 2:
292 case 3:
293 return 'status-dialog-error';
294 default:
295 return 'empty-empty';
296 }
297 }
298
299 /**
300 * Set details
301 *
302 * @param string $details
303 */
304 public function setDetails($details)
305 {
306 $this->details = $details;
307 }
308
309 /**
310 * Get details
311 *
312 * @return string
313 */
314 public function getDetails()
315 {
316 if ($this->type === 255) {
317 return str_replace('###IP###', $this->ip, $this->details);
318 }
319 return $this->details;
320 }
321
322 /**
323 * Set tstamp
324 *
325 * @param int $tstamp
326 */
327 public function setTstamp($tstamp)
328 {
329 $this->tstamp = $tstamp;
330 }
331
332 /**
333 * Get tstamp
334 *
335 * @return int
336 */
337 public function getTstamp()
338 {
339 return (int)$this->tstamp;
340 }
341
342 /**
343 * Set type
344 *
345 * @param int $type
346 */
347 public function setType($type)
348 {
349 $this->type = $type;
350 }
351
352 /**
353 * Get type
354 *
355 * @return int
356 */
357 public function getType()
358 {
359 return (int)$this->type;
360 }
361
362 /**
363 * Set details number
364 *
365 * @param int $detailsNumber
366 */
367 public function setDetailsNumber($detailsNumber)
368 {
369 $this->detailsNumber = $detailsNumber;
370 }
371
372 /**
373 * Get details number
374 *
375 * @return int
376 */
377 public function getDetailsNumber()
378 {
379 return (int)$this->detailsNumber;
380 }
381
382 /**
383 * Set ip
384 *
385 * @param string $ip
386 */
387 public function setIp($ip)
388 {
389 $this->ip = $ip;
390 }
391
392 /**
393 * Get ip
394 *
395 * @return string
396 */
397 public function getIp()
398 {
399 return $this->ip;
400 }
401
402 /**
403 * Set log data
404 *
405 * @param string $logData
406 */
407 public function setLogData($logData)
408 {
409 $this->logData = $logData;
410 }
411
412 /**
413 * Get log data
414 *
415 * @return array
416 */
417 public function getLogData()
418 {
419 if ($this->logData === '') {
420 return [];
421 }
422 $logData = @unserialize($this->logData);
423 if (!is_array($logData)) {
424 $logData = [];
425 }
426 return $logData;
427 }
428
429 /**
430 * Set event pid
431 *
432 * @param int $eventPid
433 */
434 public function setEventPid($eventPid)
435 {
436 $this->eventPid = $eventPid;
437 }
438
439 /**
440 * Get event pid
441 *
442 * @return int
443 */
444 public function getEventPid()
445 {
446 return (int)$this->eventPid;
447 }
448
449 /**
450 * Set workspace uid
451 *
452 * @param int $workspaceUid
453 */
454 public function setWorkspaceUid($workspaceUid)
455 {
456 $this->workspaceUid = $workspaceUid;
457 }
458
459 /**
460 * Get workspace
461 *
462 * @return int
463 */
464 public function getWorkspaceUid()
465 {
466 return (int)$this->workspaceUid;
467 }
468
469 /**
470 * Set new id
471 *
472 * @param string $newId
473 */
474 public function setNewId($newId)
475 {
476 $this->newId = $newId;
477 }
478
479 /**
480 * Get new id
481 *
482 * @return string
483 */
484 public function getNewId()
485 {
486 return $this->newId;
487 }
488 }