1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Helper Utility. |
5
|
|
|
*/ |
6
|
|
|
declare(strict_types=1); |
7
|
|
|
|
8
|
|
|
namespace HDNET\Calendarize\Utility; |
9
|
|
|
|
10
|
|
|
use In2code\Powermail\Utility\ObjectUtility; |
11
|
|
|
use TYPO3\CMS\Core\Database\Connection; |
12
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
13
|
|
|
use TYPO3\CMS\Core\Exception; |
14
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessage; |
15
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessageService; |
16
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
17
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
18
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; |
19
|
|
|
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface; |
20
|
|
|
use TYPO3\CMS\Extbase\Persistence\QueryInterface; |
21
|
|
|
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher; |
22
|
|
|
use function get_class; |
23
|
|
|
use function is_object; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Helper Utility. |
27
|
|
|
*/ |
28
|
|
|
class HelperUtility |
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get the query for the given class name oder object. |
34
|
|
|
* |
35
|
|
|
* @param string|object $objectName |
36
|
|
|
* |
37
|
|
|
* @return QueryInterface |
38
|
|
|
* @throws \TYPO3\CMS\Extbase\Object\Exception |
39
|
|
|
*/ |
40
|
|
|
public static function getQuery($objectName) |
41
|
|
|
{ |
42
|
|
|
$objectName = is_object($objectName) ? get_class($objectName) : $objectName; |
43
|
|
|
/** @var PersistenceManagerInterface $manager */ |
44
|
|
|
static $manager = null; |
45
|
|
|
if (null === $manager) { |
46
|
|
|
$manager = ObjectUtility::getObjectManager()->get(PersistenceManagerInterface::class); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $manager->createQueryForType($objectName); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get the signal slot dispatcher. |
54
|
|
|
* |
55
|
|
|
* @return Dispatcher |
56
|
|
|
*/ |
57
|
|
|
public static function getSignalSlotDispatcher(): Dispatcher |
58
|
|
|
{ |
59
|
|
|
return GeneralUtility::makeInstance(Dispatcher::class); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Create a flash message. |
64
|
|
|
* |
65
|
|
|
* @param string $message |
66
|
|
|
* @param string $title |
67
|
|
|
* @param int $mode |
68
|
|
|
* |
69
|
|
|
* @throws Exception |
70
|
|
|
*/ |
71
|
|
|
public static function createFlashMessage($message, $title = '', $mode = FlashMessage::OK) |
72
|
|
|
{ |
73
|
|
|
$flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $message, $title, $mode, true); |
74
|
|
|
$flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class); |
75
|
|
|
$messageQueue = $flashMessageService->getMessageQueueByIdentifier(); |
76
|
|
|
$messageQueue->enqueue($flashMessage); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get the database connection. |
81
|
|
|
* |
82
|
|
|
* @param mixed $table |
83
|
|
|
* |
84
|
|
|
* @return Connection |
85
|
|
|
*/ |
86
|
|
|
public static function getDatabaseConnection($table) |
87
|
|
|
{ |
88
|
|
|
return GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Persist all data. |
93
|
|
|
*/ |
94
|
|
|
public static function persistAll() |
95
|
|
|
{ |
96
|
|
|
/** @var $persist PersistenceManager */ |
97
|
|
|
$persist = self::create(PersistenceManager::class); |
|
|
|
|
98
|
|
|
$persist->persistAll(); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.