|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace HDNET\Calendarize\Compatibility; |
|
6
|
|
|
|
|
7
|
|
|
use HDNET\Calendarize\Command\ImportCommandController; |
|
8
|
|
|
use HDNET\Calendarize\Event\ImportSingleIcalEvent; |
|
9
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessage; |
|
10
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessageService; |
|
11
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
12
|
|
|
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher; |
|
13
|
|
|
|
|
14
|
|
|
class SlotReplacement |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var Dispatcher |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $signalSlotDispatcher; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Flash message service. |
|
23
|
|
|
* |
|
24
|
|
|
* @var FlashMessageService |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $flashMessageService; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct( |
|
29
|
|
|
Dispatcher $signalSlotDispatcher, |
|
30
|
|
|
FlashMessageService $flashMessageService |
|
31
|
|
|
) { |
|
32
|
|
|
$this->signalSlotDispatcher = $signalSlotDispatcher; |
|
33
|
|
|
$this->flashMessageService = $flashMessageService; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function emitImportCommand(ImportSingleIcalEvent $event) |
|
37
|
|
|
{ |
|
38
|
|
|
$icalEvent = $event->getEvent(); |
|
39
|
|
|
$this->signalSlotDispatcher->dispatch( |
|
40
|
|
|
ImportCommandController::class, |
|
41
|
|
|
'importCommand', |
|
42
|
|
|
[ |
|
43
|
|
|
'event' => [ |
|
44
|
|
|
'uid' => $icalEvent->getUid(), |
|
45
|
|
|
'start' => $icalEvent->getStartDate()->add(\DateInterval::createFromDateString($icalEvent->getStartTime() . ' seconds')), |
|
46
|
|
|
'end' => $icalEvent->getEndDate()->add(\DateInterval::createFromDateString($icalEvent->getEndTime() . ' seconds')), |
|
47
|
|
|
'title' => $icalEvent->getTitle(), |
|
48
|
|
|
'description' => $icalEvent->getDescription(), |
|
49
|
|
|
'location' => $icalEvent->getLocation(), |
|
50
|
|
|
], |
|
51
|
|
|
'commandController' => $this, // Implements all public functions |
|
52
|
|
|
'pid' => $event->getPid(), |
|
53
|
|
|
'handled' => false, |
|
54
|
|
|
] |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
//-------------------------------------------------------------------- |
|
59
|
|
|
// Public functions from AbstractCommandController for compatibility |
|
60
|
|
|
//-------------------------------------------------------------------- |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Adds a message to the FlashMessageQueue or prints it to the CLI. |
|
64
|
|
|
* |
|
65
|
|
|
* @param mixed $message |
|
66
|
|
|
* @param string $title |
|
67
|
|
|
* @param int $severity |
|
68
|
|
|
*/ |
|
69
|
|
|
public function enqueueMessage($message, $title = '', $severity = FlashMessage::INFO) |
|
70
|
|
|
{ |
|
71
|
|
|
if ($message instanceof \Exception) { |
|
72
|
|
|
if ('' === $title) { |
|
73
|
|
|
$title = 'Exception: ' . $message->getCode(); |
|
74
|
|
|
} |
|
75
|
|
|
$message = '"' . $message->getMessage() . '"' . LF . 'In ' . $message->getFile() . ' at line ' . $message->getLine() . '!'; |
|
76
|
|
|
$this->enqueueMessage($message, $title, FlashMessage::ERROR); |
|
77
|
|
|
|
|
78
|
|
|
return; |
|
79
|
|
|
} |
|
80
|
|
|
if (!is_scalar($message)) { |
|
81
|
|
|
$message = var_export($message, true); |
|
82
|
|
|
} |
|
83
|
|
|
if (defined('TYPO3_cliMode') && TYPO3_cliMode) { |
|
84
|
|
|
echo '==' . $title . ' == ' . LF; |
|
85
|
|
|
echo $message . LF; |
|
86
|
|
|
} else { |
|
87
|
|
|
$this->enqueueMessageGui($message, $title, $severity); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Adds a message to the FlashMessageQueue. |
|
93
|
|
|
* |
|
94
|
|
|
* @param mixed $message |
|
95
|
|
|
* @param string $title |
|
96
|
|
|
* @param int $severity |
|
97
|
|
|
*/ |
|
98
|
|
|
private function enqueueMessageGui($message, $title = '', $severity = FlashMessage::INFO) |
|
99
|
|
|
{ |
|
100
|
|
|
$message = GeneralUtility::makeInstance(FlashMessage::class, nl2br($message), $title, $severity); |
|
101
|
|
|
$this->flashMessageService->getMessageQueueByIdentifier() |
|
102
|
|
|
->enqueue($message); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|