1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SourceBroker\Hugo\DataHandling; |
4
|
|
|
|
5
|
|
|
use SourceBroker\Hugo\Queue\QueueInterface; |
6
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
7
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
8
|
|
|
use TYPO3\CMS\Core\Utility\MathUtility; |
9
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
10
|
|
|
|
11
|
|
|
class DataHandler implements SingletonInterface |
12
|
|
|
{ |
13
|
|
|
protected $supportedTables = ['tt_content', 'pages']; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Clears path and URL caches if the page was deleted. |
17
|
|
|
* |
18
|
|
|
* @param string $tableName |
19
|
|
|
* @param string|int $recordId |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
View Code Duplication |
public function processCmdmap_deleteAction($tableName, $recordId) |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
if (in_array($tableName, $this->supportedTables)) { |
25
|
|
|
$queueValue = 'delete:' . $tableName; |
26
|
|
|
|
27
|
|
|
if (is_numeric($recordId)) { |
28
|
|
|
$queueValue .= ':' . intval($recordId); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$this->getQueue()->push($queueValue); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Expires caches if the page was moved. |
37
|
|
|
* |
38
|
|
|
* @param string $command |
39
|
|
|
* @param $tableName |
40
|
|
|
* @param $recordId |
41
|
|
|
* |
42
|
|
|
*/ |
43
|
|
View Code Duplication |
public function processCmdmap_postProcess($command, $tableName, $recordId) |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
if (in_array($tableName, $this->supportedTables)) { |
46
|
|
|
$queueValue = 'update:' . $tableName; |
47
|
|
|
|
48
|
|
|
if (is_numeric($recordId)) { |
49
|
|
|
$queueValue .= ':' . $recordId; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$this->getQueue()->push($queueValue); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* A DataHandler hook to expire old records. |
58
|
|
|
* |
59
|
|
|
* @param string $status 'new' (ignoring) or 'update' |
60
|
|
|
* @param string $tableName |
61
|
|
|
* @param int $recordId |
62
|
|
|
* @param array $databaseData |
63
|
|
|
* @param \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler |
64
|
|
|
* |
65
|
|
|
* @return void |
66
|
|
|
* @throws \TYPO3\CMS\Core\Locking\Exception\LockAcquireException |
67
|
|
|
* @throws \TYPO3\CMS\Core\Locking\Exception\LockCreateException |
68
|
|
|
*/ |
69
|
|
|
public function processDatamap_afterDatabaseOperations( |
70
|
|
|
/** @noinspection PhpUnusedParameterInspection */ |
71
|
|
|
$status, |
|
|
|
|
72
|
|
|
$tableName, |
73
|
|
|
$recordId, |
74
|
|
|
array $databaseData, |
|
|
|
|
75
|
|
|
/** @noinspection PhpUnusedParameterInspection */ |
76
|
|
|
\TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler |
77
|
|
|
) { |
78
|
|
|
if (in_array($tableName, $this->supportedTables)) { |
79
|
|
|
$queueValue = 'update:' . $tableName; |
80
|
|
|
|
81
|
|
|
if (!MathUtility::canBeInterpretedAsInteger($recordId)) { |
82
|
|
|
$recordId = (int)$dataHandler->substNEWwithIDs[$recordId]; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if (is_numeric($recordId)) { |
86
|
|
|
$queueValue .= ':' . $recordId; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$this->getQueue()->push($queueValue); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return QueueInterface |
95
|
|
|
*/ |
96
|
|
|
protected function getQueue(): QueueInterface |
97
|
|
|
{ |
98
|
|
|
$objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
99
|
|
|
|
100
|
|
|
return $objectManager->get(QueueInterface::class); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.