|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* Copyright (C) |
|
6
|
|
|
* Nathan Boiron <[email protected]> |
|
7
|
|
|
* Romain Canon <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* This file is part of the TYPO3 NotiZ project. |
|
10
|
|
|
* It is free software; you can redistribute it and/or modify it |
|
11
|
|
|
* under the terms of the GNU General Public License, either |
|
12
|
|
|
* version 3 of the License, or any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* For the full copyright and license information, see: |
|
15
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace CuyZ\Notiz\Domain\Event\TYPO3; |
|
19
|
|
|
|
|
20
|
|
|
use CuyZ\Notiz\Core\Event\AbstractEvent; |
|
21
|
|
|
use CuyZ\Notiz\Core\Event\Support\ProvidesExampleProperties; |
|
22
|
|
|
use InvalidArgumentException; |
|
23
|
|
|
use TYPO3\CMS\Core\DataHandling\DataHandler; |
|
24
|
|
|
|
|
25
|
|
|
final class RecordCreatedEvent extends AbstractEvent implements ProvidesExampleProperties |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @label Event/TYPO3:record_created.marker.status |
|
29
|
|
|
* @marker |
|
30
|
|
|
* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $status; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @label Event/TYPO3:record_created.marker.table |
|
37
|
|
|
* @marker |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $table; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @label Event/TYPO3:record_created.marker.uid |
|
45
|
|
|
* @marker |
|
46
|
|
|
* |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $uid; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @label Event/TYPO3:record_created.marker.record |
|
53
|
|
|
* @marker |
|
54
|
|
|
* |
|
55
|
|
|
* @var array |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $record; |
|
58
|
|
|
|
|
59
|
|
|
public function run($status, $table, $recordId, array $updatedFields, DataHandler $dataHandler) |
|
60
|
|
|
{ |
|
61
|
|
|
if ($table !== $this->configuration['table']) { |
|
62
|
|
|
$this->cancelDispatch(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if ($status === 'new') { |
|
66
|
|
|
$this->uid = $dataHandler->substNEWwithIDs[$recordId]; |
|
67
|
|
|
} elseif ($status === 'update') { |
|
68
|
|
|
$this->uid = $recordId; |
|
69
|
|
|
} else { |
|
70
|
|
|
throw new InvalidArgumentException('$status must be `new` or `update`'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$this->record = $dataHandler->recordInfo($table, $this->uid, '*'); |
|
74
|
|
|
|
|
75
|
|
|
if ($table === 'tt_content' |
|
76
|
|
|
&& !empty($this->configuration['ctype']) |
|
77
|
|
|
&& !preg_match($this->configuration['ctype'], $this->record['CType']) |
|
78
|
|
|
) { |
|
79
|
|
|
$this->cancelDispatch(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$this->status = $status; |
|
83
|
|
|
$this->table = $table; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function getExampleProperties(): array |
|
87
|
|
|
{ |
|
88
|
|
|
return [ |
|
89
|
|
|
'status' => 'new', |
|
90
|
|
|
'table' => $this->configuration['table'], |
|
91
|
|
|
'uid' => 1337, |
|
92
|
|
|
'record' => [ |
|
93
|
|
|
'uid' => 1337, |
|
94
|
|
|
'pid' => 42, |
|
95
|
|
|
'starttime' => 1612014706, |
|
96
|
|
|
], |
|
97
|
|
|
]; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|