|
1
|
|
|
<?php |
|
2
|
|
|
namespace Gilbertsoft\Lib\Service; |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* This file is part of the "GS Library" Extension for TYPO3 CMS. |
|
6
|
|
|
* |
|
7
|
|
|
* Copyright (C) 2017 by Gilbertsoft (gilbertsoft.org) |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU General Public License as published by |
|
11
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
12
|
|
|
* (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* For the full license information, please read the LICENSE file that |
|
20
|
|
|
* was distributed with this source code. |
|
21
|
|
|
* |
|
22
|
|
|
* The TYPO3 project - inspiring people to share! |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Use declarations |
|
27
|
|
|
*/ |
|
28
|
|
|
use Gilbertsoft\Lib\Utility\FlashMessageUtility; |
|
29
|
|
|
use Gilbertsoft\Lib\Utility\Typo3Mode; |
|
30
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessage; |
|
31
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* GS Abstract Install Service class. |
|
35
|
|
|
*/ |
|
36
|
|
|
abstract class AbstractInstallService |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* @var string Extension key |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $extensionKey; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Called from ext_localconf.php, to be implemented in derrived classes. |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $extensionKey Extension key |
|
47
|
|
|
* @return null | AbstractInstallService Instance of this class |
|
|
|
|
|
|
48
|
|
|
*/ |
|
49
|
|
|
public static function registerService($extensionKey) |
|
50
|
|
|
{ |
|
51
|
|
|
if (Typo3Mode::isBackend()) { |
|
52
|
|
|
$signalSlot = GeneralUtility::makeInstance(static::class, $extensionKey); |
|
53
|
|
|
$signalSlotDispatcher = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class); |
|
54
|
|
|
$signalSlotDispatcher->connect( |
|
55
|
|
|
\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, |
|
56
|
|
|
'afterExtensionInstall', |
|
57
|
|
|
$signalSlot, |
|
58
|
|
|
'afterInstall' |
|
59
|
|
|
); |
|
60
|
|
|
$signalSlotDispatcher->connect( |
|
61
|
|
|
\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, |
|
62
|
|
|
'afterExtensionUninstall', |
|
63
|
|
|
$signalSlot, |
|
64
|
|
|
'afterUninstall' |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
return $signalSlot; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return null; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Initializes the install service |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $extensionKey Extension key |
|
77
|
|
|
* @throws InvalidArgumentException |
|
78
|
|
|
*/ |
|
79
|
|
|
public function __construct($extensionKey) |
|
80
|
|
|
{ |
|
81
|
|
|
if (!is_string($extensionKey) || empty($extensionKey)) { |
|
82
|
|
|
throw new \InvalidArgumentException('$extensionKey must be a non empty string.', 1491494798); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$this->extensionKey = $extensionKey; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Executes the setup tasks if extension is installed. |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $extensionKey Installed extension key |
|
92
|
|
|
* @return void |
|
93
|
|
|
*/ |
|
94
|
|
|
abstract public function afterInstall($extensionKey); |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Executes the setup tasks if extension is uninstalled. |
|
98
|
|
|
* |
|
99
|
|
|
* @param string $extensionKey Uninstalled extension key |
|
100
|
|
|
* @return void |
|
101
|
|
|
*/ |
|
102
|
|
|
abstract public function afterUninstall($extensionKey); |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Create a Flash Message and add it to the Queue |
|
106
|
|
|
* |
|
107
|
|
|
* @param string $message The message. |
|
108
|
|
|
* @param string $title Optional message title. |
|
109
|
|
|
* @param int $severity Optional severity, must be either of one of \TYPO3\CMS\Core\Messaging\FlashMessage constants |
|
110
|
|
|
* @param bool $storeInSession Optional, defines whether the message should be stored in the session or only for one request (default) |
|
111
|
|
|
* @return void |
|
112
|
|
|
*/ |
|
113
|
|
|
protected function showFlashMessage($message, $title = '', $severity = FlashMessage::OK, $storeInSession = true) |
|
114
|
|
|
{ |
|
115
|
|
|
return FlashMessageUtility::showFlashMessage($this->extensionKey, $message, $title, $severity, $storeInSession); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.